2D点云上的FastICA#

此示例在特征空间中直观地说明了使用两种不同成分分析技术的结果的比较。

独立成分分析(ICA) vs 主成分分析(PCA) .

在特征空间中表示ICA给出了“几何ICA”的观点:ICA是一种在特征空间中找到与高非高斯投影对应的方向的算法。这些方向不需要在原始特征空间中正交,但它们在白化特征空间中正交,其中所有方向对应于相同的方差。

另一方面,PCA在原始特征空间中找到与最大方差方向相对应的正交方向。

在这里,我们使用高度非高斯过程模拟独立源,2个学生T具有低自由度(左上图)。我们将它们混合以创建观察结果(右上图)。在这个原始观察空间中,PCA识别的方向用橙色载体表示。我们在PCA空间中表示信号,然后通过对应于PCA载体(左下)的方差白化。运行ICA对应于在该空间中找到旋转以识别最大非高斯性的方向(右下)。

# Authors: The scikit-learn developers
# SPDX-License-Identifier: BSD-3-Clause

生成示例数据#

import numpy as np

from sklearn.decomposition import PCA, FastICA

rng = np.random.RandomState(42)
S = rng.standard_t(1.5, size=(20000, 2))
S[:, 0] *= 2.0

# Mix data
A = np.array([[1, 1], [0, 2]])  # Mixing matrix

X = np.dot(S, A.T)  # Generate observations

pca = PCA()
S_pca_ = pca.fit(X).transform(X)

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

图结果#

import matplotlib.pyplot as plt


def plot_samples(S, axis_list=None):
    plt.scatter(
        S[:, 0], S[:, 1], s=2, marker="o", zorder=10, color="steelblue", alpha=0.5
    )
    if axis_list is not None:
        for axis, color, label in axis_list:
            x_axis, y_axis = axis / axis.std()
            plt.quiver(
                (0, 0),
                (0, 0),
                x_axis,
                y_axis,
                zorder=11,
                width=0.01,
                scale=6,
                color=color,
                label=label,
            )

    plt.hlines(0, -5, 5, color="black", linewidth=0.5)
    plt.vlines(0, -3, 3, color="black", linewidth=0.5)
    plt.xlim(-5, 5)
    plt.ylim(-3, 3)
    plt.gca().set_aspect("equal")
    plt.xlabel("x")
    plt.ylabel("y")


plt.figure()
plt.subplot(2, 2, 1)
plot_samples(S / S.std())
plt.title("True Independent Sources")

axis_list = [(pca.components_.T, "orange", "PCA"), (ica.mixing_, "red", "ICA")]
plt.subplot(2, 2, 2)
plot_samples(X / np.std(X), axis_list=axis_list)
legend = plt.legend(loc="upper left")
legend.set_zorder(100)

plt.title("Observations")

plt.subplot(2, 2, 3)
plot_samples(S_pca_ / np.std(S_pca_))
plt.title("PCA recovered signals")

plt.subplot(2, 2, 4)
plot_samples(S_ica_ / np.std(S_ica_))
plt.title("ICA recovered signals")

plt.subplots_adjust(0.09, 0.04, 0.94, 0.94, 0.26, 0.36)
plt.tight_layout()
plt.show()
True Independent Sources, Observations, PCA recovered signals, ICA recovered signals

Total running time of the script: (0分0.301秒)

相关实例

使用FastICA的盲源分离

Blind source separation using FastICA

Iris数据集LDA和PCA 2D投影的比较

Comparison of LDA and PCA 2D projection of Iris dataset

单一估计量与装袋:偏差方差分解

Single estimator versus bagging: bias-variance decomposition

主成分回归与偏最小平方回归

Principal Component Regression vs Partial Least Squares Regression

Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io> _