Score on Unseen Rows
Split X and y at random into a training part and a test part with a quarter of the rows (random_state=0). Fit a linear regression on the training part and return its R squared on the test part.
Example 1
X [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11]]
y [1,3,5,7,9,11,13,15,17,19,21,23]
returns 1.0
The data lie exactly on a line, so the unseen rows are predicted perfectly.
Constraints
12 <= len(X) <= 40- 1 to 3 columns
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More scikit-learn problems
- Small TreeEasy
- Table of Hits and MissesEasy
- Vote of the NeighborsEasy
- Yes or NoEasy
- Average Over Five FoldsMedium
- Best Number of NeighborsMedium
- Centers of the GroupsMedium
- Column That Matters MostMedium