Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 22

Support Vector Regression

Fit a numeric target while ignoring errors inside a margin, using the same kernel idea as a support vector machine. One example is on this page.

Intermediate12 min
Support Vector Regression MahiDev

What You Will Learn

  • Idea
  • Example
  • When to use it

Idea

Support vector regression draws a tube around the prediction. Points inside the tube do not change the fit. Points outside become the support vectors that set the shape. A kernel lets that tube bend.

Example

python
import numpy as np
from sklearn.svm import SVR

x = np.array([1, 2, 3, 4, 5], dtype=float).reshape(-1, 1)
y = np.array([2.0, 2.1, 2.0, 6.0, 6.2])
pred = SVR(kernel="rbf", C=10).fit(x, y).predict([[4.5]])[0]
print(f"predict 4.5: {pred:.2f}")

Output:

text
predict 4.5: 6.81

When to use it

  • Use it for a numeric target when a straight line is too rigid.
  • Scale the inputs. Distances drive the kernel.
  • C controls how hard the model chases points that fall outside the tube.

Loading playground…