Introduction
In [3]:
from sklearn import datasets
iris = datasets.load_iris()
digits = datasets.load_digits()
In [4]:
print(digits.data)
In [6]:
print(digits.target)
In [8]:
from sklearn import svm
clf = svm.SVC(gamma=0.001, C=100.)
clf.fit(digits.data[:-1], digits.target[:-1])
Out[8]:
In [9]:
clf.predict(digits.data[-1:])
Out[9]:
In [18]:
import numpy as np
import matplotlib.pyplot as plt
img = digits.data[-1:].reshape((8,8))
plt.imshow(img)
plt.show()
In [19]:
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)
Out[19]:
In [20]:
import pickle
s = pickle.dumps(clf)
clf2= pickle.loads(s)
clf2.predict(X[0:1])
Out[20]:
In [21]:
y[0]
Out[21]:
In [23]:
import numpy as np
from sklearn import random_projection
rng = np.random.RandomState(0)
X = rng.rand(10, 2000)
X = np.array(X, dtype='float32')
X.dtype
Out[23]:
In [25]:
transformer = random_projection.GaussianRandomProjection()
x_new = transformer.fit_transform(X)
x_new.dtype
Out[25]:
In [28]:
from sklearn.svm import SVC
from sklearn.multiclass import OneVsRestClassifier
from sklearn.preprocessing import LabelBinarizer
X = [[1,2], [2,4], [4,5], [3,2], [3,1]]
y = [0, 0, 1, 1, 2]
classif = OneVsRestClassifier(estimator=SVC(random_state=0))
classif.fit(X, y).predict(X)
Out[28]:
In [29]:
y = LabelBinarizer().fit_transform(y)
classif.fit(X, y).predict(X)
Out[29]:
In [ ]: