A wrapper method judges a feature set by actually fitting a model on it. Forward selection starts from nothing and, at each step, adds the single feature that gives the best fit when combined with the features already chosen.
Implement forward_selection(X, y, k). It returns the list of k selected column indices, in the order they were picked.
At each step, for every feature not yet chosen:
R^2 = 1 - SS_res / SS_tot. If SS_tot is zero, the score is 0.0.Pick the feature with the highest score. Ties go to the smallest index.
X is 2-D with d columns, y has one value per row.1 <= k <= d, otherwise raise ValueError.Use np.linalg.lstsq on a design matrix with a column of ones prepended.
No results yet
Run your code to check it against the examples, or submit to run every test.