AutoViML / Auto_ViML

Automatically Build Multiple ML Models with a Single Line of Code. Created by Ram Seshadri. Collaborators Welcome. Permission Granted upon Request.
Apache License 2.0
522 stars 102 forks source link

how to load the Catboost model for predicting new data #28

Closed HazelSCUT closed 1 year ago

HazelSCUT commented 1 year ago

I used the Catboost to train the model and saved the trained model by using the code (m.save_model('Catboost.dump')).

However, when I failed to load such a saved model for predicting the new data unless I trained the model again. I used the code (m.load_model('Catboost.dump')); however, the bug is name "m" is not defined.

The question is how to load such a model for predicting new data without training the model each time.

Thanks!

AutoViML commented 1 year ago

Hi @HazelSCUT

Thanks for testing out AutoViML. The instructions to do this correctly are just a click away in Stack Overflow.

# After you train the model using fit(), save like this - 
m.save_model('model_name')    # extension not required.

# And then, later load - 
from catboost import CatBoostClassifier
mx = CatBoostClassifier()      # parameters not required.
mx.load_model('model_name')

# Now, try predict().
mx.predict(test[preds])

Next time please do this 👍 https://stackoverflow.com/questions/51895761/how-to-correctly-load-pretrained-model-in-catboost-in-python Thanks AutoVIML