Skip to content

Commit 8f3e3b9

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 7ea78614829a144f2f82e94fca515722a0fc2ef3
1 parent ecce38c commit 8f3e3b9

File tree

1,208 files changed

+3797
-3772
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,208 files changed

+3797
-3772
lines changed
Binary file not shown.

dev/_downloads/51a82a09a4aa0f703f69fb5d4f15104f/plot_partial_dependence_visualization_api.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\nimport matplotlib.pyplot as plt\nfrom sklearn.datasets import load_boston\nfrom sklearn.neural_network import MLPRegressor\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.inspection import plot_partial_dependence"
29+
"print(__doc__)\n\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom sklearn.datasets import load_boston\nfrom sklearn.neural_network import MLPRegressor\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.inspection import plot_partial_dependence"
3030
]
3131
},
3232
{
@@ -44,7 +44,7 @@
4444
},
4545
"outputs": [],
4646
"source": [
47-
"boston = load_boston()\nX, y = boston.data, boston.target\nfeature_names = boston.feature_names\n\ntree = DecisionTreeRegressor()\nmlp = make_pipeline(StandardScaler(),\n MLPRegressor(hidden_layer_sizes=(100, 100),\n tol=1e-2, max_iter=500, random_state=0))\ntree.fit(X, y)\nmlp.fit(X, y)"
47+
"boston = load_boston()\nX = pd.DataFrame(boston.data, columns=boston.feature_names)\ny = boston.target\n\ntree = DecisionTreeRegressor()\nmlp = make_pipeline(StandardScaler(),\n MLPRegressor(hidden_layer_sizes=(100, 100),\n tol=1e-2, max_iter=500, random_state=0))\ntree.fit(X, y)\nmlp.fit(X, y)"
4848
]
4949
},
5050
{
@@ -62,7 +62,7 @@
6262
},
6363
"outputs": [],
6464
"source": [
65-
"fig, ax = plt.subplots(figsize=(12, 6))\nax.set_title(\"Decision Tree\")\ntree_disp = plot_partial_dependence(tree, X, [\"LSTAT\", \"RM\"],\n feature_names=feature_names, ax=ax)"
65+
"fig, ax = plt.subplots(figsize=(12, 6))\nax.set_title(\"Decision Tree\")\ntree_disp = plot_partial_dependence(tree, X, [\"LSTAT\", \"RM\"],\n feature_names=X.columns.tolist(), ax=ax)"
6666
]
6767
},
6868
{
@@ -80,7 +80,7 @@
8080
},
8181
"outputs": [],
8282
"source": [
83-
"fig, ax = plt.subplots(figsize=(12, 6))\nax.set_title(\"Multi-layer Perceptron\")\nmlp_disp = plot_partial_dependence(mlp, X, [\"LSTAT\", \"RM\"],\n feature_names=feature_names, ax=ax,\n line_kw={\"c\": \"red\"})"
83+
"fig, ax = plt.subplots(figsize=(12, 6))\nax.set_title(\"Multi-layer Perceptron\")\nmlp_disp = plot_partial_dependence(mlp, X, [\"LSTAT\", \"RM\"],\n feature_names=X.columns.tolist(), ax=ax,\n line_kw={\"c\": \"red\"})"
8484
]
8585
},
8686
{
@@ -152,7 +152,7 @@
152152
},
153153
"outputs": [],
154154
"source": [
155-
"tree_disp = plot_partial_dependence(tree, X, [\"LSTAT\"],\n feature_names=feature_names)\nmlp_disp = plot_partial_dependence(mlp, X, [\"LSTAT\"],\n feature_names=feature_names,\n ax=tree_disp.axes_, line_kw={\"c\": \"red\"})"
155+
"tree_disp = plot_partial_dependence(tree, X, [\"LSTAT\"],\n feature_names=X.columns.tolist())\nmlp_disp = plot_partial_dependence(mlp, X, [\"LSTAT\"],\n feature_names=X.columns.tolist(),\n ax=tree_disp.axes_, line_kw={\"c\": \"red\"})"
156156
]
157157
}
158158
],

dev/_downloads/5a693c97e821586539ab9d250762742c/plot_partial_dependence.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"print(__doc__)\n\nfrom time import time\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import QuantileTransformer\nfrom sklearn.pipeline import make_pipeline\n\nfrom sklearn.inspection import partial_dependence\nfrom sklearn.inspection import plot_partial_dependence\nfrom sklearn.experimental import enable_hist_gradient_boosting # noqa\nfrom sklearn.ensemble import HistGradientBoostingRegressor\nfrom sklearn.neural_network import MLPRegressor\nfrom sklearn.datasets import fetch_california_housing"
29+
"print(__doc__)\n\nfrom time import time\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import QuantileTransformer\nfrom sklearn.pipeline import make_pipeline\n\nfrom sklearn.inspection import partial_dependence\nfrom sklearn.inspection import plot_partial_dependence\nfrom sklearn.experimental import enable_hist_gradient_boosting # noqa\nfrom sklearn.ensemble import HistGradientBoostingRegressor\nfrom sklearn.neural_network import MLPRegressor\nfrom sklearn.datasets import fetch_california_housing"
3030
]
3131
},
3232
{
@@ -44,7 +44,7 @@
4444
},
4545
"outputs": [],
4646
"source": [
47-
"cal_housing = fetch_california_housing()\nnames = cal_housing.feature_names\nX, y = cal_housing.data, cal_housing.target\n\ny -= y.mean()\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1,\n random_state=0)"
47+
"cal_housing = fetch_california_housing()\nX = pd.DataFrame(cal_housing.data, columns=cal_housing.feature_names)\ny = cal_housing.target\n\ny -= y.mean()\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1,\n random_state=0)"
4848
]
4949
},
5050
{
@@ -80,7 +80,7 @@
8080
},
8181
"outputs": [],
8282
"source": [
83-
"print('Computing partial dependence plots...')\ntic = time()\n# We don't compute the 2-way PDP (5, 1) here, because it is a lot slower\n# with the brute method.\nfeatures = [0, 5, 1, 2]\nplot_partial_dependence(est, X_train, features, feature_names=names,\n n_jobs=3, grid_resolution=20)\nprint(\"done in {:.3f}s\".format(time() - tic))\nfig = plt.gcf()\nfig.suptitle('Partial dependence of house value on non-___location features\\n'\n 'for the California housing dataset, with MLPRegressor')\nfig.subplots_adjust(hspace=0.3)"
83+
"print('Computing partial dependence plots...')\ntic = time()\n# We don't compute the 2-way PDP (5, 1) here, because it is a lot slower\n# with the brute method.\nfeatures = ['MedInc', 'AveOccup', 'HouseAge', 'AveRooms']\nplot_partial_dependence(est, X_train, features,\n feature_names=X_train.columns.tolist(),\n n_jobs=3, grid_resolution=20)\nprint(\"done in {:.3f}s\".format(time() - tic))\nfig = plt.gcf()\nfig.suptitle('Partial dependence of house value on non-___location features\\n'\n 'for the California housing dataset, with MLPRegressor')\nfig.subplots_adjust(hspace=0.3)"
8484
]
8585
},
8686
{
@@ -116,7 +116,7 @@
116116
},
117117
"outputs": [],
118118
"source": [
119-
"print('Computing partial dependence plots...')\ntic = time()\nfeatures = [0, 5, 1, 2, (5, 1)]\nplot_partial_dependence(est, X_train, features, feature_names=names,\n n_jobs=3, grid_resolution=20)\nprint(\"done in {:.3f}s\".format(time() - tic))\nfig = plt.gcf()\nfig.suptitle('Partial dependence of house value on non-___location features\\n'\n 'for the California housing dataset, with Gradient Boosting')\nfig.subplots_adjust(wspace=0.4, hspace=0.3)"
119+
"print('Computing partial dependence plots...')\ntic = time()\nfeatures = ['MedInc', 'AveOccup', 'HouseAge', 'AveRooms',\n ('AveOccup', 'HouseAge')]\nplot_partial_dependence(est, X_train, features,\n feature_names=X_train.columns.tolist(),\n n_jobs=3, grid_resolution=20)\nprint(\"done in {:.3f}s\".format(time() - tic))\nfig = plt.gcf()\nfig.suptitle('Partial dependence of house value on non-___location features\\n'\n 'for the California housing dataset, with Gradient Boosting')\nfig.subplots_adjust(wspace=0.4, hspace=0.3)"
120120
]
121121
},
122122
{
@@ -141,7 +141,7 @@
141141
},
142142
"outputs": [],
143143
"source": [
144-
"fig = plt.figure()\n\ntarget_feature = (1, 5)\npdp, axes = partial_dependence(est, X_train, target_feature,\n grid_resolution=20)\nXX, YY = np.meshgrid(axes[0], axes[1])\nZ = pdp[0].T\nax = Axes3D(fig)\nsurf = ax.plot_surface(XX, YY, Z, rstride=1, cstride=1,\n cmap=plt.cm.BuPu, edgecolor='k')\nax.set_xlabel(names[target_feature[0]])\nax.set_ylabel(names[target_feature[1]])\nax.set_zlabel('Partial dependence')\n# pretty init view\nax.view_init(elev=22, azim=122)\nplt.colorbar(surf)\nplt.suptitle('Partial dependence of house value on median\\n'\n 'age and average occupancy, with Gradient Boosting')\nplt.subplots_adjust(top=0.9)\n\nplt.show()"
144+
"fig = plt.figure()\n\nfeatures = ('AveOccup', 'HouseAge')\npdp, axes = partial_dependence(est, X_train, features=features,\n grid_resolution=20)\nXX, YY = np.meshgrid(axes[0], axes[1])\nZ = pdp[0].T\nax = Axes3D(fig)\nsurf = ax.plot_surface(XX, YY, Z, rstride=1, cstride=1,\n cmap=plt.cm.BuPu, edgecolor='k')\nax.set_xlabel(features[0])\nax.set_ylabel(features[1])\nax.set_zlabel('Partial dependence')\n# pretty init view\nax.view_init(elev=22, azim=122)\nplt.colorbar(surf)\nplt.suptitle('Partial dependence of house value on median\\n'\n 'age and average occupancy, with Gradient Boosting')\nplt.subplots_adjust(top=0.9)\n\nplt.show()"
145145
]
146146
}
147147
],

dev/_downloads/781bb5a2dc85df6b75ee78d2eb118b0b/plot_partial_dependence_visualization_api.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
print(__doc__)
1717

18+
import pandas as pd
1819
import matplotlib.pyplot as plt
1920
from sklearn.datasets import load_boston
2021
from sklearn.neural_network import MLPRegressor
@@ -32,8 +33,8 @@
3233
# housing price dataset.
3334

3435
boston = load_boston()
35-
X, y = boston.data, boston.target
36-
feature_names = boston.feature_names
36+
X = pd.DataFrame(boston.data, columns=boston.feature_names)
37+
y = boston.target
3738

3839
tree = DecisionTreeRegressor()
3940
mlp = make_pipeline(StandardScaler(),
@@ -55,7 +56,7 @@
5556
fig, ax = plt.subplots(figsize=(12, 6))
5657
ax.set_title("Decision Tree")
5758
tree_disp = plot_partial_dependence(tree, X, ["LSTAT", "RM"],
58-
feature_names=feature_names, ax=ax)
59+
feature_names=X.columns.tolist(), ax=ax)
5960

6061
##############################################################################
6162
# The partial depdendence curves can be plotted for the multi-layer perceptron.
@@ -65,7 +66,7 @@
6566
fig, ax = plt.subplots(figsize=(12, 6))
6667
ax.set_title("Multi-layer Perceptron")
6768
mlp_disp = plot_partial_dependence(mlp, X, ["LSTAT", "RM"],
68-
feature_names=feature_names, ax=ax,
69+
feature_names=X.columns.tolist(), ax=ax,
6970
line_kw={"c": "red"})
7071

7172
##############################################################################
@@ -134,7 +135,7 @@
134135
# the same axes. In this case, `tree_disp.axes_` is passed into the second
135136
# plot function.
136137
tree_disp = plot_partial_dependence(tree, X, ["LSTAT"],
137-
feature_names=feature_names)
138+
feature_names=X.columns.tolist())
138139
mlp_disp = plot_partial_dependence(mlp, X, ["LSTAT"],
139-
feature_names=feature_names,
140+
feature_names=X.columns.tolist(),
140141
ax=tree_disp.axes_, line_kw={"c": "red"})
Binary file not shown.

dev/_downloads/fa25d310c75e4ff65e62ab2cd8fdcef4/plot_partial_dependence.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from time import time
3232
import numpy as np
33+
import pandas as pd
3334
import matplotlib.pyplot as plt
3435
from mpl_toolkits.mplot3d import Axes3D
3536

@@ -54,8 +55,8 @@
5455
# (here the average target, by default)
5556

5657
cal_housing = fetch_california_housing()
57-
names = cal_housing.feature_names
58-
X, y = cal_housing.data, cal_housing.target
58+
X = pd.DataFrame(cal_housing.data, columns=cal_housing.feature_names)
59+
y = cal_housing.target
5960

6061
y -= y.mean()
6162

@@ -104,8 +105,9 @@
104105
tic = time()
105106
# We don't compute the 2-way PDP (5, 1) here, because it is a lot slower
106107
# with the brute method.
107-
features = [0, 5, 1, 2]
108-
plot_partial_dependence(est, X_train, features, feature_names=names,
108+
features = ['MedInc', 'AveOccup', 'HouseAge', 'AveRooms']
109+
plot_partial_dependence(est, X_train, features,
110+
feature_names=X_train.columns.tolist(),
109111
n_jobs=3, grid_resolution=20)
110112
print("done in {:.3f}s".format(time() - tic))
111113
fig = plt.gcf()
@@ -143,8 +145,10 @@
143145

144146
print('Computing partial dependence plots...')
145147
tic = time()
146-
features = [0, 5, 1, 2, (5, 1)]
147-
plot_partial_dependence(est, X_train, features, feature_names=names,
148+
features = ['MedInc', 'AveOccup', 'HouseAge', 'AveRooms',
149+
('AveOccup', 'HouseAge')]
150+
plot_partial_dependence(est, X_train, features,
151+
feature_names=X_train.columns.tolist(),
148152
n_jobs=3, grid_resolution=20)
149153
print("done in {:.3f}s".format(time() - tic))
150154
fig = plt.gcf()
@@ -192,16 +196,16 @@
192196

193197
fig = plt.figure()
194198

195-
target_feature = (1, 5)
196-
pdp, axes = partial_dependence(est, X_train, target_feature,
199+
features = ('AveOccup', 'HouseAge')
200+
pdp, axes = partial_dependence(est, X_train, features=features,
197201
grid_resolution=20)
198202
XX, YY = np.meshgrid(axes[0], axes[1])
199203
Z = pdp[0].T
200204
ax = Axes3D(fig)
201205
surf = ax.plot_surface(XX, YY, Z, rstride=1, cstride=1,
202206
cmap=plt.cm.BuPu, edgecolor='k')
203-
ax.set_xlabel(names[target_feature[0]])
204-
ax.set_ylabel(names[target_feature[1]])
207+
ax.set_xlabel(features[0])
208+
ax.set_ylabel(features[1])
205209
ax.set_zlabel('Partial dependence')
206210
# pretty init view
207211
ax.view_init(elev=22, azim=122)

dev/_downloads/scikit-learn-docs.pdf

-27.9 KB
Binary file not shown.

dev/_images/iris.png

0 Bytes

0 commit comments

Comments
 (0)