Skip to content

Instantly share code, notes, and snippets.

@liebke
Created June 2, 2009 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liebke/121931 to your computer and use it in GitHub Desktop.
Save liebke/121931 to your computer and use it in GitHub Desktop.
;; 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"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment