Gaps Are Fine Here

Machine Learning in CodeMedium+10 XP+10

Gaps Are Fine Here

HistGradientBoostingClassifier copes with missing values by itself, with no imputer in front. You will punch holes in the iris flower data and check it still works.

Write score_with_gaps(column, every).

  • Load the data with load_iris(return_X_y=True, as_frame=True) and split it with train_test_split(X, y, test_size=0.25, random_state=0, stratify=y).
  • Make copies of X_train and X_test. In both copies, set every every-th row of the column named column to np.nan, starting from the first row. Use .iloc positions, so the rows chosen are positions 0, every, 2 * every and so on in each table.
  • Fit HistGradientBoostingClassifier(random_state=0) on the training copy and score it on the test copy.

Return the test score, rounded to 3 places.

Examples

column = 'petal length (cm)'
every = 2
returns 0.921
column = 'sepal width (cm)'
every = 5
returns 0.974

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run