e650a207efc9dd33556b1b9678b043f73a18aecb,examples/classification/plot_digits_classification.py,,,#,13

Before Change


print("Confusion matrix:\n%s" % metrics.confusion_matrix(y_test, predicted))

images_and_predictions = list(zip(digits.images[n_samples // 2:], predicted))
for index, (image, prediction) in enumerate(images_and_predictions[:4]):
    plt.subplot(2, 4, index + 5)
    plt.axis("off")
    plt.imshow(image, cmap=plt.cm.gray_r, interpolation="nearest")
    plt.title("Prediction: %i" % prediction)

plt.show()

After Change


// matplotlib.pyplot.imread.  Note that each image must have the same size. For these
// images, we know which digit they represent: it is given in the "target" of
// the dataset.
_, axes = plt.subplots(2, 4)
images_and_labels = list(zip(digits.images, digits.target))
for ax, (image, label) in zip(axes[0, :], images_and_labels[:4]):
    ax.set_axis_off()
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation="nearest")
    ax.set_title("Training: %i" % label)

// To apply a classifier on this data, we need to flatten the image, to
// turn the data in a (samples, feature) matrix:
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1))

// Create a classifier: a support vector classifier
classifier = svm.SVC(gamma=0.001)

// Split data into train and test subsets
X_train, X_test, y_train, y_test = train_test_split(
    data, digits.target, test_size=0.5, shuffle=False)

// We learn the digits on the first half of the digits
classifier.fit(X_train, y_train)

// Now predict the value of the digit on the second half:
predicted = classifier.predict(X_test)

images_and_predictions = list(zip(digits.images[n_samples // 2:], predicted))
for ax, (image, prediction) in zip(axes[1, :], images_and_predictions[:4]):
    ax.set_axis_off()
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation="nearest")
    ax.set_title("Prediction: %i" % prediction)

print("Classification report for classifier %s:\n%s\n"
      % (classifier, metrics.classification_report(y_test, predicted)))
disp = metrics.plot_confusion_matrix(classifier, X_test, y_test)
disp.figure_.suptitle("Confusion Matrix")
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 7

Instances


Project Name: scikit-learn/scikit-learn
Commit Name: e650a207efc9dd33556b1b9678b043f73a18aecb
Time: 2019-11-14
Author: thomasjpfan@gmail.com
File Name: examples/classification/plot_digits_classification.py
Class Name:
Method Name:


Project Name: nilearn/nilearn
Commit Name: 9b9095f877f603d91495c72f91e4fddf61f1724e
Time: 2019-07-22
Author: jerome@dockes.org
File Name: examples/02_decoding/plot_haxby_stimuli.py
Class Name:
Method Name:


Project Name: scikit-image/scikit-image
Commit Name: 958f8f41da4f00c2e9c8d1be0616fcc59c5ee3f0
Time: 2017-10-21
Author: peter@goldsborough.me
File Name: doc/examples/edges/plot_random_shapes.py
Class Name:
Method Name: