public static PlotCanvas screeplot ( PCA pca ) { int n = pca . getVarianceProportion ( ) . length ; double [ ] lowerBound = { 0 , 0.0 } ; double [ ] upperBound = { n + 1 , 1.0 } ; PlotCanvas canvas = new PlotCanvas ( lowerBound , upperBound , false ) ; canvas . setAxisLabels ( "Principal Component" , "Proportion of Variance" ) ; String [ ] labels = new String [ n ] ; double [ ] x = new double [ n ] ; double [ ] [ ] data = new double [ n ] [ 2 ] ; double [ ] [ ] data2 = new double [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { labels [ i ] = "PC" + ( i + 1 ) ; x [ i ] = i + 1 ; data [ i ] [ 0 ] = x [ i ] ; data [ i ] [ 1 ] = pca . getVarianceProportion ( ) [ i ] ; data2 [ i ] [ 0 ] = x [ i ] ; data2 [ i ] [ 1 ] = pca . getCumulativeVarianceProportion ( ) [ i ] ; } LinePlot plot = new LinePlot ( data ) ; plot . setID ( "Variance" ) ; plot . setColor ( Color . RED ) ; plot . setLegend ( ' ' ) ; canvas . add ( plot ) ; canvas . getAxis ( 0 ) . addLabel ( labels , x ) ; LinePlot plot2 = new LinePlot ( data2 ) ; plot2 . setID ( "Cumulative Variance" ) ; plot2 . setColor ( Color . BLUE ) ; plot2 . setLegend ( ' ' ) ; canvas . add ( plot2 ) ; return canvas ; }
Create a scree plot for PCA .