Reputation: 329
I am trying to save a Linear model with below lines of code, but I am getting error as 'LinearRegression' object has no attribute 'save'.
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.save('Linear_Model.h5')
How to fix this issue ?
Upvotes: 0
Views: 2070
Reputation: 6025
model.save() is not built for sklearn models as opposed to keras/tensorflow models. You might want to save them as you would do with other python objects as follows:
# 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)
# save the model to disk
filename = 'finalized_model.sav'
joblib.dump(model, filename)
# some time later...
# load the model from disk
loaded_model = joblib.load(filename)
result = loaded_model.score(X_test, Y_test)
If you are interested, this article has these codes with examples. Also check the link to the SO question that might already answer what you are looking for
Upvotes: 1