快速上手scikit-learn

scikit-learn是啥?
python机器学习库。

官网:http://scikit-learn.org/

安装

$ pip install scikit-learn numpy scipy

quick start

$ python
>>> from sklearn import datasets
>>> digits = datasets.load_digits()
>>> print(digits.data)  #查看数据
[[ 0.  0.  5. ...  0.  0.  0.]
 [ 0.  0.  0. ... 10.  0.  0.]
 [ 0.  0.  0. ... 16.  9.  0.]
 ...
 [ 0.  0.  1. ...  6.  0.  0.]
 [ 0.  0.  2. ... 12.  0.  0.]
 [ 0.  0. 10. ... 12.  1.  0.]]
>>> digits.target  #Ground truth
array([0, 1, 2, ..., 8, 9, 8])
>>> digits.images[0]
array([[ 0.,  0.,  5., 13.,  9.,  1.,  0.,  0.],
       [ 0.,  0., 13., 15., 10., 15.,  5.,  0.],
       [ 0.,  3., 15.,  2.,  0., 11.,  8.,  0.],
       [ 0.,  4., 12.,  0.,  0.,  8.,  8.,  0.],
       [ 0.,  5.,  8.,  0.,  0.,  9.,  8.,  0.],
       [ 0.,  4., 11.,  0.,  1., 12.,  7.,  0.],
       [ 0.,  2., 14.,  5., 10., 12.,  0.,  0.],
       [ 0.,  0.,  6., 13., 10.,  0.,  0.,  0.]])
>>> from sklearn import svm
>>> clf = svm.SVC(gamma=0.001, C=100.)  #svm classifier
>>> clf.fit(digits.data[:-1], digits.target[:-1])  #训练
SVC(C=100.0, cache_size=200, class_weight=None, coef0=0.0,
  decision_function_shape='ovr', degree=3, gamma=0.001, kernel='rbf',
  max_iter=-1, probability=False, random_state=None, shrinking=True,
  tol=0.001, verbose=False)
>>> clf.predict(digits.data[-1:])  #测试
array([8])
>>>

完成!

QY 2018-03-29

你可能感兴趣的:(快速上手scikit-learn)