Scored in Time Order
The rows of X and y are in time order. Ordinary cross-validation would fit on the future to predict the past. Score a ridge regression (alpha=1.0) with a time series split of 4 splits instead, where every test fold comes after the rows used for fitting, and return the mean of the negative mean squared errors.
Example 1
X [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19]]
y [3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41]
returns -0.5033301284796573
Close to 0: a line continues the same way into the future, and the small penalty costs a little.
Constraints
20 <= len(X) <= 60- 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
- Spam or NotHard
- Tune Then TestHard
- Hold Some BackBeginner
- Learn Then PredictBeginner
- Names to NumbersBeginner
- Same ScaleBeginner
- Share RightBeginner
- Typical Squared MissBeginner