Loosen the Corridor

Machine Learning in CodeMedium+10 XP+10

Loosen the Corridor

C says how much a support vector machine cares about training mistakes. A small C buys a wider corridor, and more rows end up touching it.

Write corridor_by_c(c_values) for the breast cancer data.

  • 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).
  • For each value in c_values, in order, fit make_pipeline(StandardScaler(), SVC(kernel="linear", C=c)) on the training rows.
  • Count its support vectors (the sum of n_support_ on the svc step) and score it on the test rows.

Return a list with one [c, support_vectors, test_score] per value. support_vectors is an int. Round test_score to 3 places.

Examples

c_values = [0.01, 1]
returns [[0.01, 95, 0.965], [1, 29, 0.965]]
c_values = [100]
returns [[100, 24, 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