-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathp02.py
More file actions
22 lines (19 loc) · 733 Bytes
/
p02.py
File metadata and controls
22 lines (19 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn import svm
digits = datasets.load_digits()
print(digits.data)
print(digits.target)
# digits.target is the actual label we've assigned to the digits data.
# Now that we've got the data ready, we're ready to do the machine learning.
# First, we specify the classifier:
# If you want, you can just leave parameters blank and use the defaults, like this:
# clf = svm.SVC()
# clf = svm.SVC(gamma=0.001, C=100)
# clf = svm.SVC(gamma=0.01, C=100)
clf = svm.SVC(gamma=0.0001, C=100)
X,y = digits.data[:-10], digits.target[:-10]
clf.fit(X,y)
print(clf.predict(digits.data[-5]))
plt.imshow(digits.images[-5], cmap=plt.cm.gray_r, interpolation='nearest')
plt.show()