Skip to content

Commit f348fa3

Browse files
committed
Pushing the docs to dev/ for branch: master, commit bbedfa0216877e26376acf147c50458710a4fc03
1 parent 6aade94 commit f348fa3

File tree

1,205 files changed

+3714
-3732
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,205 files changed

+3714
-3732
lines changed

dev/_downloads/206285a20b3b1231a7792b027515ea8f/plot_lasso_model_selection.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: Olivier Grisel, Gael Varoquaux, Alexandre Gramfort\n# License: BSD 3 clause\n\nimport time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn.linear_model import LassoCV, LassoLarsCV, LassoLarsIC\nfrom sklearn import datasets\n\n# This is to avoid division by zero while doing np.log10\nEPSILON = 1e-4\n\nX, y = datasets.load_diabetes(return_X_y=True)\n\nrng = np.random.RandomState(42)\nX = np.c_[X, rng.randn(X.shape[0], 14)] # add some bad features\n\n# normalize data as done by Lars to allow for comparison\nX /= np.sqrt(np.sum(X ** 2, axis=0))\n\n# #############################################################################\n# LassoLarsIC: least angle regression with BIC/AIC criterion\n\nmodel_bic = LassoLarsIC(criterion='bic')\nt1 = time.time()\nmodel_bic.fit(X, y)\nt_bic = time.time() - t1\nalpha_bic_ = model_bic.alpha_\n\nmodel_aic = LassoLarsIC(criterion='aic')\nmodel_aic.fit(X, y)\nalpha_aic_ = model_aic.alpha_\n\n\ndef plot_ic_criterion(model, name, color):\n alpha_ = model.alpha_ + EPSILON\n alphas_ = model.alphas_ + EPSILON\n criterion_ = model.criterion_\n plt.plot(-np.log10(alphas_), criterion_, '--', color=color,\n linewidth=3, label='%s criterion' % name)\n plt.axvline(-np.log10(alpha_), color=color, linewidth=3,\n label='alpha: %s estimate' % name)\n plt.xlabel('-log(alpha)')\n plt.ylabel('criterion')\n\n\nplt.figure()\nplot_ic_criterion(model_aic, 'AIC', 'b')\nplot_ic_criterion(model_bic, 'BIC', 'r')\nplt.legend()\nplt.title('Information-criterion for model selection (training time %.3fs)'\n % t_bic)\n\n# #############################################################################\n# LassoCV: coordinate descent\n\n# Compute paths\nprint(\"Computing regularization path using the coordinate descent lasso...\")\nt1 = time.time()\nmodel = LassoCV(cv=20).fit(X, y)\nt_lasso_cv = time.time() - t1\n\n# Display results\nm_log_alphas = -np.log10(model.alphas_ + EPSILON)\n\nplt.figure()\nymin, ymax = 2300, 3800\nplt.plot(m_log_alphas, model.mse_path_, ':')\nplt.plot(m_log_alphas, model.mse_path_.mean(axis=-1), 'k',\n label='Average across the folds', linewidth=2)\nplt.axvline(-np.log10(model.alpha_ + EPSILON), linestyle='--', color='k',\n label='alpha: CV estimate')\n\nplt.legend()\n\nplt.xlabel('-log(alpha)')\nplt.ylabel('Mean square error')\nplt.title('Mean square error on each fold: coordinate descent '\n '(train time: %.2fs)' % t_lasso_cv)\nplt.axis('tight')\nplt.ylim(ymin, ymax)\n\n# #############################################################################\n# LassoLarsCV: least angle regression\n\n# Compute paths\nprint(\"Computing regularization path using the Lars lasso...\")\nt1 = time.time()\nmodel = LassoLarsCV(cv=20).fit(X, y)\nt_lasso_lars_cv = time.time() - t1\n\n# Display results\nm_log_alphas = -np.log10(model.cv_alphas_ + EPSILON)\n\nplt.figure()\nplt.plot(m_log_alphas, model.mse_path_, ':')\nplt.plot(m_log_alphas, model.mse_path_.mean(axis=-1), 'k',\n label='Average across the folds', linewidth=2)\nplt.axvline(-np.log10(model.alpha_), linestyle='--', color='k',\n label='alpha CV')\nplt.legend()\n\nplt.xlabel('-log(alpha)')\nplt.ylabel('Mean square error')\nplt.title('Mean square error on each fold: Lars (train time: %.2fs)'\n % t_lasso_lars_cv)\nplt.axis('tight')\nplt.ylim(ymin, ymax)\n\nplt.show()"
29+
"print(__doc__)\n\n# Author: Olivier Grisel, Gael Varoquaux, Alexandre Gramfort\n# License: BSD 3 clause\n\nimport time\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn.linear_model import LassoCV, LassoLarsCV, LassoLarsIC\nfrom sklearn import datasets\n\n# This is to avoid division by zero while doing np.log10\nEPSILON = 1e-4\n\nX, y = datasets.load_diabetes(return_X_y=True)\n\nrng = np.random.RandomState(42)\nX = np.c_[X, rng.randn(X.shape[0], 14)] # add some bad features\n\n# normalize data as done by Lars to allow for comparison\nX /= np.sqrt(np.sum(X ** 2, axis=0))\n\n# #############################################################################\n# LassoLarsIC: least angle regression with BIC/AIC criterion\n\nmodel_bic = LassoLarsIC(criterion='bic')\nt1 = time.time()\nmodel_bic.fit(X, y)\nt_bic = time.time() - t1\nalpha_bic_ = model_bic.alpha_\n\nmodel_aic = LassoLarsIC(criterion='aic')\nmodel_aic.fit(X, y)\nalpha_aic_ = model_aic.alpha_\n\n\ndef plot_ic_criterion(model, name, color):\n criterion_ = model.criterion_\n plt.semilogx(model.alphas_ + EPSILON, criterion_, '--', color=color,\n linewidth=3, label='%s criterion' % name)\n plt.axvline(model.alpha_ + EPSILON, color=color, linewidth=3,\n label='alpha: %s estimate' % name)\n plt.xlabel(r'$\\alpha$')\n plt.ylabel('criterion')\n\n\nplt.figure()\nplot_ic_criterion(model_aic, 'AIC', 'b')\nplot_ic_criterion(model_bic, 'BIC', 'r')\nplt.legend()\nplt.title('Information-criterion for model selection (training time %.3fs)'\n % t_bic)\n\n# #############################################################################\n# LassoCV: coordinate descent\n\n# Compute paths\nprint(\"Computing regularization path using the coordinate descent lasso...\")\nt1 = time.time()\nmodel = LassoCV(cv=20).fit(X, y)\nt_lasso_cv = time.time() - t1\n\n# Display results\nplt.figure()\nymin, ymax = 2300, 3800\nplt.semilogx(model.alphas_ + EPSILON, model.mse_path_, ':')\nplt.plot(model.alphas_ + EPSILON, model.mse_path_.mean(axis=-1), 'k',\n label='Average across the folds', linewidth=2)\nplt.axvline(model.alpha_ + EPSILON, linestyle='--', color='k',\n label='alpha: CV estimate')\n\nplt.legend()\n\nplt.xlabel(r'$\\alpha$')\nplt.ylabel('Mean square error')\nplt.title('Mean square error on each fold: coordinate descent '\n '(train time: %.2fs)' % t_lasso_cv)\nplt.axis('tight')\nplt.ylim(ymin, ymax)\n\n# #############################################################################\n# LassoLarsCV: least angle regression\n\n# Compute paths\nprint(\"Computing regularization path using the Lars lasso...\")\nt1 = time.time()\nmodel = LassoLarsCV(cv=20).fit(X, y)\nt_lasso_lars_cv = time.time() - t1\n\n# Display results\nplt.figure()\nplt.semilogx(model.cv_alphas_ + EPSILON, model.mse_path_, ':')\nplt.semilogx(model.cv_alphas_ + EPSILON, model.mse_path_.mean(axis=-1), 'k',\n label='Average across the folds', linewidth=2)\nplt.axvline(model.alpha_, linestyle='--', color='k',\n label='alpha CV')\nplt.legend()\n\nplt.xlabel(r'$\\alpha$')\nplt.ylabel('Mean square error')\nplt.title('Mean square error on each fold: Lars (train time: %.2fs)'\n % t_lasso_lars_cv)\nplt.axis('tight')\nplt.ylim(ymin, ymax)\n\nplt.show()"
3030
]
3131
}
3232
],
Binary file not shown.

dev/_downloads/64cb62fe8f8f5f93b1b63fb7d0d85095/plot_lasso_model_selection.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,12 @@
8080

8181

8282
def plot_ic_criterion(model, name, color):
83-
alpha_ = model.alpha_ + EPSILON
84-
alphas_ = model.alphas_ + EPSILON
8583
criterion_ = model.criterion_
86-
plt.plot(-np.log10(alphas_), criterion_, '--', color=color,
87-
linewidth=3, label='%s criterion' % name)
88-
plt.axvline(-np.log10(alpha_), color=color, linewidth=3,
84+
plt.semilogx(model.alphas_ + EPSILON, criterion_, '--', color=color,
85+
linewidth=3, label='%s criterion' % name)
86+
plt.axvline(model.alpha_ + EPSILON, color=color, linewidth=3,
8987
label='alpha: %s estimate' % name)
90-
plt.xlabel('-log(alpha)')
88+
plt.xlabel(r'$\alpha$')
9189
plt.ylabel('criterion')
9290

9391

@@ -108,19 +106,17 @@ def plot_ic_criterion(model, name, color):
108106
t_lasso_cv = time.time() - t1
109107

110108
# Display results
111-
m_log_alphas = -np.log10(model.alphas_ + EPSILON)
112-
113109
plt.figure()
114110
ymin, ymax = 2300, 3800
115-
plt.plot(m_log_alphas, model.mse_path_, ':')
116-
plt.plot(m_log_alphas, model.mse_path_.mean(axis=-1), 'k',
111+
plt.semilogx(model.alphas_ + EPSILON, model.mse_path_, ':')
112+
plt.plot(model.alphas_ + EPSILON, model.mse_path_.mean(axis=-1), 'k',
117113
label='Average across the folds', linewidth=2)
118-
plt.axvline(-np.log10(model.alpha_ + EPSILON), linestyle='--', color='k',
114+
plt.axvline(model.alpha_ + EPSILON, linestyle='--', color='k',
119115
label='alpha: CV estimate')
120116

121117
plt.legend()
122118

123-
plt.xlabel('-log(alpha)')
119+
plt.xlabel(r'$\alpha$')
124120
plt.ylabel('Mean square error')
125121
plt.title('Mean square error on each fold: coordinate descent '
126122
'(train time: %.2fs)' % t_lasso_cv)
@@ -137,17 +133,15 @@ def plot_ic_criterion(model, name, color):
137133
t_lasso_lars_cv = time.time() - t1
138134

139135
# Display results
140-
m_log_alphas = -np.log10(model.cv_alphas_ + EPSILON)
141-
142136
plt.figure()
143-
plt.plot(m_log_alphas, model.mse_path_, ':')
144-
plt.plot(m_log_alphas, model.mse_path_.mean(axis=-1), 'k',
145-
label='Average across the folds', linewidth=2)
146-
plt.axvline(-np.log10(model.alpha_), linestyle='--', color='k',
137+
plt.semilogx(model.cv_alphas_ + EPSILON, model.mse_path_, ':')
138+
plt.semilogx(model.cv_alphas_ + EPSILON, model.mse_path_.mean(axis=-1), 'k',
139+
label='Average across the folds', linewidth=2)
140+
plt.axvline(model.alpha_, linestyle='--', color='k',
147141
label='alpha CV')
148142
plt.legend()
149143

150-
plt.xlabel('-log(alpha)')
144+
plt.xlabel(r'$\alpha$')
151145
plt.ylabel('Mean square error')
152146
plt.title('Mean square error on each fold: Lars (train time: %.2fs)'
153147
% t_lasso_lars_cv)
Binary file not shown.

dev/_downloads/scikit-learn-docs.pdf

33.9 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
-552 Bytes
-32 Bytes
-166 Bytes
-166 Bytes
538 Bytes
538 Bytes
-16 Bytes
-47 Bytes
44 Bytes
44 Bytes
15 Bytes
-273 Bytes
-273 Bytes
-183 Bytes
-93 Bytes
-256 Bytes
4.04 KB
157 Bytes
-161 Bytes
-424 Bytes
-424 Bytes
-5 Bytes
-5 Bytes
165 Bytes
165 Bytes
-109 Bytes
-109 Bytes
120 Bytes
120 Bytes
-136 Bytes
-136 Bytes
149 Bytes
105 Bytes
105 Bytes
-71 Bytes
-138 Bytes
-138 Bytes
-121 Bytes
-729 Bytes
59 Bytes
59 Bytes
-34 Bytes
-5 Bytes

dev/_sources/auto_examples/applications/plot_face_recognition.rst.txt

Lines changed: 5 additions & 5 deletions

dev/_sources/auto_examples/applications/plot_model_complexity_influence.rst.txt

Lines changed: 15 additions & 15 deletions

0 commit comments

Comments
 (0)