Skip to content

Commit 967c7d6

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 37a9d187f9eb4864fb52556e9f293f8ff4f698b7
1 parent fc160eb commit 967c7d6

File tree

1,114 files changed

+6948
-5059
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,114 files changed

+6948
-5059
lines changed

dev/.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 57af4ad45c223405da86d36f09e97508
3+
config: f356e7646dfa6003e9bcdf9a6b0fd0ce
44
tags: 645f666f9bcd5a90fca523b33c5a78b7
1.1 KB
Binary file not shown.
1.08 KB
Binary file not shown.

dev/_downloads/plot_partial_dependence.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\n# Partial Dependence Plots\n\n\nPartial dependence plots show the dependence between the target function [2]_\nand a set of 'target' features, marginalizing over the\nvalues of all other features (the complement features). Due to the limits\nof human perception the size of the target feature set must be small (usually,\none or two) thus the target features are usually chosen among the most\nimportant features\n(see :attr:`~sklearn.ensemble.GradientBoostingRegressor.feature_importances_`).\n\nThis example shows how to obtain partial dependence plots from a\n:class:`~sklearn.ensemble.GradientBoostingRegressor` trained on the California\nhousing dataset. The example is taken from [1]_.\n\nThe plot shows four one-way and one two-way partial dependence plots.\nThe target variables for the one-way PDP are:\nmedian income (`MedInc`), avg. occupants per household (`AvgOccup`),\nmedian house age (`HouseAge`), and avg. rooms per household (`AveRooms`).\n\nWe can clearly see that the median house price shows a linear relationship\nwith the median income (top left) and that the house price drops when the\navg. occupants per household increases (top middle).\nThe top right plot shows that the house age in a district does not have\na strong influence on the (median) house price; so does the average rooms\nper household.\nThe tick marks on the x-axis represent the deciles of the feature values\nin the training data.\n\nPartial dependence plots with two target features enable us to visualize\ninteractions among them. The two-way partial dependence plot shows the\ndependence of median house price on joint values of house age and avg.\noccupants per household. We can clearly see an interaction between the\ntwo features:\nFor an avg. occupancy greater than two, the house price is nearly independent\nof the house age, whereas for values less than two there is a strong dependence\non age.\n\n.. [1] T. Hastie, R. Tibshirani and J. Friedman,\n \"Elements of Statistical Learning Ed. 2\", Springer, 2009.\n\n.. [2] For classification you can think of it as the regression score before\n the link function.\n\n"
18+
"\n# Partial Dependence Plots\n\n\nPartial dependence plots show the dependence between the target function [2]_\nand a set of 'target' features, marginalizing over the\nvalues of all other features (the complement features). Due to the limits\nof human perception the size of the target feature set must be small (usually,\none or two) thus the target features are usually chosen among the most\nimportant features.\n\nThis example shows how to obtain partial dependence plots from a\n:class:`~sklearn.neural_network.MLPRegressor` and a\n:class:`~sklearn.ensemble.GradientBoostingRegressor` trained on the\nCalifornia housing dataset. The example is taken from [1]_.\n\nThe plots show four 1-way and two 1-way partial dependence plots (ommitted for\n:class:`~sklearn.neural_network.MLPRegressor` due to computation time).\nThe target variables for the one-way PDP are: median income (`MedInc`),\naverage occupants per household (`AvgOccup`), median house age (`HouseAge`),\nand average rooms per household (`AveRooms`).\n\nWe can clearly see that the median house price shows a linear relationship\nwith the median income (top left) and that the house price drops when the\naverage occupants per household increases (top middle).\nThe top right plot shows that the house age in a district does not have\na strong influence on the (median) house price; so does the average rooms\nper household.\nThe tick marks on the x-axis represent the deciles of the feature values\nin the training data.\n\nWe also observe that :class:`~sklearn.neural_network.MLPRegressor` has much\nsmoother predictions than\n:class:`~sklearn.ensemble.GradientBoostingRegressor`. For the plots to be\ncomparable, it is necessary to subtract the average value of the target\n``y``: The 'recursion' method, used by default for\n:class:`~sklearn.ensemble.GradientBoostingRegressor`, does not account for\nthe initial predictor (in our case the average target). Setting the target\naverage to 0 avoids this bias.\n\nPartial dependence plots with two target features enable us to visualize\ninteractions among them. The two-way partial dependence plot shows the\ndependence of median house price on joint values of house age and average\noccupants per household. We can clearly see an interaction between the\ntwo features: for an average occupancy greater than two, the house price is\nnearly independent of the house age, whereas for values less than two there\nis a strong dependence on age.\n\nOn a third figure, we have plotted the same partial dependence plot, this time\nin 3 dimensions.\n\n.. [1] T. Hastie, R. Tibshirani and J. Friedman,\n \"Elements of Statistical Learning Ed. 2\", Springer, 2009.\n\n.. [2] For classification you can think of it as the regression score before\n the link function.\n\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom mpl_toolkits.mplot3d import Axes3D\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import GradientBoostingRegressor\nfrom sklearn.ensemble.partial_dependence import plot_partial_dependence\nfrom sklearn.ensemble.partial_dependence import partial_dependence\nfrom sklearn.datasets.california_housing import fetch_california_housing\n\n\ndef main():\n cal_housing = fetch_california_housing()\n\n # split 80/20 train-test\n X_train, X_test, y_train, y_test = train_test_split(cal_housing.data,\n cal_housing.target,\n test_size=0.2,\n random_state=1)\n names = cal_housing.feature_names\n\n print(\"Training GBRT...\")\n clf = GradientBoostingRegressor(n_estimators=100, max_depth=4,\n learning_rate=0.1, loss='huber',\n random_state=1)\n clf.fit(X_train, y_train)\n print(\" done.\")\n\n print('Convenience plot with ``partial_dependence_plots``')\n\n features = [0, 5, 1, 2, (5, 1)]\n fig, axs = plot_partial_dependence(clf, X_train, features,\n feature_names=names,\n n_jobs=3, grid_resolution=50)\n fig.suptitle('Partial dependence of house value on nonlocation features\\n'\n 'for the California housing dataset')\n plt.subplots_adjust(top=0.9) # tight_layout causes overlap with suptitle\n\n print('Custom 3d plot via ``partial_dependence``')\n fig = plt.figure()\n\n target_feature = (1, 5)\n pdp, axes = partial_dependence(clf, target_feature,\n X=X_train, grid_resolution=50)\n XX, YY = np.meshgrid(axes[0], axes[1])\n Z = pdp[0].reshape(list(map(np.size, axes))).T\n ax = Axes3D(fig)\n surf = ax.plot_surface(XX, YY, Z, rstride=1, cstride=1,\n cmap=plt.cm.BuPu, edgecolor='k')\n ax.set_xlabel(names[target_feature[0]])\n ax.set_ylabel(names[target_feature[1]])\n ax.set_zlabel('Partial dependence')\n # pretty init view\n ax.view_init(elev=22, azim=122)\n plt.colorbar(surf)\n plt.suptitle('Partial dependence of house value on median\\n'\n 'age and average occupancy')\n plt.subplots_adjust(top=0.9)\n\n plt.show()\n\n\n# Needed on Windows because plot_partial_dependence uses multiprocessing\nif __name__ == '__main__':\n main()"
29+
"print(__doc__)\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\nfrom sklearn.inspection import partial_dependence\nfrom sklearn.inspection import plot_partial_dependence\nfrom sklearn.ensemble import GradientBoostingRegressor\nfrom sklearn.neural_network import MLPRegressor\nfrom sklearn.datasets.california_housing import fetch_california_housing\n\n\ndef main():\n cal_housing = fetch_california_housing()\n\n X, y = cal_housing.data, cal_housing.target\n names = cal_housing.feature_names\n\n # Center target to avoid gradient boosting init bias: gradient boosting\n # with the 'recursion' method does not account for the initial estimator\n # (here the average target, by default)\n y -= y.mean()\n\n print(\"Training MLPRegressor...\")\n est = MLPRegressor(activation='logistic')\n est.fit(X, y)\n print('Computing partial dependence plots...')\n # We don't compute the 2-way PDP (5, 1) here, because it is a lot slower\n # with the brute method.\n features = [0, 5, 1, 2]\n plot_partial_dependence(est, X, features, feature_names=names,\n n_jobs=3, grid_resolution=50)\n fig = plt.gcf()\n fig.suptitle('Partial dependence of house value on non-___location features\\n'\n 'for the California housing dataset, with MLPRegressor')\n plt.subplots_adjust(top=0.9) # tight_layout causes overlap with suptitle\n\n print(\"Training GradientBoostingRegressor...\")\n est = GradientBoostingRegressor(n_estimators=100, max_depth=4,\n learning_rate=0.1, loss='huber',\n random_state=1)\n est.fit(X, y)\n print('Computing partial dependence plots...')\n features = [0, 5, 1, 2, (5, 1)]\n plot_partial_dependence(est, X, features, feature_names=names,\n n_jobs=3, grid_resolution=50)\n fig = plt.gcf()\n fig.suptitle('Partial dependence of house value on non-___location features\\n'\n 'for the California housing dataset, with Gradient Boosting')\n plt.subplots_adjust(top=0.9)\n\n print('Custom 3d plot via ``partial_dependence``')\n fig = plt.figure()\n\n target_feature = (1, 5)\n pdp, axes = partial_dependence(est, X, target_feature,\n grid_resolution=50)\n XX, YY = np.meshgrid(axes[0], axes[1])\n Z = pdp[0].T\n ax = Axes3D(fig)\n surf = ax.plot_surface(XX, YY, Z, rstride=1, cstride=1,\n cmap=plt.cm.BuPu, edgecolor='k')\n ax.set_xlabel(names[target_feature[0]])\n ax.set_ylabel(names[target_feature[1]])\n ax.set_zlabel('Partial dependence')\n # pretty init view\n ax.view_init(elev=22, azim=122)\n plt.colorbar(surf)\n plt.suptitle('Partial dependence of house value on median\\n'\n 'age and average occupancy, with Gradient Boosting')\n plt.subplots_adjust(top=0.9)\n\n plt.show()\n\n\n# Needed on Windows because plot_partial_dependence uses multiprocessing\nif __name__ == '__main__':\n main()"
3030
]
3131
}
3232
],

dev/_downloads/plot_partial_dependence.py

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,47 @@
88
values of all other features (the complement features). Due to the limits
99
of human perception the size of the target feature set must be small (usually,
1010
one or two) thus the target features are usually chosen among the most
11-
important features
12-
(see :attr:`~sklearn.ensemble.GradientBoostingRegressor.feature_importances_`).
11+
important features.
1312
1413
This example shows how to obtain partial dependence plots from a
15-
:class:`~sklearn.ensemble.GradientBoostingRegressor` trained on the California
16-
housing dataset. The example is taken from [1]_.
14+
:class:`~sklearn.neural_network.MLPRegressor` and a
15+
:class:`~sklearn.ensemble.GradientBoostingRegressor` trained on the
16+
California housing dataset. The example is taken from [1]_.
1717
18-
The plot shows four one-way and one two-way partial dependence plots.
19-
The target variables for the one-way PDP are:
20-
median income (`MedInc`), avg. occupants per household (`AvgOccup`),
21-
median house age (`HouseAge`), and avg. rooms per household (`AveRooms`).
18+
The plots show four 1-way and two 1-way partial dependence plots (ommitted for
19+
:class:`~sklearn.neural_network.MLPRegressor` due to computation time).
20+
The target variables for the one-way PDP are: median income (`MedInc`),
21+
average occupants per household (`AvgOccup`), median house age (`HouseAge`),
22+
and average rooms per household (`AveRooms`).
2223
2324
We can clearly see that the median house price shows a linear relationship
2425
with the median income (top left) and that the house price drops when the
25-
avg. occupants per household increases (top middle).
26+
average occupants per household increases (top middle).
2627
The top right plot shows that the house age in a district does not have
2728
a strong influence on the (median) house price; so does the average rooms
2829
per household.
2930
The tick marks on the x-axis represent the deciles of the feature values
3031
in the training data.
3132
33+
We also observe that :class:`~sklearn.neural_network.MLPRegressor` has much
34+
smoother predictions than
35+
:class:`~sklearn.ensemble.GradientBoostingRegressor`. For the plots to be
36+
comparable, it is necessary to subtract the average value of the target
37+
``y``: The 'recursion' method, used by default for
38+
:class:`~sklearn.ensemble.GradientBoostingRegressor`, does not account for
39+
the initial predictor (in our case the average target). Setting the target
40+
average to 0 avoids this bias.
41+
3242
Partial dependence plots with two target features enable us to visualize
3343
interactions among them. The two-way partial dependence plot shows the
34-
dependence of median house price on joint values of house age and avg.
44+
dependence of median house price on joint values of house age and average
3545
occupants per household. We can clearly see an interaction between the
36-
two features:
37-
For an avg. occupancy greater than two, the house price is nearly independent
38-
of the house age, whereas for values less than two there is a strong dependence
39-
on age.
46+
two features: for an average occupancy greater than two, the house price is
47+
nearly independent of the house age, whereas for values less than two there
48+
is a strong dependence on age.
49+
50+
On a third figure, we have plotted the same partial dependence plot, this time
51+
in 3 dimensions.
4052
4153
.. [1] T. Hastie, R. Tibshirani and J. Friedman,
4254
"Elements of Statistical Learning Ed. 2", Springer, 2009.
@@ -48,51 +60,62 @@
4860

4961
import numpy as np
5062
import matplotlib.pyplot as plt
51-
5263
from mpl_toolkits.mplot3d import Axes3D
5364

54-
from sklearn.model_selection import train_test_split
65+
from sklearn.inspection import partial_dependence
66+
from sklearn.inspection import plot_partial_dependence
5567
from sklearn.ensemble import GradientBoostingRegressor
56-
from sklearn.ensemble.partial_dependence import plot_partial_dependence
57-
from sklearn.ensemble.partial_dependence import partial_dependence
68+
from sklearn.neural_network import MLPRegressor
5869
from sklearn.datasets.california_housing import fetch_california_housing
5970

6071

6172
def main():
6273
cal_housing = fetch_california_housing()
6374

64-
# split 80/20 train-test
65-
X_train, X_test, y_train, y_test = train_test_split(cal_housing.data,
66-
cal_housing.target,
67-
test_size=0.2,
68-
random_state=1)
75+
X, y = cal_housing.data, cal_housing.target
6976
names = cal_housing.feature_names
7077

71-
print("Training GBRT...")
72-
clf = GradientBoostingRegressor(n_estimators=100, max_depth=4,
78+
# Center target to avoid gradient boosting init bias: gradient boosting
79+
# with the 'recursion' method does not account for the initial estimator
80+
# (here the average target, by default)
81+
y -= y.mean()
82+
83+
print("Training MLPRegressor...")
84+
est = MLPRegressor(activation='logistic')
85+
est.fit(X, y)
86+
print('Computing partial dependence plots...')
87+
# We don't compute the 2-way PDP (5, 1) here, because it is a lot slower
88+
# with the brute method.
89+
features = [0, 5, 1, 2]
90+
plot_partial_dependence(est, X, features, feature_names=names,
91+
n_jobs=3, grid_resolution=50)
92+
fig = plt.gcf()
93+
fig.suptitle('Partial dependence of house value on non-___location features\n'
94+
'for the California housing dataset, with MLPRegressor')
95+
plt.subplots_adjust(top=0.9) # tight_layout causes overlap with suptitle
96+
97+
print("Training GradientBoostingRegressor...")
98+
est = GradientBoostingRegressor(n_estimators=100, max_depth=4,
7399
learning_rate=0.1, loss='huber',
74100
random_state=1)
75-
clf.fit(X_train, y_train)
76-
print(" done.")
77-
78-
print('Convenience plot with ``partial_dependence_plots``')
79-
101+
est.fit(X, y)
102+
print('Computing partial dependence plots...')
80103
features = [0, 5, 1, 2, (5, 1)]
81-
fig, axs = plot_partial_dependence(clf, X_train, features,
82-
feature_names=names,
83-
n_jobs=3, grid_resolution=50)
84-
fig.suptitle('Partial dependence of house value on nonlocation features\n'
85-
'for the California housing dataset')
86-
plt.subplots_adjust(top=0.9) # tight_layout causes overlap with suptitle
104+
plot_partial_dependence(est, X, features, feature_names=names,
105+
n_jobs=3, grid_resolution=50)
106+
fig = plt.gcf()
107+
fig.suptitle('Partial dependence of house value on non-___location features\n'
108+
'for the California housing dataset, with Gradient Boosting')
109+
plt.subplots_adjust(top=0.9)
87110

88111
print('Custom 3d plot via ``partial_dependence``')
89112
fig = plt.figure()
90113

91114
target_feature = (1, 5)
92-
pdp, axes = partial_dependence(clf, target_feature,
93-
X=X_train, grid_resolution=50)
115+
pdp, axes = partial_dependence(est, X, target_feature,
116+
grid_resolution=50)
94117
XX, YY = np.meshgrid(axes[0], axes[1])
95-
Z = pdp[0].reshape(list(map(np.size, axes))).T
118+
Z = pdp[0].T
96119
ax = Axes3D(fig)
97120
surf = ax.plot_surface(XX, YY, Z, rstride=1, cstride=1,
98121
cmap=plt.cm.BuPu, edgecolor='k')
@@ -103,7 +126,7 @@ def main():
103126
ax.view_init(elev=22, azim=122)
104127
plt.colorbar(surf)
105128
plt.suptitle('Partial dependence of house value on median\n'
106-
'age and average occupancy')
129+
'age and average occupancy, with Gradient Boosting')
107130
plt.subplots_adjust(top=0.9)
108131

109132
plt.show()

dev/_downloads/scikit-learn-docs.pdf

70 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes
-42 Bytes
-42 Bytes
-189 Bytes

0 commit comments

Comments
 (0)