Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Machine Learning by (19k points)
using python scikit svm, after running clf.fit(X, Y), you get your support vectors. could I load these support vectors directly (passing them as paramter) when instantiate a svm.SVC object? which means I do not need to running fit() method each time to do predication

1 Answer

0 votes
by (33.1k points)
edited by

Model persistence is used to save a model in the scikit by using Python’s built-in persistence model, namely pickle.

For example:

>>> from sklearn import svm

>>> from sklearn import datasets

>>> clf = svm.SVC()

>>> iris = datasets.load_iris()

>>> X, y = iris.data, iris.target

>>> clf.fit(X, y)

SVC(kernel=’rbf’, C=1.0, probability=False, degree=3, coef0=0.0, eps=0.001,

cache_size=100.0, shrinking=True, gamma=0.00666666666667)

Using Pickle

>>> import pickle

>>> s = pickle.dumps(clf)

>>> clf2 = pickle.loads(s)

>>> clf2.predict(X[0])

array([ 0.])

>>> y[0]

0

In some case, you can use joblib’s replacement of pickle, which is more efficient for big data, but can only pickle to the disk and not to a string:

>>> from sklearn.externals import joblib

>>> joblib.dump(clf, ’filename.pkl’)

Hope this answer helps you!

If you want to learn K Means Clustering Algorithm then you can refer to the below video:

Browse Categories

...