Skip to content

Commit 79e058d

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 3379e90f6dd658881d828f1d65d3e01d2140eb1a
1 parent bb95928 commit 79e058d

File tree

713 files changed

+1699
-1712
lines changed

Some content is hidden

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

713 files changed

+1699
-1712
lines changed

dev/_downloads/00701bf1048deb8daeb5ad086596d260/plot_lasso_lars.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: Fabian Pedregosa <[email protected]>\n# Alexandre Gramfort <[email protected]>\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn import linear_model\nfrom sklearn import datasets\n\ndiabetes = datasets.load_diabetes()\nX = diabetes.data\ny = diabetes.target\n\nprint(\"Computing regularization path using the LARS ...\")\n_, _, coefs = linear_model.lars_path(X, y, method='lasso', verbose=True)\n\nxx = np.sum(np.abs(coefs.T), axis=1)\nxx /= xx[-1]\n\nplt.plot(xx, coefs.T)\nymin, ymax = plt.ylim()\nplt.vlines(xx, ymin, ymax, linestyle='dashed')\nplt.xlabel('|coef| / max|coef|')\nplt.ylabel('Coefficients')\nplt.title('LASSO Path')\nplt.axis('tight')\nplt.show()"
29+
"print(__doc__)\n\n# Author: Fabian Pedregosa <[email protected]>\n# Alexandre Gramfort <[email protected]>\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn import linear_model\nfrom sklearn import datasets\n\nX, y = datasets.load_diabetes(return_X_y=True)\n\nprint(\"Computing regularization path using the LARS ...\")\n_, _, coefs = linear_model.lars_path(X, y, method='lasso', verbose=True)\n\nxx = np.sum(np.abs(coefs.T), axis=1)\nxx /= xx[-1]\n\nplt.plot(xx, coefs.T)\nymin, ymax = plt.ylim()\nplt.vlines(xx, ymin, ymax, linestyle='dashed')\nplt.xlabel('|coef| / max|coef|')\nplt.ylabel('Coefficients')\nplt.title('LASSO Path')\nplt.axis('tight')\nplt.show()"
3030
]
3131
}
3232
],

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\ndiabetes = datasets.load_diabetes()\nX = diabetes.data\ny = diabetes.target\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\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 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()"
3030
]
3131
}
3232
],
Binary file not shown.

dev/_downloads/3bc388ac00a41366cf48b6e294838489/plot_ols.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\n# Code source: Jaques Grobler\n# License: BSD 3 clause\n\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom sklearn import datasets, linear_model\nfrom sklearn.metrics import mean_squared_error, r2_score\n\n# Load the diabetes dataset\ndiabetes = datasets.load_diabetes()\n\n\n# Use only one feature\ndiabetes_X = diabetes.data[:, np.newaxis, 2]\n\n# Split the data into training/testing sets\ndiabetes_X_train = diabetes_X[:-20]\ndiabetes_X_test = diabetes_X[-20:]\n\n# Split the targets into training/testing sets\ndiabetes_y_train = diabetes.target[:-20]\ndiabetes_y_test = diabetes.target[-20:]\n\n# Create linear regression object\nregr = linear_model.LinearRegression()\n\n# Train the model using the training sets\nregr.fit(diabetes_X_train, diabetes_y_train)\n\n# Make predictions using the testing set\ndiabetes_y_pred = regr.predict(diabetes_X_test)\n\n# The coefficients\nprint('Coefficients: \\n', regr.coef_)\n# The mean squared error\nprint('Mean squared error: %.2f'\n % mean_squared_error(diabetes_y_test, diabetes_y_pred))\n# The coefficient of determination: 1 is perfect prediction\nprint('Coefficient of determination: %.2f'\n % r2_score(diabetes_y_test, diabetes_y_pred))\n\n# Plot outputs\nplt.scatter(diabetes_X_test, diabetes_y_test, color='black')\nplt.plot(diabetes_X_test, diabetes_y_pred, color='blue', linewidth=3)\n\nplt.xticks(())\nplt.yticks(())\n\nplt.show()"
29+
"print(__doc__)\n\n\n# Code source: Jaques Grobler\n# License: BSD 3 clause\n\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom sklearn import datasets, linear_model\nfrom sklearn.metrics import mean_squared_error, r2_score\n\n# Load the diabetes dataset\ndiabetes_X, diabetes_y = datasets.load_diabetes(return_X_y=True)\n\n# Use only one feature\ndiabetes_X = diabetes_X[:, np.newaxis, 2]\n\n# Split the data into training/testing sets\ndiabetes_X_train = diabetes_X[:-20]\ndiabetes_X_test = diabetes_X[-20:]\n\n# Split the targets into training/testing sets\ndiabetes_y_train = diabetes_y[:-20]\ndiabetes_y_test = diabetes_y[-20:]\n\n# Create linear regression object\nregr = linear_model.LinearRegression()\n\n# Train the model using the training sets\nregr.fit(diabetes_X_train, diabetes_y_train)\n\n# Make predictions using the testing set\ndiabetes_y_pred = regr.predict(diabetes_X_test)\n\n# The coefficients\nprint('Coefficients: \\n', regr.coef_)\n# The mean squared error\nprint('Mean squared error: %.2f'\n % mean_squared_error(diabetes_y_test, diabetes_y_pred))\n# The coefficient of determination: 1 is perfect prediction\nprint('Coefficient of determination: %.2f'\n % r2_score(diabetes_y_test, diabetes_y_pred))\n\n# Plot outputs\nplt.scatter(diabetes_X_test, diabetes_y_test, color='black')\nplt.plot(diabetes_X_test, diabetes_y_pred, color='blue', linewidth=3)\n\nplt.xticks(())\nplt.yticks(())\n\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/525570147c5d8b2eba26233cf65c8da7/plot_ols.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@
2929
from sklearn.metrics import mean_squared_error, r2_score
3030

3131
# Load the diabetes dataset
32-
diabetes = datasets.load_diabetes()
33-
32+
diabetes_X, diabetes_y = datasets.load_diabetes(return_X_y=True)
3433

3534
# Use only one feature
36-
diabetes_X = diabetes.data[:, np.newaxis, 2]
35+
diabetes_X = diabetes_X[:, np.newaxis, 2]
3736

3837
# Split the data into training/testing sets
3938
diabetes_X_train = diabetes_X[:-20]
4039
diabetes_X_test = diabetes_X[-20:]
4140

4241
# Split the targets into training/testing sets
43-
diabetes_y_train = diabetes.target[:-20]
44-
diabetes_y_test = diabetes.target[-20:]
42+
diabetes_y_train = diabetes_y[:-20]
43+
diabetes_y_test = diabetes_y[-20:]
4544

4645
# Create linear regression object
4746
regr = linear_model.LinearRegression()

dev/_downloads/64cb62fe8f8f5f93b1b63fb7d0d85095/plot_lasso_model_selection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@
5757
# This is to avoid division by zero while doing np.log10
5858
EPSILON = 1e-4
5959

60-
diabetes = datasets.load_diabetes()
61-
X = diabetes.data
62-
y = diabetes.target
60+
X, y = datasets.load_diabetes(return_X_y=True)
6361

6462
rng = np.random.RandomState(42)
6563
X = np.c_[X, rng.randn(X.shape[0], 14)] # add some bad features
@@ -92,6 +90,7 @@ def plot_ic_criterion(model, name, color):
9290
plt.xlabel('-log(alpha)')
9391
plt.ylabel('criterion')
9492

93+
9594
plt.figure()
9695
plot_ic_criterion(model_aic, 'AIC', 'b')
9796
plot_ic_criterion(model_bic, 'BIC', 'r')

dev/_downloads/703c77d8ad4ea9fea3ccbab3a691d9d8/plot_cv_diabetes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from sklearn.model_selection import KFold
2121
from sklearn.model_selection import GridSearchCV
2222

23-
diabetes = datasets.load_diabetes()
24-
X = diabetes.data[:150]
25-
y = diabetes.target[:150]
23+
X, y = datasets.load_diabetes(return_X_y=True)
24+
X = X[:150]
25+
y = y[:150]
2626

2727
lasso = Lasso(random_state=0, max_iter=10000)
2828
alphas = np.logspace(-4, -0.5, 30)

dev/_downloads/79e4690100f4bd29f64fb06c544129d6/plot_lasso_lars.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
from sklearn import linear_model
2323
from sklearn import datasets
2424

25-
diabetes = datasets.load_diabetes()
26-
X = diabetes.data
27-
y = diabetes.target
25+
X, y = datasets.load_diabetes(return_X_y=True)
2826

2927
print("Computing regularization path using the LARS ...")
3028
_, _, coefs = linear_model.lars_path(X, y, method='lasso', verbose=True)

dev/_downloads/915460448434dcfa808fb3b4305bc4fa/plot_ols_3d.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626
from sklearn import datasets, linear_model
2727

28-
diabetes = datasets.load_diabetes()
28+
X, y = datasets.load_diabetes(return_X_y=True)
2929
indices = (0, 1)
3030

31-
X_train = diabetes.data[:-20, indices]
32-
X_test = diabetes.data[-20:, indices]
33-
y_train = diabetes.target[:-20]
34-
y_test = diabetes.target[-20:]
31+
X_train = X[:-20, indices]
32+
X_test = X[-20:, indices]
33+
y_train = y[:-20]
34+
y_test = y[-20:]
3535

3636
ols = linear_model.LinearRegression()
3737
ols.fit(X_train, y_train)
@@ -58,7 +58,8 @@ def plot_figs(fig_num, elev, azim, X_train, clf):
5858
ax.w_yaxis.set_ticklabels([])
5959
ax.w_zaxis.set_ticklabels([])
6060

61-
#Generate the three different figures from different views
61+
62+
# Generate the three different figures from different views
6263
elev = 43.5
6364
azim = -110
6465
plot_figs(1, elev, azim, X_train, ols)

dev/_downloads/9833e959e5148a63a53a15ee99c05f88/plot_lasso_coordinate_descent_path.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from sklearn.linear_model import lasso_path, enet_path
2121
from sklearn import datasets
2222

23-
diabetes = datasets.load_diabetes()
24-
X = diabetes.data
25-
y = diabetes.target
23+
24+
X, y = datasets.load_diabetes(return_X_y=True)
25+
2626

2727
X /= X.std(axis=0) # Standardize data (easier to set the l1_ratio parameter)
2828

0 commit comments

Comments
 (0)