Matrix 主成分函数白炽灯

Matrix 主成分函数白炽灯,matrix,clojure,pca,incanter,principal-components,Matrix,Clojure,Pca,Incanter,Principal Components,我一直在尝试使用Incater的主成分功能来进行PCA,但在使用过程中似乎偏离了正轨。我从PCA教程中在线找到了一些样本数据,并想在上面进行练习: (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)] [

我一直在尝试使用Incater的
主成分
功能来进行PCA,但在使用过程中似乎偏离了正轨。我从PCA教程中在线找到了一些样本数据,并想在上面进行练习:

(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时,我尝试将向量传递给Incanter的矩阵函数,但发现自己传递的参数太多。在这一点上,我决定尝试上面定义的嵌套向量结构,但希望避免这种路径

我如何将
数据
转换为矩阵(白炽灯),以便将其作为输入输入白炽灯的功能
主要部件
。为了简单起见,我们将新矩阵称为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))
看看这本书。我相信您只需要
(incanter.core/matrix data)
。这些是白炽灯矩阵功能的选项。也许A2是你感兴趣的

(def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) ; produces a 3x3 matrix
(def A2 (matrix [1 2 3 4 5 6 7 8 9] 3)) ; produces the same 3x3 matrix
(def B (matrix [1 2 3 4 5 6 7 8 9])) ; produces a 9x1 column vector
使用数据的示例:

user=> (use '[incanter core stats charts datasets])
nil
user=>(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)])
user=>(def fooMatrix (matrix data 2))
user=>(principal-components fooMatrix)
{:std-dev (1.3877785387777999 0.27215937850413047), :rotation  A 2x2 matrix
 -------------
-7.07e-01 -7.07e-01 
-7.07e-01  7.07e-01 
}

瞧。嵌套向量结构消失。

您似乎没有提出任何问题。讨论通过白炽灯使用PCA,在文章的底部是所有使用的源代码的链接。我不明白的是如何将
数据
中包含的向量转换成一个矩阵,而不是白炽灯函数
主成分
@galdreI已经修改了我最初的文章,使问题变得明确,谢谢。
A2
就是我想要的矩阵构造