Python data Analytics-the 11th chapter-Identifying handwritten numbers

Source: Internet
Author: User
Tags svm

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 ()
1
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.]])
1
Digits.target.size
1797
1
Digits.target
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.