Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to save model to a file python

model.fit(X_train, Y_train)
# save the model to disk
filename = 'finalized_model.sav'
pickle.dump(model, open(filename, 'wb'))
 
# some time later...
 
# load the model from disk
loaded_model = pickle.load(open(filename, 'rb'))
result = loaded_model.score(X_test, Y_test)
print(result)
Comment

how to save the model in python

import pickle # first import library
pickle.dump(model, open("any_model_name.pkl", "wb"))
Comment

save model python

import pickle
# To save
pickle.dump(model, "model.p")
# To load again
with open('model.p', 'r') as fp:
    model = pickle.load(fp)
Comment

PREVIOUS NEXT
Code Example
Python :: find index of maximum value in list python 
Python :: sqlite query in python 
Python :: python convert string to float array 
Python :: application/x-www-form-urlencoded python 
Python :: append item to array python 
Python :: python pyqt5 sleep 
Python :: seaborn bar plot 
Python :: multiple variables in for loop python 
Python :: make a window tkinter 
Python :: generate list of consecutive numbers 
Python :: python check if character is letter 
Python :: __str__() 
Python :: python string to int 
Python :: discord.py fetch channel 
Python :: python slice string 
Python :: palindrome string python 
Python :: scikit image 0.16.2 
Python :: delete columns pandas 
Python :: streamlit python install 
Python :: python library to make qr codes 
Python :: python iterate through string in reverse 
Python :: ping with python 
Python :: make the program title a name python 
Python :: Extract column from a pandas dataframe 
Python :: fstring 
Python :: ion flux relabeling 
Python :: how to do disconnect command on member in discord python 
Python :: numpy combinations of 5 bits 
Python :: zscore python 
Python :: pandas change order of columns in multiindex 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =