Created
May 17, 2017 21:21
-
-
Save bsaf/9a9d7aa5a3e7f6f414f5303aea787c3f to your computer and use it in GitHub Desktop.
scikit learn digits example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load the digits dataset | |
from sklearn import datasets | |
digits = datasets.load_digits() | |
# show the data | |
digits.data | |
# show the answers | |
digits.target | |
# each item is a 2D array | |
digits.data[0] | |
# the original image is an 8,8 array | |
digits.images[0] | |
# show an image | |
from matplotlib import pyplot as plt | |
plt.imshow(digits.images[0], interpolation='nearest') | |
plt.show() | |
# import an estimator to do the predicting | |
from sklearn import svm | |
# set it up with some params | |
clf = svm.SVC(gamma=0.001, C=100.) | |
# train it on all but the last digit | |
clf.fit(digits.data[:-1], digits.target[:-1]) | |
# predict the last digit | |
clf.predict(digits.data[-1:]) | |
# check the 'answer' for the last digit | |
digits.target[-1:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment