Skip to content

Instantly share code, notes, and snippets.

@sakethramanujam
Created December 9, 2019 10:32
Show Gist options
  • Save sakethramanujam/bc1967ba32ba5cc59f0aa9054d8a870a to your computer and use it in GitHub Desktop.
Save sakethramanujam/bc1967ba32ba5cc59f0aa9054d8a870a to your computer and use it in GitHub Desktop.
Functions to save machine learning Models as .pickle files and importing them
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