I'm new to neural networks and data science field. I have a dataset with over 90,000 rows. which Include 9 text columns & 29 Number Columns. after encoding with label encoder and one hot encoder It has over 10,000 columns. Now I like to save those scalers, encoders and prediction files for later use. But I have no Idea how to save and use them later for single prediction. Any help is appreciate. Thank You
1 Answer
$\begingroup$
$\endgroup$
2
You could use pickle to store your encoders/scalers/etc. It is a common way of storing Python objects
from sklearn.preprocessing import LabelEncoder
import pickle
# Fit a label encoder
le = LabelEncoder()
X = le.fit_transform(X)
# Pickle the encoder for later use
with open('path/and/name', 'wb') as f:
pickle.dump(le, f)
Then when you have it stored it can be used again by loading the pickle
# Read the pickle from file
with open('path/and/name', 'rb') as f:
le = pickle.load(f)
# Use the already fitted encoder to transform new data
X = le.transform(X)
Then repeat the process for your all your preprocessing objects
-
$\begingroup$ thank you. Sorry I couldn't up vote. My points are not high enough for that $\endgroup$ Commented Jan 14, 2019 at 9:56
-
$\begingroup$ No worries, just glad it was helpful :) $\endgroup$ Commented Jan 14, 2019 at 10:00