回答編集履歴

2

修正

2018/09/04 04:40

投稿

hayataka2049
hayataka2049

スコア30933

test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
  array([-2.68420713e+00, 3.26607315e-01, -2.15118370e-02, 1.00615724e-03])
48
48
 
49
- >>> np.matmul(iris.data - iris.data.mean(axis=0), pca.components_.T)[0] # 平均を引いてセンタリングして、pca.components_を転置したものと行列積を計算し、0番目を取り出す
49
+ >>> np.matmul(iris.data - iris.data.mean(axis=0), pca.components_.T)[0] # データから平均を引いてセンタリングして、pca.components_を転置したものと行列積を計算し、0番目を取り出す
50
50
 
51
51
  array([-2.68420713e+00, 3.26607315e-01, -2.15118370e-02, 1.00615724e-03])
52
52
 

1

追記

2018/09/04 04:40

投稿

hayataka2049
hayataka2049

スコア30933

test CHANGED
@@ -19,3 +19,39 @@
19
19
 
20
20
 
21
21
  主成分を削減後の空間の基底にしたいので、主成分が直交するような表現を作ります。これは共分散行列を固有値分解して固有ベクトルを得れば良いのですね。
22
+
23
+
24
+
25
+ ### 追記
26
+
27
+ components_から削減後のデータ(いわゆる主成分得点)を生成するのは簡単です。
28
+
29
+
30
+
31
+ ```python
32
+
33
+ >>> import numpy as np
34
+
35
+ >>> from sklearn.decomposition import PCA
36
+
37
+ >>> from sklearn.datasets import load_iris
38
+
39
+ >>> iris = load_iris()
40
+
41
+ >>> pca = PCA()
42
+
43
+ >>> X = pca.fit_transform(iris.data)
44
+
45
+ >>> X[0] # 0番目の変換後のデータ
46
+
47
+ array([-2.68420713e+00, 3.26607315e-01, -2.15118370e-02, 1.00615724e-03])
48
+
49
+ >>> np.matmul(iris.data - iris.data.mean(axis=0), pca.components_.T)[0] # 平均を引いてセンタリングして、pca.components_を転置したものと行列積を計算し、0番目を取り出す
50
+
51
+ array([-2.68420713e+00, 3.26607315e-01, -2.15118370e-02, 1.00615724e-03])
52
+
53
+ ```
54
+
55
+
56
+
57
+ transformを呼ぶと、こういう処理がなされると。