Too Sure of Itself

Machine Learning in CodeMedium+10 XP+10

Too Sure of Itself

Naive Bayes counts the same evidence many times over when columns rise together, so it ends up far too sure of itself. You want to measure that on the breast cancer data.

Write very_sure(level).

  • Load the data with load_breast_cancer(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).
  • Fit a GaussianNB model on the training rows.
  • For each test row, take the larger of its two predict_proba values. That is how sure the model is about the class it picks.
  • Count the test rows where that value is greater than level.
  • Of those rows, count how many the model actually got wrong (its prediction differs from the true label).

Return a dict {"very_sure": ..., "very_sure_but_wrong": ...} with two ints.

Examples

level = 0.9
returns {'very_sure': 141, 'very_sure_but_wrong': 11}
level = 0.9999
returns {'very_sure': 132, 'very_sure_but_wrong': 5}

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