11th. Recognition of handwritten numerals 271
11.1 Handwriting Recognition 271
11.2 using Scikit-learn to recognize handwritten numerals 271
11.3 Digits Data Set 272
11.4 Learning and Forecasting 274
11.5 Summary 276
1 2
|
Import SVM svc = SVM. SVC (gamma=0.001, c=100.)
|
1 2 3
|
Import datasets
digits = Datasets.load_digits ()
|
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.]])
1797
array([0, 1, 2, ..., 8, 9, 8])
1 2 3 4
|
As Plt %matplotlib Inline
Plt.imshow (digits.images[0], cmap=plt.cm.gray_r, interpolation=' nearest ')
|
<matplotlib.image.AxesImage at 0x16657400>
1
|
Svc.fit (digits.data[1:1790], digits.target[1:1790])
|
SVC(C=100.0, cache_size=200, class_weight=None, coef0=0.0, degree=3, gamma=0.001, kernel=‘rbf‘, max_iter=-1, probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
Import Matplotlib.pyplotAs Plt %matplotlib Inline
Plt.subplot (321) Plt.imshow (digits.images[1791], Cmap=plt.cm.gray_r, interpolation=' Nearest ') Plt.subplot (322) Plt.imshow (digits.images[1792], Cmap=plt.cm.gray_r, interpolation= ' nearest ') plt.subplot (323) plt.imshow (digits.images[< Span class= "number" >1793], Cmap=plt.cm.gray_r, Interpolation= ' nearest ') plt.subplot (324) plt.imshow (digits.images[1794], Cmap=plt.cm.gray_r, Interpolation= ' nearest ') Plt.subplot (325) plt.imshow (Digits.images[1795 ], Cmap=plt.cm.gray_r, Interpolation= ' nearest ') plt.subplot (326) plt.imshow (Digits.images[1796], Cmap=plt.cm.gray _r, Interpolation= ' nearest ') |
<matplotlib.image.AxesImage at 0x175e6b00>
1
|
Svc.predict (digits.data[1791:1976])
|
array([4, 9, 0, 8, 9, 8])
1
|
digits.target[1791:1976]
|
array([4, 9, 0, 8, 9, 8])
Python data Analytics-the 11th chapter-Identifying handwritten numbers