Two Main Directions
Principal component analysis finds the directions along which a table varies most. Fit it on X keeping 2 components and return the share of the total variance each of the two explains, largest first.
Example 1
X [[1,2,0],[2,4,0],[3,6,0],[4,8,0],[5,10,0],[6,12,0]]
returns [1.0,0.0]
Every row is a multiple of (1, 2, 0): all the variation lies along one direction.
Constraints
- 6 to 40 rows, 3 to 5 columns
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.