Flag the Close Calls

Machine Learning in CodeMedium+10 XP+10

Flag the Close Calls

A lab wants a person to double-check any test sample the model is unsure about.

Task: write close_calls(name, k, threshold). name is "iris", "wine" or "breast_cancer".

  • Load the dataset as X and y, and split with train_test_split(X, y, test_size=0.25, random_state=0).
  • Train a KNeighborsClassifier(n_neighbors=k) on the training rows.
  • For every test row, take the highest of its predicted probabilities.
  • Return the positions (0, 1, 2, ... counting rows of X_test in order) of the test rows whose highest probability is less than threshold, in increasing order.

Examples

name = "breast_cancer"
k = 5
threshold = 0.7
returns [0, 3, 10, 14, 93, 107, 116, 126]
name = "wine"
k = 5
threshold = 0.5
returns [14, 22, 24, 35, 36, 39]

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