Skip to content

Commit d0b446f

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 538fa63cc3bd7b1a4e15b946a2aaaa7c950c73ee
1 parent f87d9ad commit d0b446f

File tree

1,217 files changed

+3808
-3792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,217 files changed

+3808
-3792
lines changed
Binary file not shown.

dev/_downloads/622fb50f5e367eda84eb7c32d306f659/plot_digits_classification.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\n# Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>\n# License: BSD 3 clause\n\n# Standard scientific Python imports\nimport matplotlib.pyplot as plt\n\n# Import datasets, classifiers and performance metrics\nfrom sklearn import datasets, svm, metrics\n\n# The digits dataset\ndigits = datasets.load_digits()\n\n# The data that we are interested in is made of 8x8 images of digits, let's\n# have a look at the first 4 images, stored in the `images` attribute of the\n# dataset. If we were working from image files, we could load them using\n# matplotlib.pyplot.imread. Note that each image must have the same size. For these\n# images, we know which digit they represent: it is given in the 'target' of\n# the dataset.\nimages_and_labels = list(zip(digits.images, digits.target))\nfor index, (image, label) in enumerate(images_and_labels[:4]):\n plt.subplot(2, 4, index + 1)\n plt.axis('off')\n plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n plt.title('Training: %i' % label)\n\n# To apply a classifier on this data, we need to flatten the image, to\n# turn the data in a (samples, feature) matrix:\nn_samples = len(digits.images)\ndata = digits.images.reshape((n_samples, -1))\n\n# Create a classifier: a support vector classifier\nclassifier = svm.SVC(gamma=0.001)\n\n# We learn the digits on the first half of the digits\nclassifier.fit(data[:n_samples // 2], digits.target[:n_samples // 2])\n\n# Now predict the value of the digit on the second half:\nexpected = digits.target[n_samples // 2:]\npredicted = classifier.predict(data[n_samples // 2:])\n\nprint(\"Classification report for classifier %s:\\n%s\\n\"\n % (classifier, metrics.classification_report(expected, predicted)))\nprint(\"Confusion matrix:\\n%s\" % metrics.confusion_matrix(expected, predicted))\n\nimages_and_predictions = list(zip(digits.images[n_samples // 2:], predicted))\nfor index, (image, prediction) in enumerate(images_and_predictions[:4]):\n plt.subplot(2, 4, index + 5)\n plt.axis('off')\n plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n plt.title('Prediction: %i' % prediction)\n\nplt.show()"
29+
"print(__doc__)\n\n# Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>\n# License: BSD 3 clause\n\n# Standard scientific Python imports\nimport matplotlib.pyplot as plt\n\n# Import datasets, classifiers and performance metrics\nfrom sklearn import datasets, svm, metrics\nfrom sklearn.model_selection import train_test_split\n\n# The digits dataset\ndigits = datasets.load_digits()\n\n# The data that we are interested in is made of 8x8 images of digits, let's\n# have a look at the first 4 images, stored in the `images` attribute of the\n# dataset. If we were working from image files, we could load them using\n# matplotlib.pyplot.imread. Note that each image must have the same size. For these\n# images, we know which digit they represent: it is given in the 'target' of\n# the dataset.\nimages_and_labels = list(zip(digits.images, digits.target))\nfor index, (image, label) in enumerate(images_and_labels[:4]):\n plt.subplot(2, 4, index + 1)\n plt.axis('off')\n plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n plt.title('Training: %i' % label)\n\n# To apply a classifier on this data, we need to flatten the image, to\n# turn the data in a (samples, feature) matrix:\nn_samples = len(digits.images)\ndata = digits.images.reshape((n_samples, -1))\n\n# Create a classifier: a support vector classifier\nclassifier = svm.SVC(gamma=0.001)\n\n# Split data into train and test subsets\nX_train, X_test, y_train, y_test = train_test_split(\n data, digits.target, test_size=0.5, shuffle=False)\n\n# We learn the digits on the first half of the digits\nclassifier.fit(X_train, y_train)\n\n# Now predict the value of the digit on the second half:\npredicted = classifier.predict(X_test)\n\nprint(\"Classification report for classifier %s:\\n%s\\n\"\n % (classifier, metrics.classification_report(y_test, predicted)))\nprint(\"Confusion matrix:\\n%s\" % metrics.confusion_matrix(y_test, predicted))\n\nimages_and_predictions = list(zip(digits.images[n_samples // 2:], predicted))\nfor index, (image, prediction) in enumerate(images_and_predictions[:4]):\n plt.subplot(2, 4, index + 5)\n plt.axis('off')\n plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n plt.title('Prediction: %i' % prediction)\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/b1e3674706d6abde2dae4b6cfa71be67/plot_digits_classification.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
# Import datasets, classifiers and performance metrics
2222
from sklearn import datasets, svm, metrics
23+
from sklearn.model_selection import train_test_split
2324

2425
# The digits dataset
2526
digits = datasets.load_digits()
@@ -45,16 +46,19 @@
4546
# Create a classifier: a support vector classifier
4647
classifier = svm.SVC(gamma=0.001)
4748

49+
# Split data into train and test subsets
50+
X_train, X_test, y_train, y_test = train_test_split(
51+
data, digits.target, test_size=0.5, shuffle=False)
52+
4853
# We learn the digits on the first half of the digits
49-
classifier.fit(data[:n_samples // 2], digits.target[:n_samples // 2])
54+
classifier.fit(X_train, y_train)
5055

5156
# Now predict the value of the digit on the second half:
52-
expected = digits.target[n_samples // 2:]
53-
predicted = classifier.predict(data[n_samples // 2:])
57+
predicted = classifier.predict(X_test)
5458

5559
print("Classification report for classifier %s:\n%s\n"
56-
% (classifier, metrics.classification_report(expected, predicted)))
57-
print("Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted))
60+
% (classifier, metrics.classification_report(y_test, predicted)))
61+
print("Confusion matrix:\n%s" % metrics.confusion_matrix(y_test, predicted))
5862

5963
images_and_predictions = list(zip(digits.images[n_samples // 2:], predicted))
6064
for index, (image, prediction) in enumerate(images_and_predictions[:4]):
Binary file not shown.

dev/_downloads/scikit-learn-docs.pdf

23.1 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
-492 Bytes
-492 Bytes
760 Bytes
760 Bytes

0 commit comments

Comments
 (0)