Saving a trained cross-validation model in Scikit

I trained the model in scikit-learnusing the classifier Cross-Validationand Naive Bayes. How can I continue this model to work with new instances later?

Here is what I have, I can get grades CV, but I don’t know how to access the trained model

gnb = GaussianNB() 
scores = cross_validation.cross_val_score(gnb, data_numpy[0],data_numpy[1], cv=10)
+4
source share
1 answer

cross_val_score does not change your score or return a built-in score. It simply returns a cross-validation evaluation score.

- . () - pickle:

# To fit your estimator
gnb.fit(data_numpy[0], data_numpy[1])
# To serialize
import pickle
with open('our_estimator.pkl', 'wb') as fid:
    pickle.dump(gnb, fid)
# To deserialize estimator later
with open('our_estimator.pkl', 'rb') as fid:
    gnb = pickle.load(fid)
+5

Source: https://habr.com/ru/post/1608353/


All Articles