2
A
回答
3
Scikit learn提供了執行獨立組件分析的方法。
print(__doc__)
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
from sklearn.decomposition import FastICA, PCA
###############################################################################
# Generate sample data
np.random.seed(0)
n_samples = 2000
time = np.linspace(0, 8, n_samples)
s1 = np.sin(2 * time) # Signal 1 : sinusoidal signal
s2 = np.sign(np.sin(3 * time)) # Signal 2 : square signal
s3 = signal.sawtooth(2 * np.pi * time) # Signal 3: saw tooth signal
S = np.c_[s1, s2, s3]
S += 0.2 * np.random.normal(size=S.shape) # Add noise
S /= S.std(axis=0) # Standardize data
# Mix data
A = np.array([[1, 1, 1], [0.5, 2, 1.0], [1.5, 1.0, 2.0]]) # Mixing matrix
X = np.dot(S, A.T) # Generate observations
# Compute ICA
ica = FastICA(n_components=3)
S_ = ica.fit_transform(X) # Reconstruct signals
A_ = ica.mixing_ # Get estimated mixing matrix
# We can `prove` that the ICA model applies by reverting the unmixing.
assert np.allclose(X, np.dot(S_, A_.T) + ica.mean_)
# For comparison, compute PCA
pca = PCA(n_components=3)
H = pca.fit_transform(X) # Reconstruct signals based on orthogonal components
###############################################################################
# Plot results
plt.figure()
models = [X, S, S_, H]
names = ['Observations (mixed signal)',
'True Sources',
'ICA recovered signals',
'PCA recovered signals']
colors = ['red', 'steelblue', 'orange']
for ii, (model, name) in enumerate(zip(models, names), 1):
plt.subplot(4, 1, ii)
plt.title(name)
for sig, color in zip(model.T, colors):
plt.plot(sig, color=color)
plt.subplots_adjust(0.09, 0.04, 0.94, 0.94, 0.26, 0.46)
plt.show()
相關問題
- 1. matlab中的ICA(獨立分量分析)
- 2. ICA(獨立分量分析)快速定點算法
- 3. 獨立的TypoScript分析器庫?
- 4. 獨立部分
- 5. 獨立BigDecimal分數部分
- 6. 獨立IntelliJ語法分析器中的符號解析
- 7. fullpage.js獨立的部分
- 8. 多個獨立的部分
- 9. ICA - 統計獨立性和協方差矩陣的特徵值
- 10. AngularJS中的多個獨立部分
- 11. 分發獨立libpython路徑
- 12. 獨立使用部分
- 13. 案例獨立分揀
- 14. 拆分變量的數據爲獨立的變量
- 15. 在VS2008 Professional中使用MS獨立分析器
- 16. 如何在獨立程序中使用llvm分析傳遞?
- 17. 分析量的
- 18. 如何在Python中生成獨立同分布(iid)隨機變量
- 19. 獲得獨立審計/審查/分析的資源?
- 20. 來自2臺獨立機器的Hadoop日誌文件分析
- 21. 兩個獨立樣本組的非入侵簇分析
- 22. 在Python中的Wav分析
- 23. python中的時間分析
- 24. PYTHON中的音頻分析
- 25. Python中的日誌分析
- 26. Python中的頻率分析
- 27. python中的情感分析
- 28. python中的因子分析
- 29. 分析python中的圖
- 30. 基於流的流量分析在Python