Skip to content

Commit 753c585

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 391baef660b08db50fc2545dd5ad381eeb6bf905
1 parent 063cf05 commit 753c585

File tree

1,224 files changed

+4580
-4440
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,224 files changed

+4580
-4440
lines changed
Binary file not shown.

dev/_downloads/113d936063a64e05f36c8cd5e870300a/plot_ols_3d.ipynb

Lines changed: 56 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# Sparsity Example: Fitting only features 1 and 2\n\nFeatures 1 and 2 of the diabetes-dataset are fitted and\nplotted below. It illustrates that although feature 2\nhas a strong coefficient on the full model, it does not\ngive us much regarding `y` when compared to just feature 1\n"
18+
"\n# Sparsity Example: Fitting only features 1 and 2\n\nFeatures 1 and 2 of the diabetes-dataset are fitted and\nplotted below. It illustrates that although feature 2\nhas a strong coefficient on the full model, it does not\ngive us much regarding `y` when compared to just feature 1.\n"
1919
]
2020
},
2121
{
@@ -26,7 +26,61 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom mpl_toolkits.mplot3d import Axes3D\n\nfrom sklearn import datasets, linear_model\n\nX, y = datasets.load_diabetes(return_X_y=True)\nindices = (0, 1)\n\nX_train = X[:-20, indices]\nX_test = X[-20:, indices]\ny_train = y[:-20]\ny_test = y[-20:]\n\nols = linear_model.LinearRegression()\nols.fit(X_train, y_train)\n\n\n# #############################################################################\n# Plot the figure\ndef plot_figs(fig_num, elev, azim, X_train, clf):\n fig = plt.figure(fig_num, figsize=(4, 3))\n plt.clf()\n ax = Axes3D(fig, elev=elev, azim=azim)\n\n ax.scatter(X_train[:, 0], X_train[:, 1], y_train, c=\"k\", marker=\"+\")\n ax.plot_surface(\n np.array([[-0.1, -0.1], [0.15, 0.15]]),\n np.array([[-0.1, 0.15], [-0.1, 0.15]]),\n clf.predict(\n np.array([[-0.1, -0.1, 0.15, 0.15], [-0.1, 0.15, -0.1, 0.15]]).T\n ).reshape((2, 2)),\n alpha=0.5,\n )\n ax.set_xlabel(\"X_1\")\n ax.set_ylabel(\"X_2\")\n ax.set_zlabel(\"Y\")\n ax.w_xaxis.set_ticklabels([])\n ax.w_yaxis.set_ticklabels([])\n ax.w_zaxis.set_ticklabels([])\n\n\n# Generate the three different figures from different views\nelev = 43.5\nazim = -110\nplot_figs(1, elev, azim, X_train, ols)\n\nelev = -0.5\nazim = 0\nplot_figs(2, elev, azim, X_train, ols)\n\nelev = -0.5\nazim = 90\nplot_figs(3, elev, azim, X_train, ols)\n\nplt.show()"
29+
"# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"First we load the diabetes dataset.\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"from sklearn import datasets\nimport numpy as np\n\nX, y = datasets.load_diabetes(return_X_y=True)\nindices = (0, 1)\n\nX_train = X[:-20, indices]\nX_test = X[-20:, indices]\ny_train = y[:-20]\ny_test = y[-20:]"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"Next we fit a linear regression model.\n\n"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {
61+
"collapsed": false
62+
},
63+
"outputs": [],
64+
"source": [
65+
"from sklearn import linear_model\n\nols = linear_model.LinearRegression()\n_ = ols.fit(X_train, y_train)"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"Finally we plot the figure from three different views.\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"import matplotlib.pyplot as plt\n\n\ndef plot_figs(fig_num, elev, azim, X_train, clf):\n fig = plt.figure(fig_num, figsize=(4, 3))\n plt.clf()\n ax = fig.add_subplot(111, projection=\"3d\", elev=elev, azim=azim)\n\n ax.scatter(X_train[:, 0], X_train[:, 1], y_train, c=\"k\", marker=\"+\")\n ax.plot_surface(\n np.array([[-0.1, -0.1], [0.15, 0.15]]),\n np.array([[-0.1, 0.15], [-0.1, 0.15]]),\n clf.predict(\n np.array([[-0.1, -0.1, 0.15, 0.15], [-0.1, 0.15, -0.1, 0.15]]).T\n ).reshape((2, 2)),\n alpha=0.5,\n )\n ax.set_xlabel(\"X_1\")\n ax.set_ylabel(\"X_2\")\n ax.set_zlabel(\"Y\")\n ax.w_xaxis.set_ticklabels([])\n ax.w_yaxis.set_ticklabels([])\n ax.w_zaxis.set_ticklabels([])\n\n\n# Generate the three different figures from different views\nelev = 43.5\nazim = -110\nplot_figs(1, elev, azim, X_train, ols)\n\nelev = -0.5\nazim = 0\nplot_figs(2, elev, azim, X_train, ols)\n\nelev = -0.5\nazim = 90\nplot_figs(3, elev, azim, X_train, ols)\n\nplt.show()"
3084
]
3185
}
3286
],

dev/_downloads/2a401e4f9bbae968abdf35a831408f10/plot_ols_3d.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
Features 1 and 2 of the diabetes-dataset are fitted and
88
plotted below. It illustrates that although feature 2
99
has a strong coefficient on the full model, it does not
10-
give us much regarding `y` when compared to just feature 1
11-
10+
give us much regarding `y` when compared to just feature 1.
1211
"""
1312

1413
# Code source: Gaël Varoquaux
1514
# Modified for documentation by Jaques Grobler
1615
# License: BSD 3 clause
1716

18-
import matplotlib.pyplot as plt
19-
import numpy as np
20-
from mpl_toolkits.mplot3d import Axes3D
17+
# %%
18+
# First we load the diabetes dataset.
2119

22-
from sklearn import datasets, linear_model
20+
from sklearn import datasets
21+
import numpy as np
2322

2423
X, y = datasets.load_diabetes(return_X_y=True)
2524
indices = (0, 1)
@@ -29,16 +28,25 @@
2928
y_train = y[:-20]
3029
y_test = y[-20:]
3130

31+
# %%
32+
# Next we fit a linear regression model.
33+
34+
from sklearn import linear_model
35+
3236
ols = linear_model.LinearRegression()
33-
ols.fit(X_train, y_train)
37+
_ = ols.fit(X_train, y_train)
38+
39+
40+
# %%
41+
# Finally we plot the figure from three different views.
42+
43+
import matplotlib.pyplot as plt
3444

3545

36-
# #############################################################################
37-
# Plot the figure
3846
def plot_figs(fig_num, elev, azim, X_train, clf):
3947
fig = plt.figure(fig_num, figsize=(4, 3))
4048
plt.clf()
41-
ax = Axes3D(fig, elev=elev, azim=azim)
49+
ax = fig.add_subplot(111, projection="3d", elev=elev, azim=azim)
4250

4351
ax.scatter(X_train[:, 0], X_train[:, 1], y_train, c="k", marker="+")
4452
ax.plot_surface(
Binary file not shown.

dev/_downloads/scikit-learn-docs.zip

-31 KB
Binary file not shown.
-212 Bytes
-204 Bytes
74 Bytes
132 Bytes
-62 Bytes

0 commit comments

Comments
 (0)