Skip to content

Commit 81332b6

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 3c6f2b09061a49a0ca281f6b651ae3dc61d7e34f
1 parent 2f62cbe commit 81332b6

File tree

897 files changed

+2580
-2598
lines changed

Some content is hidden

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

897 files changed

+2580
-2598
lines changed
-92 Bytes
Binary file not shown.
-86 Bytes
Binary file not shown.

dev/_downloads/plot_cv_diabetes.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"execution_count": null,
2525
"cell_type": "code",
2626
"source": [
27-
"from __future__ import print_function\nprint(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn import datasets\nfrom sklearn.linear_model import LassoCV\nfrom sklearn.linear_model import Lasso\nfrom sklearn.model_selection import KFold\nfrom sklearn.model_selection import cross_val_score\n\ndiabetes = datasets.load_diabetes()\nX = diabetes.data[:150]\ny = diabetes.target[:150]\n\nlasso = Lasso(random_state=0)\nalphas = np.logspace(-4, -0.5, 30)\n\nscores = list()\nscores_std = list()\n\nn_folds = 3\n\nfor alpha in alphas:\n lasso.alpha = alpha\n this_scores = cross_val_score(lasso, X, y, cv=n_folds, n_jobs=1)\n scores.append(np.mean(this_scores))\n scores_std.append(np.std(this_scores))\n\nscores, scores_std = np.array(scores), np.array(scores_std)\n\nplt.figure().set_size_inches(8, 6)\nplt.semilogx(alphas, scores)\n\n# plot error lines showing +/- std. errors of the scores\nstd_error = scores_std / np.sqrt(n_folds)\n\nplt.semilogx(alphas, scores + std_error, 'b--')\nplt.semilogx(alphas, scores - std_error, 'b--')\n\n# alpha=0.2 controls the translucency of the fill color\nplt.fill_between(alphas, scores + std_error, scores - std_error, alpha=0.2)\n\nplt.ylabel('CV score +/- std error')\nplt.xlabel('alpha')\nplt.axhline(np.max(scores), linestyle='--', color='.5')\nplt.xlim([alphas[0], alphas[-1]])"
27+
"from __future__ import print_function\nprint(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn import datasets\nfrom sklearn.linear_model import LassoCV\nfrom sklearn.linear_model import Lasso\nfrom sklearn.model_selection import KFold\nfrom sklearn.model_selection import GridSearchCV\n\ndiabetes = datasets.load_diabetes()\nX = diabetes.data[:150]\ny = diabetes.target[:150]\n\nlasso = Lasso(random_state=0)\nalphas = np.logspace(-4, -0.5, 30)\n\ntuned_parameters = [{'alpha': alphas}]\nn_folds = 3\n\nclf = GridSearchCV(lasso, tuned_parameters, cv=n_folds, refit=False)\nclf.fit(X, y)\nscores = clf.cv_results_['mean_test_score']\nscores_std = clf.cv_results_['std_test_score']\nplt.figure().set_size_inches(8, 6)\nplt.semilogx(alphas, scores)\n\n# plot error lines showing +/- std. errors of the scores\nstd_error = scores_std / np.sqrt(n_folds)\n\nplt.semilogx(alphas, scores + std_error, 'b--')\nplt.semilogx(alphas, scores - std_error, 'b--')\n\n# alpha=0.2 controls the translucency of the fill color\nplt.fill_between(alphas, scores + std_error, scores - std_error, alpha=0.2)\n\nplt.ylabel('CV score +/- std error')\nplt.xlabel('alpha')\nplt.axhline(np.max(scores), linestyle='--', color='.5')\nplt.xlim([alphas[0], alphas[-1]])"
2828
],
2929
"outputs": [],
3030
"metadata": {

dev/_downloads/plot_cv_diabetes.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from sklearn.linear_model import LassoCV
2020
from sklearn.linear_model import Lasso
2121
from sklearn.model_selection import KFold
22-
from sklearn.model_selection import cross_val_score
22+
from sklearn.model_selection import GridSearchCV
2323

2424
diabetes = datasets.load_diabetes()
2525
X = diabetes.data[:150]
@@ -28,19 +28,13 @@
2828
lasso = Lasso(random_state=0)
2929
alphas = np.logspace(-4, -0.5, 30)
3030

31-
scores = list()
32-
scores_std = list()
33-
31+
tuned_parameters = [{'alpha': alphas}]
3432
n_folds = 3
3533

36-
for alpha in alphas:
37-
lasso.alpha = alpha
38-
this_scores = cross_val_score(lasso, X, y, cv=n_folds, n_jobs=1)
39-
scores.append(np.mean(this_scores))
40-
scores_std.append(np.std(this_scores))
41-
42-
scores, scores_std = np.array(scores), np.array(scores_std)
43-
34+
clf = GridSearchCV(lasso, tuned_parameters, cv=n_folds, refit=False)
35+
clf.fit(X, y)
36+
scores = clf.cv_results_['mean_test_score']
37+
scores_std = clf.cv_results_['std_test_score']
4438
plt.figure().set_size_inches(8, 6)
4539
plt.semilogx(alphas, scores)
4640

dev/_downloads/scikit-learn-docs.pdf

1.66 KB
Binary file not shown.
-24 Bytes
-24 Bytes
91 Bytes
91 Bytes
130 Bytes

0 commit comments

Comments
 (0)