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: