Database Reference
In-Depth Information
(def race-by-state
(reduce #(i/$join [:STATE :STATE] %1 %2)
(map #(i/$rollup :sum % :STATE race-data)
fields)))
2.
Next, we'll take the summary and create a matrix from it. From that matrix, we'll
extract the columns that we're interested in analyzing and graphing:
(def race-by-state-matrix (i/to-matrix race-by-state))
(def x (i/sel race-by-state-matrix :cols (range 1 8)))
3.
Now we'll perform the principal component analysis:
(def pca (s/principal-components x))
4. From the output of the PCA, we'll get the components for the irst two dimensions and
multiply all the columns in the data matrix by each component:
(def components (:rotation pca))
(def pc1 (i/sel components :cols 0))
(def pc2 (i/sel components :cols 1))
(def x1 (i/mmult x pc1))
(def x2 (i/mmult x pc2))
5.
We can plot x1 and x2 . We'll use them to create a two-dimensional scatter plot:
(def pca-plot
(c/scatter-plot
x1 x2
:x-label "PC1", :y-label "PC2"
:title "Census Race Data by State"))
6.
We can view that chart as we normally would:
(i/view pca-plot)
 
Search WWH ::




Custom Search