Skip to content

Commit c360bc7

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 31a75c004d91e909a43a6abb16301a0cfe37a557
1 parent bb476e6 commit c360bc7

File tree

1,223 files changed

+4218
-4218
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,223 files changed

+4218
-4218
lines changed
Binary file not shown.

dev/_downloads/57163227aeb4c19ca4c69b87a8d1949c/plot_learning_curve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ def plot_learning_curve(
179179
X, y = load_digits(return_X_y=True)
180180

181181
title = "Learning Curves (Naive Bayes)"
182-
# Cross validation with 100 iterations to get smoother mean test and train
182+
# Cross validation with 50 iterations to get smoother mean test and train
183183
# score curves, each time with 20% data randomly selected as a validation set.
184-
cv = ShuffleSplit(n_splits=100, test_size=0.2, random_state=0)
184+
cv = ShuffleSplit(n_splits=50, test_size=0.2, random_state=0)
185185

186186
estimator = GaussianNB()
187187
plot_learning_curve(
@@ -190,7 +190,7 @@ def plot_learning_curve(
190190

191191
title = r"Learning Curves (SVM, RBF kernel, $\gamma=0.001$)"
192192
# SVC is more expensive so we do a lower number of CV iterations:
193-
cv = ShuffleSplit(n_splits=10, test_size=0.2, random_state=0)
193+
cv = ShuffleSplit(n_splits=5, test_size=0.2, random_state=0)
194194
estimator = SVC(gamma=0.001)
195195
plot_learning_curve(
196196
estimator, title, X, y, axes=axes[:, 1], ylim=(0.7, 1.01), cv=cv, n_jobs=4
Binary file not shown.

dev/_downloads/ca0bfe2435d9b3fffe21c713e63d3a6f/plot_learning_curve.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-
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.svm import SVC\nfrom sklearn.datasets import load_digits\nfrom sklearn.model_selection import learning_curve\nfrom sklearn.model_selection import ShuffleSplit\n\n\ndef plot_learning_curve(\n estimator,\n title,\n X,\n y,\n axes=None,\n ylim=None,\n cv=None,\n n_jobs=None,\n train_sizes=np.linspace(0.1, 1.0, 5),\n):\n \"\"\"\n Generate 3 plots: the test and training learning curve, the training\n samples vs fit times curve, the fit times vs score curve.\n\n Parameters\n ----------\n estimator : estimator instance\n An estimator instance implementing `fit` and `predict` methods which\n will be cloned for each validation.\n\n title : str\n Title for the chart.\n\n X : array-like of shape (n_samples, n_features)\n Training vector, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features.\n\n y : array-like of shape (n_samples) or (n_samples, n_features)\n Target relative to ``X`` for classification or regression;\n None for unsupervised learning.\n\n axes : array-like of shape (3,), default=None\n Axes to use for plotting the curves.\n\n ylim : tuple of shape (2,), default=None\n Defines minimum and maximum y-values plotted, e.g. (ymin, ymax).\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if ``y`` is binary or multiclass,\n :class:`StratifiedKFold` used. If the estimator is not a classifier\n or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.\n\n Refer :ref:`User Guide <cross_validation>` for the various\n cross-validators that can be used here.\n\n n_jobs : int or None, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary <n_jobs>`\n for more details.\n\n train_sizes : array-like of shape (n_ticks,)\n Relative or absolute numbers of training examples that will be used to\n generate the learning curve. If the ``dtype`` is float, it is regarded\n as a fraction of the maximum size of the training set (that is\n determined by the selected validation method), i.e. it has to be within\n (0, 1]. Otherwise it is interpreted as absolute sizes of the training\n sets. Note that for classification the number of samples usually have\n to be big enough to contain at least one sample from each class.\n (default: np.linspace(0.1, 1.0, 5))\n \"\"\"\n if axes is None:\n _, axes = plt.subplots(1, 3, figsize=(20, 5))\n\n axes[0].set_title(title)\n if ylim is not None:\n axes[0].set_ylim(*ylim)\n axes[0].set_xlabel(\"Training examples\")\n axes[0].set_ylabel(\"Score\")\n\n train_sizes, train_scores, test_scores, fit_times, _ = learning_curve(\n estimator,\n X,\n y,\n cv=cv,\n n_jobs=n_jobs,\n train_sizes=train_sizes,\n return_times=True,\n )\n train_scores_mean = np.mean(train_scores, axis=1)\n train_scores_std = np.std(train_scores, axis=1)\n test_scores_mean = np.mean(test_scores, axis=1)\n test_scores_std = np.std(test_scores, axis=1)\n fit_times_mean = np.mean(fit_times, axis=1)\n fit_times_std = np.std(fit_times, axis=1)\n\n # Plot learning curve\n axes[0].grid()\n axes[0].fill_between(\n train_sizes,\n train_scores_mean - train_scores_std,\n train_scores_mean + train_scores_std,\n alpha=0.1,\n color=\"r\",\n )\n axes[0].fill_between(\n train_sizes,\n test_scores_mean - test_scores_std,\n test_scores_mean + test_scores_std,\n alpha=0.1,\n color=\"g\",\n )\n axes[0].plot(\n train_sizes, train_scores_mean, \"o-\", color=\"r\", label=\"Training score\"\n )\n axes[0].plot(\n train_sizes, test_scores_mean, \"o-\", color=\"g\", label=\"Cross-validation score\"\n )\n axes[0].legend(loc=\"best\")\n\n # Plot n_samples vs fit_times\n axes[1].grid()\n axes[1].plot(train_sizes, fit_times_mean, \"o-\")\n axes[1].fill_between(\n train_sizes,\n fit_times_mean - fit_times_std,\n fit_times_mean + fit_times_std,\n alpha=0.1,\n )\n axes[1].set_xlabel(\"Training examples\")\n axes[1].set_ylabel(\"fit_times\")\n axes[1].set_title(\"Scalability of the model\")\n\n # Plot fit_time vs score\n axes[2].grid()\n axes[2].plot(fit_times_mean, test_scores_mean, \"o-\")\n axes[2].fill_between(\n fit_times_mean,\n test_scores_mean - test_scores_std,\n test_scores_mean + test_scores_std,\n alpha=0.1,\n )\n axes[2].set_xlabel(\"fit_times\")\n axes[2].set_ylabel(\"Score\")\n axes[2].set_title(\"Performance of the model\")\n\n return plt\n\n\nfig, axes = plt.subplots(3, 2, figsize=(10, 15))\n\nX, y = load_digits(return_X_y=True)\n\ntitle = \"Learning Curves (Naive Bayes)\"\n# Cross validation with 100 iterations to get smoother mean test and train\n# score curves, each time with 20% data randomly selected as a validation set.\ncv = ShuffleSplit(n_splits=100, test_size=0.2, random_state=0)\n\nestimator = GaussianNB()\nplot_learning_curve(\n estimator, title, X, y, axes=axes[:, 0], ylim=(0.7, 1.01), cv=cv, n_jobs=4\n)\n\ntitle = r\"Learning Curves (SVM, RBF kernel, $\\gamma=0.001$)\"\n# SVC is more expensive so we do a lower number of CV iterations:\ncv = ShuffleSplit(n_splits=10, test_size=0.2, random_state=0)\nestimator = SVC(gamma=0.001)\nplot_learning_curve(\n estimator, title, X, y, axes=axes[:, 1], ylim=(0.7, 1.01), cv=cv, n_jobs=4\n)\n\nplt.show()"
29+
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.svm import SVC\nfrom sklearn.datasets import load_digits\nfrom sklearn.model_selection import learning_curve\nfrom sklearn.model_selection import ShuffleSplit\n\n\ndef plot_learning_curve(\n estimator,\n title,\n X,\n y,\n axes=None,\n ylim=None,\n cv=None,\n n_jobs=None,\n train_sizes=np.linspace(0.1, 1.0, 5),\n):\n \"\"\"\n Generate 3 plots: the test and training learning curve, the training\n samples vs fit times curve, the fit times vs score curve.\n\n Parameters\n ----------\n estimator : estimator instance\n An estimator instance implementing `fit` and `predict` methods which\n will be cloned for each validation.\n\n title : str\n Title for the chart.\n\n X : array-like of shape (n_samples, n_features)\n Training vector, where ``n_samples`` is the number of samples and\n ``n_features`` is the number of features.\n\n y : array-like of shape (n_samples) or (n_samples, n_features)\n Target relative to ``X`` for classification or regression;\n None for unsupervised learning.\n\n axes : array-like of shape (3,), default=None\n Axes to use for plotting the curves.\n\n ylim : tuple of shape (2,), default=None\n Defines minimum and maximum y-values plotted, e.g. (ymin, ymax).\n\n cv : int, cross-validation generator or an iterable, default=None\n Determines the cross-validation splitting strategy.\n Possible inputs for cv are:\n\n - None, to use the default 5-fold cross-validation,\n - integer, to specify the number of folds.\n - :term:`CV splitter`,\n - An iterable yielding (train, test) splits as arrays of indices.\n\n For integer/None inputs, if ``y`` is binary or multiclass,\n :class:`StratifiedKFold` used. If the estimator is not a classifier\n or if ``y`` is neither binary nor multiclass, :class:`KFold` is used.\n\n Refer :ref:`User Guide <cross_validation>` for the various\n cross-validators that can be used here.\n\n n_jobs : int or None, default=None\n Number of jobs to run in parallel.\n ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n ``-1`` means using all processors. See :term:`Glossary <n_jobs>`\n for more details.\n\n train_sizes : array-like of shape (n_ticks,)\n Relative or absolute numbers of training examples that will be used to\n generate the learning curve. If the ``dtype`` is float, it is regarded\n as a fraction of the maximum size of the training set (that is\n determined by the selected validation method), i.e. it has to be within\n (0, 1]. Otherwise it is interpreted as absolute sizes of the training\n sets. Note that for classification the number of samples usually have\n to be big enough to contain at least one sample from each class.\n (default: np.linspace(0.1, 1.0, 5))\n \"\"\"\n if axes is None:\n _, axes = plt.subplots(1, 3, figsize=(20, 5))\n\n axes[0].set_title(title)\n if ylim is not None:\n axes[0].set_ylim(*ylim)\n axes[0].set_xlabel(\"Training examples\")\n axes[0].set_ylabel(\"Score\")\n\n train_sizes, train_scores, test_scores, fit_times, _ = learning_curve(\n estimator,\n X,\n y,\n cv=cv,\n n_jobs=n_jobs,\n train_sizes=train_sizes,\n return_times=True,\n )\n train_scores_mean = np.mean(train_scores, axis=1)\n train_scores_std = np.std(train_scores, axis=1)\n test_scores_mean = np.mean(test_scores, axis=1)\n test_scores_std = np.std(test_scores, axis=1)\n fit_times_mean = np.mean(fit_times, axis=1)\n fit_times_std = np.std(fit_times, axis=1)\n\n # Plot learning curve\n axes[0].grid()\n axes[0].fill_between(\n train_sizes,\n train_scores_mean - train_scores_std,\n train_scores_mean + train_scores_std,\n alpha=0.1,\n color=\"r\",\n )\n axes[0].fill_between(\n train_sizes,\n test_scores_mean - test_scores_std,\n test_scores_mean + test_scores_std,\n alpha=0.1,\n color=\"g\",\n )\n axes[0].plot(\n train_sizes, train_scores_mean, \"o-\", color=\"r\", label=\"Training score\"\n )\n axes[0].plot(\n train_sizes, test_scores_mean, \"o-\", color=\"g\", label=\"Cross-validation score\"\n )\n axes[0].legend(loc=\"best\")\n\n # Plot n_samples vs fit_times\n axes[1].grid()\n axes[1].plot(train_sizes, fit_times_mean, \"o-\")\n axes[1].fill_between(\n train_sizes,\n fit_times_mean - fit_times_std,\n fit_times_mean + fit_times_std,\n alpha=0.1,\n )\n axes[1].set_xlabel(\"Training examples\")\n axes[1].set_ylabel(\"fit_times\")\n axes[1].set_title(\"Scalability of the model\")\n\n # Plot fit_time vs score\n axes[2].grid()\n axes[2].plot(fit_times_mean, test_scores_mean, \"o-\")\n axes[2].fill_between(\n fit_times_mean,\n test_scores_mean - test_scores_std,\n test_scores_mean + test_scores_std,\n alpha=0.1,\n )\n axes[2].set_xlabel(\"fit_times\")\n axes[2].set_ylabel(\"Score\")\n axes[2].set_title(\"Performance of the model\")\n\n return plt\n\n\nfig, axes = plt.subplots(3, 2, figsize=(10, 15))\n\nX, y = load_digits(return_X_y=True)\n\ntitle = \"Learning Curves (Naive Bayes)\"\n# Cross validation with 50 iterations to get smoother mean test and train\n# score curves, each time with 20% data randomly selected as a validation set.\ncv = ShuffleSplit(n_splits=50, test_size=0.2, random_state=0)\n\nestimator = GaussianNB()\nplot_learning_curve(\n estimator, title, X, y, axes=axes[:, 0], ylim=(0.7, 1.01), cv=cv, n_jobs=4\n)\n\ntitle = r\"Learning Curves (SVM, RBF kernel, $\\gamma=0.001$)\"\n# SVC is more expensive so we do a lower number of CV iterations:\ncv = ShuffleSplit(n_splits=5, test_size=0.2, random_state=0)\nestimator = SVC(gamma=0.001)\nplot_learning_curve(\n estimator, title, X, y, axes=axes[:, 1], ylim=(0.7, 1.01), cv=cv, n_jobs=4\n)\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/scikit-learn-docs.zip

12.9 KB
Binary file not shown.
76 Bytes
80 Bytes
226 Bytes
-215 Bytes
24 Bytes

0 commit comments

Comments
 (0)