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 :: how to return only fractional part in python 
Python :: django admin table columns wrap text into multiple lines django 
Python :: create numpy table with random values in range 
Python :: erreur install pyaudio 
Python :: python program to find all prime numbers within a given range 
Python :: how to put more than one file type in pysimplegui 
Python :: python multiply matrices 
Python :: numpy multiply by inverse square root of value 
Python :: pil save image 
Python :: python format float as currency 
Python :: pandas filter non nan 
Python :: overlapping date matplotlib 
Python :: how to create text file with python and store a dictionary 
Python :: selenium send keys python 
Python :: How to to efficiently find the first index in a sorted array of distinct numbers that is equal to the value at that index? 
Python :: who is elcharitas 
Python :: Write multiple DataFrames to Excel files 
Python :: python beep 
Python :: python pandas how to load csv file 
Python :: print all values of dictionary 
Python :: python 3 of 4 conditions true 
Python :: print 1 thing repeatedly in 1 line python 
Python :: django httpresponseredirect 
Python :: get home directory in windows python os 
Python :: python saveAsTextFile 
Python :: check version numpy 
Python :: python read file in string list 
Python :: pandas combine two data frames with same index and same columns 
Python :: py-trello add card 
Python :: how to get current page url in django template 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =