How to retrain logistic regression model in sklearn with new data

Viewed 11169

How do I retrain my existing machine learning model in sklearn python?

I have thousands of records using which I have trained my model and dumped as .pkl file using pickle. While training the model for the first time, I have used the warmStart = True parameter while creating the logistic regression object.

Sample Code:

 log_regression_model =  linear_model.LogisticRegression(warm_start = True)
 log_regression_model.fit(X, Y)
 # Saved this model as .pkl file on filesystem like pickle.dump(model,open('model.pkl', wb))

I want to keep this up to date with the new data I will getting daily. For that I am opening the existing model file and get the new data of last 24 hours and train it again./

Sample Code:

#open the model from filesystem
log_regression_model = pickle.load(open('model.pkl','rb'))
log_regression_model.fit(X, Y) # New X, Y here is data of last 24 hours only. Few hundreds records only.

But, when I retrain model by loading it from filesystem, it seems to erase the existing model which is created with thousands of records, and create the new one with few hundreds of records from last 24 hours (model with thousands records is 3MB in size on filesystem, while new retrained model is only 67KB)

I have tried using warmStart option. How do I retrain my LogisticRegression model?

2 Answers
Related