+1 vote
2 views
in Python by (320 points)
How can I save a trained Naive Bayes classifier to a disk and use it for predicting data?

1 Answer

+2 votes
by (10.9k points)
edited by

You have to initialize your classifier first and then train it for a long time with

clf= some.classifier()

clf.fit(x,y)

After this you can opt for any of the two options-

1. Using Pickle

import pickle

with open('file.pkl', 'wb') as f:

   pickle.dump(clf, f)

with open('file.pkl', 'rb') as f:

   clf = pickle.load(f)

2. Using Joblib

from sklearn.externals import joblib

joblib.dump(clf, 'filename.pkl')

clf = joblib.load('filename.pkl')

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...