0Pricing
Learn AI with Python · Lesson

SVMs for Regression (SVR)

SVR epsilon tube, nu-SVR, comparing SVR to linear regression on non-linear data.

SVMs for Regression (SVR) is a free Learn AI with Python lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

SVMs Can Do Regression Too

The margin idea extends to regression. Support Vector Regression (SVR) fits a function while keeping predictions within a tolerance band, ignoring small errors.

The Epsilon-Insensitive Tube

SVR draws an epsilon tube around the predicted function. Points inside the tube contribute zero loss; only points outside are penalized. This focuses the model on meaningful errors.

Why a Tube Helps

By ignoring tiny deviations, SVR resists overfitting to noise and produces a smoother, more robust fit. Small wiggles within tolerance simply do not affect the model.

Basic SVR Usage

SVR mirrors SVC and supports the same kernels. RBF is the common default for non-linear regression.

from sklearn.svm import SVR

model = SVR(kernel="rbf", C=100, epsilon=0.1, gamma="scale")
model.fit(Xtr, ytr)
print(model.score(Xte, yte))

The epsilon Parameter

epsilon sets the tube width. A larger epsilon means a wider band, fewer support vectors, and a simpler model. A smaller epsilon fits the data more tightly.

from sklearn.svm import SVR

wide = SVR(epsilon=1.0)   # tolerant, simpler
tight = SVR(epsilon=0.01) # fits closely

The C Parameter in SVR

As in classification, C controls the penalty for points outside the tube. Larger C punishes those errors more, fitting harder; smaller C regularizes more for a smoother curve.

from sklearn.svm import SVR

flexible = SVR(C=1000)  # fits training closely
smooth = SVR(C=0.1)     # more regularized

epsilon vs C: Two Different Knobs

Remember the distinction: epsilon controls the tube width (how much error to ignore), while C controls the penalty for errors that fall outside the tube. Tune both.

Scaling Matters for SVR Too

Like all SVMs, SVR depends on distances and is scale-sensitive. Always standardize features, and consider scaling the target as well for stable training.

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVR

pipe = make_pipeline(StandardScaler(), SVR(kernel="rbf"))
pipe.fit(Xtr, ytr)

Tuning SVR

Grid search over C, gamma, and epsilon to find the best fit. Use a regression metric like negative mean squared error for scoring.

from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVR

param = {
    "C": [1, 10, 100],
    "gamma": [0.01, 0.1, 1],
    "epsilon": [0.01, 0.1, 0.5],
}
gs = GridSearchCV(SVR(), param, cv=5, scoring="neg_mean_squared_error")
gs.fit(Xtr, ytr)

The nu-SVR Variant

NuSVR replaces epsilon with nu (between 0 and 1), which controls the fraction of support vectors and training errors directly, an alternative parameterization some find easier to reason about.

from sklearn.svm import NuSVR

model = NuSVR(nu=0.5, C=100, kernel="rbf")
model.fit(Xtr, ytr)

When to Use SVR

SVR works well on small-to-medium datasets with non-linear patterns and when robustness to noise matters. For very large data, prefer linear models or gradient boosting, which scale better.

Quick Check

Test your SVR knowledge.

Recap

Recap: SVR fits a function inside an epsilon-insensitive tube where inside points cost zero. epsilon sets the tube width (larger = simpler), while C penalizes points outside it. Always scale features, tune C/gamma/epsilon, and consider NuSVR as an alternative parameterization.

Frequently asked questions

Is the “SVMs for Regression (SVR)” lesson free?

Yes — the full text of “SVMs for Regression (SVR)” is free to read here on the web, and the Learn AI with Python course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.

What will I learn in “SVMs for Regression (SVR)”?

SVR epsilon tube, nu-SVR, comparing SVR to linear regression on non-linear data. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn AI with Python?

No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “SVMs for Regression (SVR)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn AI with Python lesson?

Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. SVM Theory: Margins and Support Vectors
  2. Kernel Trick: RBF, Polynomial, and Sigmoid
  3. SVMs for Classification with sklearn
  4. SVMs for Regression (SVR)
← Back to Learn AI with Python