How to save classifier to disk in scikit-learn

0 votes

Hi Guys,

I have trained the Naive Bayes classifier. I want to save this model for future use. How do I save a trained Naive Bayes classifier to disk and use it to predict data?

Jul 14, 2020 in Machine Learning by akhtar
• 38,260 points
1,092 views

1 answer to this question.

0 votes

Hi@akhtar,

Classifiers are just objects that can be pickled and dumped like any other. You can go through the below code for your reference.

import cPickle
# save the classifier
with open('my_dumped_classifier.pkl', 'wb') as fid:
    cPickle.dump(gnb, fid)    
# load it again
with open('my_dumped_classifier.pkl', 'rb') as fid:
    gnb_loaded = cPickle.load(fid)
answered Jul 14, 2020 by MD
• 95,460 points

Related Questions In Machine Learning

0 votes
1 answer

How to get a regression summary in scikit-learn like R does?

In sklearn, there is no R type ...READ MORE

answered Mar 15, 2022 in Machine Learning by Dev
• 6,000 points
3,602 views
0 votes
1 answer
0 votes
1 answer

How to add one new column in an existing dataset?

Hi@akhtar, You can do this task using numpy ...READ MORE

answered Apr 17, 2020 in Machine Learning by MD
• 95,460 points
2,471 views
+1 vote
1 answer

How to load CNN model in keras?

Hi@akhtar, You can load your pre-created model in ...READ MORE

answered May 18, 2020 in Machine Learning by MD
• 95,460 points
1,866 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,391 views
0 votes
1 answer
0 votes
0 answers

Hello I have some errors while implementing variational autoencoder

def dense_layers(sizes): return tfk.Sequential([tfkl.Dense(size, ...READ MORE

May 19, 2019 in Machine Learning by anonymous

edited May 20, 2019 by Omkar 1,359 views
0 votes
1 answer

How to save CNN model in keras?

Hi@akhtar, You can save your CNN model in keras. For ...READ MORE

answered May 19, 2020 in Machine Learning by MD
• 95,460 points
1,915 views
0 votes
1 answer

How to save machine learning model?

Hi@akhtar, To save your Machine Learning model, you ...READ MORE

answered Apr 13, 2020 in Machine Learning by MD
• 95,460 points
847 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP