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,170 points
134 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,200 points

Related Questions In Machine Learning

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,200 points
876 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,200 points
682 views
0 votes
1 answer

How to load a model from an HDF5 file in Keras?

Hi@akhtar, If you stored the complete model, not ...READ MORE

answered Jul 14, 2020 in Machine Learning by MD
• 95,200 points
1,970 views
0 votes
1 answer

How to import the BatchNormalization function in Keras?

Hi@akhtar, The general use case is to use ...READ MORE

answered Jul 29, 2020 in Machine Learning by MD
• 95,200 points
186 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,161 views
0 votes
0 answers
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 18, 2019 in Machine Learning by anonymous

edited May 20, 2019 by Omkar 643 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,200 points
685 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,200 points
273 views