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 :: mypy clear cache 
Python :: determinant of matrix in python 
Python :: sendgrid django smtp 
Python :: get basename without extension python 
Python :: python generate pdf from template 
Python :: how to take first digit of number python 
Python :: go to line in python 
Python :: create the dataframe column based on condition 
Python :: decode binary string python 
Python :: typing multiple types 
Python :: django meta attributes 
Python :: mulitplication symbo for unpacking in python 
Python :: python jwt 
Python :: at=error code=h10 desc= app crashed python flask 
Python :: pivot pyspark 
Python :: download pytz python 
Python :: python delete all occurrences from list 
Python :: addition of matrix in python using numpy 
Python :: how to access variables from a class in python 
Python :: python get env 
Python :: create numpy array with ones 
Python :: tk inter entry 
Python :: send mail through python 
Python :: how to print all items in a list python 
Python :: dataframe unstack 
Python :: Get the square root of a number in Python 
Python :: BURGERS2 codechef solution 
Python :: python requests-session for websites with login 
Python :: fakultät python 
Python :: pandas remove repeated index 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =