Skip to content

Commit a7b6c0a

Browse files
committed
Pushing the docs to dev/ for branch: main, commit fbc56edab96c52ecefa9a67cb7d925b500e72207
1 parent de7c9ca commit a7b6c0a

File tree

1,235 files changed

+4627
-4502
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,235 files changed

+4627
-4502
lines changed
Binary file not shown.

dev/_downloads/6304a55e6fa4d75c8e8d11b4ea9a8679/plot_pca_3d.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
# Kevin Hughes
1616
# License: BSD 3 clause
1717

18-
from sklearn.decomposition import PCA
18+
# %%
19+
# Create the data
20+
# ---------------
1921

2022
import numpy as np
21-
import matplotlib.pyplot as plt
22-
from scipy import stats
2323

24-
25-
# #############################################################################
26-
# Create the data
24+
from scipy import stats
2725

2826
e = np.exp(1)
2927
np.random.seed(4)
@@ -51,8 +49,18 @@ def pdf(x):
5149
b /= norm
5250

5351

54-
# #############################################################################
52+
# %%
5553
# Plot the figures
54+
# ----------------
55+
56+
from sklearn.decomposition import PCA
57+
58+
import matplotlib.pyplot as plt
59+
60+
# unused but required import for doing 3d projections with matplotlib < 3.2
61+
import mpl_toolkits.mplot3d # noqa: F401
62+
63+
5664
def plot_figs(fig_num, elev, azim):
5765
fig = plt.figure(fig_num, figsize=(4, 3))
5866
plt.clf()
Binary file not shown.

dev/_downloads/720e4861bf00cd09b55ae64187ea58be/plot_pca_3d.ipynb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,43 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Authors: Gael Varoquaux\n# Jaques Grobler\n# Kevin Hughes\n# License: BSD 3 clause\n\nfrom sklearn.decomposition import PCA\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import stats\n\n\n# #############################################################################\n# Create the data\n\ne = np.exp(1)\nnp.random.seed(4)\n\n\ndef pdf(x):\n return 0.5 * (stats.norm(scale=0.25 / e).pdf(x) + stats.norm(scale=4 / e).pdf(x))\n\n\ny = np.random.normal(scale=0.5, size=(30000))\nx = np.random.normal(scale=0.5, size=(30000))\nz = np.random.normal(scale=0.1, size=len(x))\n\ndensity = pdf(x) * pdf(y)\npdf_z = pdf(5 * z)\n\ndensity *= pdf_z\n\na = x + y\nb = 2 * y\nc = a - b + z\n\nnorm = np.sqrt(a.var() + b.var())\na /= norm\nb /= norm\n\n\n# #############################################################################\n# Plot the figures\ndef plot_figs(fig_num, elev, azim):\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 ax.set_position([0, 0, 0.95, 1])\n\n ax.scatter(a[::10], b[::10], c[::10], c=density[::10], marker=\"+\", alpha=0.4)\n Y = np.c_[a, b, c]\n\n # Using SciPy's SVD, this would be:\n # _, pca_score, Vt = scipy.linalg.svd(Y, full_matrices=False)\n\n pca = PCA(n_components=3)\n pca.fit(Y)\n V = pca.components_.T\n\n x_pca_axis, y_pca_axis, z_pca_axis = 3 * V\n x_pca_plane = np.r_[x_pca_axis[:2], -x_pca_axis[1::-1]]\n y_pca_plane = np.r_[y_pca_axis[:2], -y_pca_axis[1::-1]]\n z_pca_plane = np.r_[z_pca_axis[:2], -z_pca_axis[1::-1]]\n x_pca_plane.shape = (2, 2)\n y_pca_plane.shape = (2, 2)\n z_pca_plane.shape = (2, 2)\n ax.plot_surface(x_pca_plane, y_pca_plane, z_pca_plane)\n ax.w_xaxis.set_ticklabels([])\n ax.w_yaxis.set_ticklabels([])\n ax.w_zaxis.set_ticklabels([])\n\n\nelev = -40\nazim = -80\nplot_figs(1, elev, azim)\n\nelev = 30\nazim = 20\nplot_figs(2, elev, azim)\n\nplt.show()"
29+
"# Authors: Gael Varoquaux\n# Jaques Grobler\n# Kevin Hughes\n# License: BSD 3 clause"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"## Create the data\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"import numpy as np\n\nfrom scipy import stats\n\ne = np.exp(1)\nnp.random.seed(4)\n\n\ndef pdf(x):\n return 0.5 * (stats.norm(scale=0.25 / e).pdf(x) + stats.norm(scale=4 / e).pdf(x))\n\n\ny = np.random.normal(scale=0.5, size=(30000))\nx = np.random.normal(scale=0.5, size=(30000))\nz = np.random.normal(scale=0.1, size=len(x))\n\ndensity = pdf(x) * pdf(y)\npdf_z = pdf(5 * z)\n\ndensity *= pdf_z\n\na = x + y\nb = 2 * y\nc = a - b + z\n\nnorm = np.sqrt(a.var() + b.var())\na /= norm\nb /= norm"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"## Plot the figures\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.decomposition import PCA\n\nimport matplotlib.pyplot as plt\n\n# unused but required import for doing 3d projections with matplotlib < 3.2\nimport mpl_toolkits.mplot3d # noqa: F401\n\n\ndef plot_figs(fig_num, elev, azim):\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 ax.set_position([0, 0, 0.95, 1])\n\n ax.scatter(a[::10], b[::10], c[::10], c=density[::10], marker=\"+\", alpha=0.4)\n Y = np.c_[a, b, c]\n\n # Using SciPy's SVD, this would be:\n # _, pca_score, Vt = scipy.linalg.svd(Y, full_matrices=False)\n\n pca = PCA(n_components=3)\n pca.fit(Y)\n V = pca.components_.T\n\n x_pca_axis, y_pca_axis, z_pca_axis = 3 * V\n x_pca_plane = np.r_[x_pca_axis[:2], -x_pca_axis[1::-1]]\n y_pca_plane = np.r_[y_pca_axis[:2], -y_pca_axis[1::-1]]\n z_pca_plane = np.r_[z_pca_axis[:2], -z_pca_axis[1::-1]]\n x_pca_plane.shape = (2, 2)\n y_pca_plane.shape = (2, 2)\n z_pca_plane.shape = (2, 2)\n ax.plot_surface(x_pca_plane, y_pca_plane, z_pca_plane)\n ax.w_xaxis.set_ticklabels([])\n ax.w_yaxis.set_ticklabels([])\n ax.w_zaxis.set_ticklabels([])\n\n\nelev = -40\nazim = -80\nplot_figs(1, elev, azim)\n\nelev = 30\nazim = 20\nplot_figs(2, elev, azim)\n\nplt.show()"
3066
]
3167
}
3268
],

dev/_downloads/scikit-learn-docs.zip

8.17 KB
Binary file not shown.
185 Bytes
-145 Bytes
45 Bytes
76 Bytes
334 Bytes

0 commit comments

Comments
 (0)