liebke (owner)

Revisions

gist: 121931 Download_button fork
public
Public Clone URL: git://gist.github.com/121931.git
Embed All Files: show embed
incanter_pca.clj #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
;; example of performing PCA on Fisher's iris data
 
(use '(incanter core stats charts datasets))
 
(def iris (to-matrix (get-dataset :iris)))
(view iris)
 
(def X (sel iris :cols (range 4)))
(def species (sel iris :cols 4))
(def pca (principal-components X))
(def components (:rotation pca))
(def pc1 (sel components :cols 0))
(def pc2 (sel components :cols 1))
(def x1 (mmult X pc1))
(def x2 (mmult X pc2))
 
(view (scatter-plot x1 x2
                    :group-by species
                    :x-label "PC1"
                    :y-label "PC2"
                    :title "Iris PCA"))