Skip to content

Commit 16aedc3

Browse files
committed
Pushing the docs to dev/ for branch: main, commit d37988916405d1b2a59b1c54d409a2205e45f3e4
1 parent 7ce9423 commit 16aedc3

File tree

1,216 files changed

+4305
-4217
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,216 files changed

+4305
-4217
lines changed
Binary file not shown.

dev/_downloads/4ee88a807e060ca374ab95e0d8d819ed/plot_ica_vs_pca.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: Alexandre Gramfort, Gael Varoquaux\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom sklearn.decomposition import PCA, FastICA\n\n# #############################################################################\n# Generate sample data\nrng = np.random.RandomState(42)\nS = rng.standard_t(1.5, size=(20000, 2))\nS[:, 0] *= 2.0\n\n# Mix data\nA = np.array([[1, 1], [0, 2]]) # Mixing matrix\n\nX = np.dot(S, A.T) # Generate observations\n\npca = PCA()\nS_pca_ = pca.fit(X).transform(X)\n\nica = FastICA(random_state=rng)\nS_ica_ = ica.fit(X).transform(X) # Estimate the sources\n\nS_ica_ /= S_ica_.std(axis=0)\n\n\n# #############################################################################\n# Plot results\n\n\ndef plot_samples(S, axis_list=None):\n plt.scatter(\n S[:, 0], S[:, 1], s=2, marker=\"o\", zorder=10, color=\"steelblue\", alpha=0.5\n )\n if axis_list is not None:\n colors = [\"orange\", \"red\"]\n for color, axis in zip(colors, axis_list):\n axis /= axis.std()\n x_axis, y_axis = axis\n # Trick to get legend to work\n plt.plot(0.1 * x_axis, 0.1 * y_axis, linewidth=2, color=color)\n plt.quiver(\n (0, 0),\n (0, 0),\n x_axis,\n y_axis,\n zorder=11,\n width=0.01,\n scale=6,\n color=color,\n )\n\n plt.hlines(0, -3, 3)\n plt.vlines(0, -3, 3)\n plt.xlim(-3, 3)\n plt.ylim(-3, 3)\n plt.xlabel(\"x\")\n plt.ylabel(\"y\")\n\n\nplt.figure()\nplt.subplot(2, 2, 1)\nplot_samples(S / S.std())\nplt.title(\"True Independent Sources\")\n\naxis_list = [pca.components_.T, ica.mixing_]\nplt.subplot(2, 2, 2)\nplot_samples(X / np.std(X), axis_list=axis_list)\nlegend = plt.legend([\"PCA\", \"ICA\"], loc=\"upper right\")\nlegend.set_zorder(100)\n\nplt.title(\"Observations\")\n\nplt.subplot(2, 2, 3)\nplot_samples(S_pca_ / np.std(S_pca_, axis=0))\nplt.title(\"PCA recovered signals\")\n\nplt.subplot(2, 2, 4)\nplot_samples(S_ica_ / np.std(S_ica_))\nplt.title(\"ICA recovered signals\")\n\nplt.subplots_adjust(0.09, 0.04, 0.94, 0.94, 0.26, 0.36)\nplt.show()"
29+
"# Authors: Alexandre Gramfort, Gael Varoquaux\n# License: BSD 3 clause"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"## Generate sample 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 sklearn.decomposition import PCA, FastICA\n\nrng = np.random.RandomState(42)\nS = rng.standard_t(1.5, size=(20000, 2))\nS[:, 0] *= 2.0\n\n# Mix data\nA = np.array([[1, 1], [0, 2]]) # Mixing matrix\n\nX = np.dot(S, A.T) # Generate observations\n\npca = PCA()\nS_pca_ = pca.fit(X).transform(X)\n\nica = FastICA(random_state=rng, whiten=\"arbitrary-variance\")\nS_ica_ = ica.fit(X).transform(X) # Estimate the sources\n\nS_ica_ /= S_ica_.std(axis=0)"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"## Plot results\n\n"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {
61+
"collapsed": false
62+
},
63+
"outputs": [],
64+
"source": [
65+
"import matplotlib.pyplot as plt\n\n\ndef plot_samples(S, axis_list=None):\n plt.scatter(\n S[:, 0], S[:, 1], s=2, marker=\"o\", zorder=10, color=\"steelblue\", alpha=0.5\n )\n if axis_list is not None:\n colors = [\"orange\", \"red\"]\n for color, axis in zip(colors, axis_list):\n axis /= axis.std()\n x_axis, y_axis = axis\n # Trick to get legend to work\n plt.plot(0.1 * x_axis, 0.1 * y_axis, linewidth=2, color=color)\n plt.quiver(\n (0, 0),\n (0, 0),\n x_axis,\n y_axis,\n zorder=11,\n width=0.01,\n scale=6,\n color=color,\n )\n\n plt.hlines(0, -3, 3)\n plt.vlines(0, -3, 3)\n plt.xlim(-3, 3)\n plt.ylim(-3, 3)\n plt.xlabel(\"x\")\n plt.ylabel(\"y\")\n\n\nplt.figure()\nplt.subplot(2, 2, 1)\nplot_samples(S / S.std())\nplt.title(\"True Independent Sources\")\n\naxis_list = [pca.components_.T, ica.mixing_]\nplt.subplot(2, 2, 2)\nplot_samples(X / np.std(X), axis_list=axis_list)\nlegend = plt.legend([\"PCA\", \"ICA\"], loc=\"upper right\")\nlegend.set_zorder(100)\n\nplt.title(\"Observations\")\n\nplt.subplot(2, 2, 3)\nplot_samples(S_pca_ / np.std(S_pca_, axis=0))\nplt.title(\"PCA recovered signals\")\n\nplt.subplot(2, 2, 4)\nplot_samples(S_ica_ / np.std(S_ica_))\nplt.title(\"ICA recovered signals\")\n\nplt.subplots_adjust(0.09, 0.04, 0.94, 0.94, 0.26, 0.36)\nplt.show()"
3066
]
3167
}
3268
],
Binary file not shown.

dev/_downloads/dc313f6a0617a04ceea6108f4cde71b6/plot_ica_vs_pca.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
# Authors: Alexandre Gramfort, Gael Varoquaux
3333
# License: BSD 3 clause
3434

35+
# %%
36+
# Generate sample data
37+
# --------------------
3538
import numpy as np
36-
import matplotlib.pyplot as plt
3739

3840
from sklearn.decomposition import PCA, FastICA
3941

40-
# #############################################################################
41-
# Generate sample data
4242
rng = np.random.RandomState(42)
4343
S = rng.standard_t(1.5, size=(20000, 2))
4444
S[:, 0] *= 2.0
@@ -51,14 +51,16 @@
5151
pca = PCA()
5252
S_pca_ = pca.fit(X).transform(X)
5353

54-
ica = FastICA(random_state=rng)
54+
ica = FastICA(random_state=rng, whiten="arbitrary-variance")
5555
S_ica_ = ica.fit(X).transform(X) # Estimate the sources
5656

5757
S_ica_ /= S_ica_.std(axis=0)
5858

5959

60-
# #############################################################################
60+
# %%
6161
# Plot results
62+
# ------------
63+
import matplotlib.pyplot as plt
6264

6365

6466
def plot_samples(S, axis_list=None):

dev/_downloads/scikit-learn-docs.zip

-80 Bytes
Binary file not shown.
-212 Bytes
-204 Bytes
-146 Bytes
-62 Bytes
-1.18 KB

0 commit comments

Comments
 (0)