Your First Real Score

Machine Learning in CodeEasy+10 XP+10

Your First Real Score

A clinic wants to know how well nearest neighbours tells harmless tissue samples from cancerous ones, using the built-in breast cancer data.

Task: write cancer_test_score(k).

  • Load the breast cancer data as X and y.
  • Split it with train_test_split(X, y, test_size=0.25, random_state=0).
  • Train a KNeighborsClassifier(n_neighbors=k) on the training rows.
  • Return its score on the test rows, rounded to 3 decimal places.

Examples

k = 5
returns 0.937
k = 1
returns 0.916

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