Created
December 9, 2019 10:32
-
-
Save sakethramanujam/bc1967ba32ba5cc59f0aa9054d8a870a to your computer and use it in GitHub Desktop.
Functions to save machine learning Models as .pickle files and importing them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
def save_pickle(model): | |
name=input('Name of the model: ') | |
with open(f'{name}.pickle','wb') as model: | |
pickle.dump(rf_model,model) | |
print('Model Saved.') | |
def load_pickle(filename): | |
file = open(filename,'rb') | |
model = pickle.load(file) | |
return model | |
''' | |
Usage: | |
To save a model to the pickle file: | |
model = model.fit(x,y....) | |
save_to_pickle(model) | |
To use a pickled model | |
model = load_pickle('path/to/pickle') | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment