Skip to content
AI360XpertBeta
Playgrounds

Supervised Learning

Support Vector Machines

A soft-margin fit balances a small weight norm against training points falling short of their functional margin.

Data seed 1234

Guided steps 1 / 4

Stage 1 of 4: Margin street

Training observations 80. 0 outside the raw plot. pending computation. No completed current fit.

40 × 28 cell-centre samples; interpolated score contours stop at sample centres. ±6 raw window; 0 observations cropped. Fixed opacity is not confidence. Axes stretch to the frame; pixel distances are not feature distances. Diamond: final observation; cross: query. Heavy class glyphs: alpha support.

  • Class A / plain region
  • Class B / hatched region
  • Score zero
  • Scores −1 and +1

Observation 1: raw x 0.9722470803952576, y 1.8554967390254187, Class B.

Edit final observation

Only observation 80 is editable. Its label stays Class A. Raw starting coordinates stay exact until edited. The handle is limited to ±5; an unedited observation beyond that range has its handle parked at the edge until moved.

Adjust parameters

Computation: pending. Pair searches 0/2000; field rows 0/28.

Current fit/readouts are unavailable until computation completes.

Move the editable observation. How does the fitted street respond?

The solid boundary is score zero. Dashed contours are scores −1 and +1. For a linear fit their feature-space separation is 2 divided by the weight norm.

  1. Choose features and C
  2. Fit training labels only
  3. Compute one kernel score
  4. Inspect margin, slack and evaluation
Geometric margin

Score divided by a nonzero feature-space weight norm is signed perpendicular distance.

Check this stage

Move a training observation, inspect its score and slack, then compare fitted kernels on the same observations.

What holds the street in place?

An SVM balances a wide feature-space margin against training observations that fall short of it. Move the neutral diamond: it edits the final training observation while keeping its label. The solid curve is score zero; dashed curves are scores −1 and +1. Class A uses circles and Class B squares. The plain and hatched regions sample the same fitted score. Their opacity is fixed, not confidence.

In Support vectors, move the separate cross and predict its class. The cross is a query, never a training observation. A nonnegative score selects B, including exact zero. The score is not a calibrated probability. Heavier class glyphs mark observations whose fitted dual coefficient exceeds the numerical tolerance shown under the hood. Inspect any observation using the selector or its focused mark.

For a linear model with w=(1,0)w=(1,0) and b=0b=0, the score is just xx. Observations at (−1,0)(-1,0) labelled A and (1,0)(1,0) labelled B have scores −1 and +1. Each has signed margin 1 and hinge loss 0. The planes are two feature units apart. Moving a formerly inactive point into the street can change which observations support a refitted model; support status is not a permanent property of a point.

What does C pay for?

Open Soft margin. This lab fits the mean-hinge objective

J(w,b)=12∥w∥2+Cn∑i=1nmax⁡(0,1−yif(xi)).J(w,b)=\frac12\lVert w\rVert^2+\frac Cn\sum_{i=1}^{n}\max(0,1-y_i f(x_i)).

Here nn counts training observations, yiy_i is −1 for A and +1 for B, and ff is the fitted score. The intercept bb is not penalised. Hinge loss is not squared hinge. This C multiplies the mean, whereas a common library convention multiplies the sum: the equivalent summed-loss C is this value divided by nn.

Slack is the dimensionless deficit ξi=max⁡(0,1−yif(xi))\xi_i=\max(0,1-y_i f(x_i)). A B observation with score 0.4 is correct but has slack 0.6. An A observation with score 8 has signed margin −8 and slack 9. For a linear weight vector (3,4)(3,4) its signed geometric distance is 8/58/5, since the norm is 5. Slack itself is not that distance.

On the two-observation example, C = 2 gives dual coefficients 0.5 each, weight (1,0)(1,0), zero hinge and objective 0.5. C = 0.2 gives coefficients 0.1, weight (0.2,0)(0.2,0), mean hinge 0.8 and objective 0.02+0.2×0.8=0.180.02+0.2\times0.8=0.18. Both predictions are still correct. A wider street and support from every observation do not establish a bad model or numerical divergence.

Try Conflicting labels. Each location has both labels, so the same score necessarily gets at least one member of each pair wrong. Increasing C cannot invent a distinguishing feature. Back to working restores the preceding experiment, including its mode, inspection and prediction. Recovery remains available in free exploration.

Which space has the margin?

The feature-one divisor changes every kernel through (x/d,y)(x/d,y). It is a chosen scale, not learned standardisation. Even for a linear fit, the reported street width 2/∥w∥2/\lVert w\rVert is measured in these scaled coordinates. Nonlinear raw-space contours generally have no constant Euclidean width.

Open Kernels, press Load rings, then switch kernels. The observations stay fixed during the comparison.

  • Linear uses the inner product of (x/d,y)(x/d,y).
  • Explicit radial height uses ϕ(x,y)=0.3((x/d)2+y2)\phi(x,y)=0.3((x/d)^2+y^2) and K(u,v)=ϕ(u)ϕ(v)K(u,v)=\phi(u)\phi(v). It discards angular information. This is a one-feature kernel, not a full polynomial kernel.
  • RBF uses K(u,v)=exp⁡(−γ∥u−v∥2)K(u,v)=\exp(-\gamma\lVert u-v\rVert^2) in scaled coordinates. Gamma is relevant only here; larger gamma makes similarity decay faster at fixed nonzero distance.

For (1,0)(1,0) and (0,2)(0,2) with divisor 1, radial heights are 0.3 and 1.2, giving kernel value 0.36. RBF with gamma 0.5 instead gives exp⁡(−2.5)\exp(-2.5). These are different geometries, not two views of one feature map.

With radial height selected, Lift to 3D places observations at their actual feature heights and outlines the fitted horizontal score-zero cut. The angle control changes an oblique projection. It preserves the depicted height relation but distorts lengths and angles and loses depth information. Original coordinates and height remain in inspection. Projected distance must not be read as an original-space margin; the raw view stays alongside it. This picture does not represent RBF's feature space.

How much of the solution is known?

The score uses the actual fitted expansion

f(x)=∑iαiyiK(xi,x)+b,0≤αi≤C/n,∑iyiαi=0.f(x)=\sum_i\alpha_i y_iK(x_i,x)+b,\qquad 0\leq\alpha_i\leq C/n,\qquad\sum_i y_i\alpha_i=0.

The solver searches feasible coefficient pairs deterministically within a fixed budget. Under the hood shows primal and dual objectives, their gap, equality/box residuals and the largest KKT residual. At an exact optimum, zero alpha permits signed margin at least 1; a coefficient strictly between bounds has margin 1; a coefficient at its upper bound permits margin below 1. Finite numerical results only approximate these conditions. A completed computation can report budget exhausted or pair improvement stalled rather than tolerance met. Cancelled and failed work has a Retry action and supplies no completed current scores.

The field samples 40 × 28 cell centres in the raw ±6 window. Contours interpolate that score mesh and stop at its outer sample centres. They can miss narrow features between samples. Cropped observation counts are printed, and raw coordinates, scores and margins remain in the drawer. Neither the mesh nor a screenshot proves a claim about every query.

What do the scores evaluate?

Training accuracy uses the fitted observations. Generated datasets also have a fixed independent validation draw; its labels never enter the solver, kernel matrix or coefficient-pair selection. Kernel comparisons reuse both draws. New data changes the training seed while retaining validation; duplicates have no independent-validation claim. Per-class recall and a training-majority baseline expose imbalance under the hood.

Once you use validation to choose a kernel or C, it is exploratory validation. An untouched final test would come after selection and is not computed here. Increasing C need not improve training accuracy after finite optimisation, and a higher training score does not guarantee better generalisation.

Load the fixed rings challenge and choose a kernel while keeping its seed, C, scaling and unedited observations unchanged. The goal measures training and exploratory validation accuracy, with the stated solver tolerance. Reset controls retains stage and seed, clears edits and recovery. Shared links reproduce the guided display stage, seed, controls, edit, query, inspection and projection by refitting from scratch; guesses, pending work, mode identity and recovery snapshots are excluded.

Stage recap

  1. Margin street

    The solid boundary is score zero. Dashed contours are scores −1 and +1. For a linear fit their feature-space separation is 2 divided by the weight norm.

  2. Support vectors

    Heavier class glyphs have a dual coefficient above numerical tolerance. They include bound observations on the wrong side, not just points near the boundary.

  3. Soft margin

    C weights mean hinge loss here. Slack is max(0, 1 − signed label × score), a dimensionless deficit. A wide street or many support vectors is not numerical divergence.

  4. Kernels

    The radial feature supplies explicit height; RBF evaluates pairwise similarity. Their feature-space margins are not Euclidean street widths in the raw plot.

Reference

Objective
J = ||w||²/2 + C × mean max(0, 1 − y f(x)). Hinge is not squared hinge; the intercept is unpenalised.
Dual constraints
0 ≤ alpha ≤ C/n and sum y alpha = 0. Score = sum alpha y K + b; zero selects B.
Geometry
The ±1 feature-space planes are 2/||w|| apart for nonzero norm. Nonlinear raw contours have no constant Euclidean width.
Kernels
Linear on (x/divisor,y); radial phi=0.3((x/divisor)²+y²), K=phi(u)phi(v); RBF exp(−gamma × squared scaled distance). No polynomial degree is fitted.

Break it on purpose

Load conflicting labels at identical coordinates. A deterministic score gives each duplicate pair the same prediction, so at least one label in each pair is wrong. Increasing C cannot repair contradictory features.