A Ring Around a Dot

Machine Learning in CodeMedium+10 XP+10

A Ring Around a Dot

A sprinkler waters a small circle of lawn. Points inside the circle are wet (0). Points in a ring further out are dry (1). No straight line can separate a circle from the ring around it.

Write ring_predictions(points, labels, new_points).

  • Fit two models on the same points: SVC(kernel="linear") and SVC(kernel="rbf"). Use the default C for both. The two columns share the same units, so no scaling is needed.
  • Predict every point in new_points with each model.

Return a dict {"linear": [...], "rbf": [...]} holding the two lists of predicted labels, as ints, in order.

Examples

points = [[1.0, 0.1], [0.63, 0.77], [-0.1, 1.0], [-0.77, 0.63], [-1.0, -0.1], [-0.63, -0.77], [0.1, -1.0], [0.77, -0.63], [2.94, 0.6], [2.49, 1.68], [1.66, 2.5], [0.57, 2.94], [-0.6, 2.94], [-1.68, 2.49], [-2.5, 1.66], [-2.94, 0.57], [-2.94, -0.6], [-2.49, -1.68], [-1.66, -2.5], [-0.57, -2.94], [0.6, -2.94], [1.68, -2.49], [2.5, -1.66], [2.94, -0.57]]
labels = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
new_points = [[0.2, 0.3], [2.8, 0.9]]
returns {'linear': [1, 1], 'rbf': [0, 1]}
points = [[1.0, 0.1], [0.63, 0.77], [-0.1, 1.0], [-0.77, 0.63], [-1.0, -0.1], [-0.63, -0.77], [0.1, -1.0], [0.77, -0.63], [2.94, 0.6], [2.49, 1.68], [1.66, 2.5], [0.57, 2.94], [-0.6, 2.94], [-1.68, 2.49], [-2.5, 1.66], [-2.94, 0.57], [-2.94, -0.6], [-2.49, -1.68], [-1.66, -2.5], [-0.57, -2.94], [0.6, -2.94], [1.68, -2.49], [2.5, -1.66], [2.94, -0.57]]
labels = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
new_points = [[-0.5, 0.4], [-2.5, -1.6]]
returns {'linear': [1, 1], 'rbf': [0, 1]}

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