我一直在嘗試使用Incanter的principal-components
函數來做PCA,看起來在使用它的時候出現了偏離軌跡。我從PCA教程發現了一些樣本數據在線,並希望它的做法:主要組件功能Inc器
(def data [[0.69 0.49] [-1.31 -1.21] [0.39 0.99] [0.09 0.29] [1.29 1.09]
[0.49 0.79] [0.19 (- 0 0.31)] [(- 0 0.81) (- 0 0.81)]
[(- 0 0.31) (- 0 0.31)] [(- 0 0.71) (- 0 1.01)]])
在第一次嘗試實現PCA我試圖通過向量咒術矩陣功能,但發現自己傳遞的參數太多。在這一點上,我決定嘗試一個上面定義的嵌套向量結構,但是想避免這條路線。
如何將data
轉換成矩陣(瞳孔),以便它將被接受爲Incanter函數principal-components
的輸入。爲了簡單起見,我們稱之爲新矩陣fooMatrix。
一旦這個矩陣,fooMatrix,已構建了下面的代碼應該工作以提取前兩個主成分
(def pca (principal-components fooMatrix))
(def components (:rotation pca))
(def pc1 (sel components :cols 0))
(def pc2 (sel components :cols 1))
,然後將數據可以在主成分由
(def principal1 (mmult fooMatrix pc1))
(def principal2 (mmult fooMatrix pc2))
您似乎沒有提出問題。 [此鏈接](http://data-sorcery.org/category/pca/)討論通過Incanter使用PCA,並且在帖子的底部是所有使用的源代碼的鏈接。 – galdre
我不明白的是如何將'data'中包含的向量轉換成矩陣,可以用於Incanter函數'principal-component'。@ galdre – sunspots
我修改了我的初始文章,使得問題是明確的, 謝謝。 – sunspots