Support Vector Regression with Scikit-Learn
Support Vector Regression (SVR) is a supervised machine learning algorithm used to predict continuous numerical values, such as salaries, house prices, temperatures, or sales.
The central idea is simple:
Find a function that is as simple as possible while keeping prediction errors within an acceptable margin.
Unlike ordinary linear regression, SVR does not try to make every prediction as close as possible to its actual value. Instead, it allows small errors and penalizes errors that exceed a chosen tolerance.
TL;DR
- SVR draws a tolerance tube of half-width ε around a function. Errors inside cost nothing; errors outside cost in proportion to how far outside they are.
- ε = how much error to ignore. C = how much to care about the errors that remain. γ (gamma) = how wiggly the RBF curve may be.
- A kernel lets SVR fit curves while doing straight-line math behind the scenes.
- Only support vectors (points on or outside the tube) shape the model.
- Scale X and, in practice, y with two separate scalers;
inverse_transformevery prediction. - Fit scalers on training data only, and evaluate on data the model hasn't seen.
What you'll learn
- Where SVR fits among regression algorithms
- How the epsilon-insensitive tube works
- What support vectors and slack variables mean
- How
epsilonandCaffect the model - How kernels allow SVR to learn non-linear relationships
- Why feature scaling matters
- How to train, predict with, and visualize an SVR model
We'll begin with a straight line to understand the algorithm, then use a non-linear kernel to model more complex relationships.
1. The Big Picture
Imagine that we have data about job position levels and their salaries. We want to learn the relationship between position level and salary so that we can estimate the salary for a new level.
SVR tries to draw a function through the data, but it does not insist that the function pass close to every observation.
Instead, it creates a tolerance tube around the function:
- Points inside the tube are considered close enough and receive no error penalty.
- Points outside the tube receive a penalty based on how far they are beyond the tube.
- The model also tries to keep the function simple or flat.
This creates a trade-off between model simplicity and prediction error.
Keep this picture in mind. The rest of the algorithm explains how SVR defines the tube, measures errors outside it, and chooses the function.
2. Where SVR Fits: Regression Models
SVR is a supervised learning algorithm. Supervised learning means that we train a model using examples that contain both input features and known target values.
Regression algorithms predict continuous numerical values.
| Algorithm | Purpose |
|---|---|
| Linear Regression | Fits a linear relationship by minimizing squared errors |
| Polynomial Regression | Uses polynomial features to model curved relationships |
| Support Vector Regression | Fits a function using an acceptable error margin |
SVR is based on the Support Vector Machine (SVM) framework:
- SVM for classification finds a decision boundary that separates classes.
- SVR for regression finds a function that predicts numerical values while tolerating errors inside a margin.
Notation used in this tutorial
| Symbol | Meaning |
|---|---|
| Input feature(s) for observation | |
| Actual target value | |
| Predicted target value | |
| Regression function | |
| Half-width of the tolerance tube | |
| Slack for a point above the upper tube boundary | |
| Slack for a point below the lower tube boundary | |
| Weight vector in the linear formulation | |
| Penalty strength for errors outside the tube | |
| Kernel measuring similarity between two observations |
You do not need to memorize these symbols now. We'll introduce them as we use them.
3. The Intuition Behind SVR
3.1 First, remember how Linear Regression works
Linear Regression tries to find the best-fitting line by minimizing the sum of squared residuals. A residual is the difference between the actual value and the predicted value:
For example:
| Actual salary | Predicted salary | Residual |
|---|---|---|
| $100,000 | $95,000 | $5,000 |
| $100,000 | $100,000 | $0 |
| $100,000 | $110,000 | -$10,000 |
Linear Regression minimizes:
This is called Ordinary Least Squares (OLS). Every observation contributes to the total error. A point with a large residual can have a particularly strong influence because the residual is squared.
3.2 SVR uses an acceptable error margin
SVR takes a different approach. It creates a tolerance tube around the regression function. The tube represents a region where prediction errors are considered acceptable.

Figure 3.2: SVR tries to fit a simple regression function while tolerating errors inside an epsilon-insensitive tube.
Suppose the model predicts a salary of $100,000 and we choose an acceptable error of $5,000.
The acceptable range is:
Any actual salary in this range is considered close enough. SVR does not penalize those errors.
The tube extends ε above and below the function, so its total width is 2ε.
Important: Epsilon is measured vertically, along the target-value axis. It is not a horizontal distance along the input axis.
3.3 What happens outside the tube?
Consider three actual salaries when the prediction is $100,000 and ε = $5,000.
| Actual salary | Distance beyond tube | Penalty amount |
|---|---|---|
| $102,000 | Inside the tube | $0 |
| $112,000 | $7,000 above the upper edge | $7,000 |
| $90,000 | $5,000 below the lower edge | $5,000 |

Figure 3.3: the three salaries against one prediction of $100,000, with the tube from $95,000 to $105,000.
Notice that the penalty is measured from the edge of the tube, not from the regression function.
For the $90,000 observation, the prediction error is $10,000, but the amount outside the acceptable margin is only $5,000.
🔑 Key takeaway: SVR ignores errors inside the epsilon tube and penalizes only the amount by which observations fall outside it.
3.4 Why does SVR want a flat function?
If SVR only tried to put every point inside the tube, it could build an unnecessarily complicated function. So it has a second goal: keep the function simple or flat.
For a line f(x) = wx + b, the slope is w, so a small w means a gentle slope. For non-linear kernels the same regularization idea controls the complexity of the function in the model's feature space.
SVR therefore balances two goals:
- Keep the function simple.
- Reduce errors that exceed the epsilon margin.
4. Understanding Epsilon and C
Two important SVR hyperparameters are:
- ε (epsilon): the width of the tolerance tube around the prediction.
- C: how strongly errors outside that tube are penalized.
They affect different parts of the model: epsilon decides which errors are penalized, and C decides how heavily.
4.1 What Does Epsilon Control?
Epsilon answers:
How much prediction error am I willing to ignore?
Suppose the prediction is $100,000.
| Epsilon | Acceptable range |
|---|---|
| $1,000 | 101,000 |
| $5,000 | 105,000 |
| $10,000 | 110,000 |
- A smaller epsilon creates a narrower tube, so more observations may fall outside.
- A larger epsilon creates a wider tube, so more observations may fall inside.

Figure 4.1: Same data and regression line with two epsilon values.
Important: epsilon is in the same units as the target.
- Salary in dollars:
epsilon=0.1means $0.10, far too small to be useful.- Standardized salary (our dataset): one unit is one standard deviation, about $284,000. So
epsilon=0.1is about $28,000, a sensible tube.This is a major reason target scaling matters when training SVR.
4.2 What Does C Control?
C answers:
How strongly should the model care about errors that exceed the acceptable margin?
Epsilon decides which errors are penalized. C controls how heavily those errors are penalized.
| C | General effect |
|---|---|
| Small C | Outside errors are relatively cheap; the model is more willing to accept them for a simpler function |
| Large C | Outside errors are more expensive; the model works harder to reduce them |
Imagine two models with the same epsilon:
- Model A:
SVR(C=0.1, epsilon=0.1): 'I prefer a simple function, even if some points miss. Those misses are cheap.' - Model B:
SVR(C=100, epsilon=0.1): 'Misses are expensive. I'll reshape the function to pull points inside the tube.'
Both have the same tube width. They differ only in how strongly they penalize points outside it.
How C behaves depends on the kernel:
- Linear kernel: the function can only change slope and intercept. A larger C may tilt or shift the line but can't bend it, so the effect is often modest.
- Non-linear kernel: a larger C lets the curve bend toward the observations.

Figure 4.2: linear SVR, small vs. large C.

Figure 4.3: RBF SVR, small vs. large C.
A larger C does not guarantee every observation will be fitted perfectly. The model still balances error penalties against its preference for a simpler function.
4.3 Epsilon vs. C
| Parameter | Controls | Ask yourself |
|---|---|---|
epsilon |
Width of the tolerance tube | How much error can I ignore? |
C |
Penalty for errors outside the tube | How much should I care about those errors? |
- Increasing epsilon widens the tube.
- Increasing C makes each remaining violation more costly.
- Small ε + large C: nearly every point counts, and each is punished hard, so the model chases noise (overfitting).
- Large ε + small C: most errors are ignored, and the rest are cheap, so the model barely reacts to the data (underfitting).
A safe starting intuition: set ε to define 'close enough', then tune C for how hard the model fights for the points still outside. In practice, they interact (and so does gamma), so tune them together rather than one at a time.
5. Slack Variables and the SVR Objective
To penalize points outside the tube, SVR must measure how far outside they are. It uses two slack variables:
| Slack variable | Meaning |
|---|---|
| How far an observation exceeds the upper tube boundary | |
| How far an observation falls below the lower tube boundary |
Let's reuse the salary example:
- Prediction: $100,000
- Epsilon: $5,000
- Tube: $95,000–$105,000
Observation 1: Actual salary = $112,000
It is above the upper boundary:
Observation 2: Actual salary = $90,000
It is below the lower boundary:
Observation 3: Actual salary = $102,000
It is inside the tube:
5.1 The mathematical objective
For linear SVR, the optimization objective is:
| Term | What it encourages |
|---|---|
| ½‖w‖² | A simpler, flatter function |
| C × Σ(ξ_i + ξ_i*) | Smaller errors outside the epsilon tube |
C is the weight on the second term, so it decides which goal wins when they conflict:
- Small C: violations are cheap, so the model stays simple and accepts them.
- Large C: violations are expensive, so the model reshapes itself to reduce them.
This is why C changes the fitted function without ever changing the tube's width: epsilon sits inside the slack definition (it decides which points are penalized), while C sits outside (it decides how much they cost).
Note on scaling: slack is measured in target units, so C's effective strength depends on target scale as well as on ε.
You don't need to memorize the formula. Remember what the variables represent: they measure how far observations extend beyond the acceptable margin.
6. Support Vectors
Why is it called Support Vector Regression?
A vector is simply an observation represented by its feature values. With one feature, it might be [6.5]; with three features, it could be [6.5, 10, 3].
A support vector is an observation that helps determine the position and shape of the fitted regression function.

Figure 6: Observations near or outside the tube can influence the fitted function.
Look at the black-circled observations in the figure:
- Points inside the tube: Observations comfortably inside the tube generally do not influence the fitted function.
- Points on the tube boundaries: These can become support vectors because they help define the acceptable error margin.
- Points outside the tube: These can also become support vectors because they violate the acceptable error margin and contribute to the optimization penalty.
Notice that support vectors appear both above and below the regression function. They are not necessarily the observations with the largest prediction errors. What matters is their contribution to determining the fitted function.
Why are support vectors important?
Imagine removing an observation that lies comfortably inside the tube. The fitted function will generally remain unchanged.
However, removing a support vector can change the fitted function because that observation contributes to the model's optimization.
This is one of the key differences between Ordinary Least Squares (OLS) and SVR:
- OLS: Every observation contributes to the squared-error objective.
- SVR: The fitted function is determined by support vectors; observations comfortably inside the tube generally have no influence on it.
🔑 Key takeaway: Support vectors are the critical observations that help determine the fitted regression function. They typically lie on or outside the epsilon-tube boundaries, while observations comfortably inside the tube generally do not affect the model.
7. Linear vs. Non-Linear SVR
So far, we have used a straight line to make the ideas easier to understand. But real-world relationships are not always linear.
7.1 Why might we need a curve?
Consider this position-level salary dataset:
| Position level | Salary |
|---|---|
| 1 | $45,000 |
| 2 | $50,000 |
| 3 | $60,000 |
| 4 | $80,000 |
| 5 | $110,000 |
| 6 | $150,000 |
| 7 | $200,000 |
| 8 | $300,000 |
| 9 | $500,000 |
| 10 | $1,000,000 |
Salary rises slowly at first, then much faster. Levels 1 to 5 add about $65,000 in total, but level 9 to 10 adds $500,000. A straight line would even predict negative salaries at the lowest levels. We need a model that can learn a curved relationship.

Figure 7.1: straight-line fit (amber) vs. an illustrative non-linear fit (teal) on the ten levels.
To get the second kind of fit, SVR uses a kernel.
7.2 What Is a Kernel?
A kernel allows SVR to learn non-linear relationships. A helpful way to imagine it:
- Transform the data into a different (higher-dimensional) feature space where a linear relationship can represent the pattern.
- Fit a straight tube in that space.
- Map the result back to the original input space, where it appears curved.
The kernel trick lets the algorithm calculate the relationships it needs without explicitly building all the transformed features.
A kernel function is written as:
It measures a particular kind of similarity between two observations. (Strictly, a kernel must satisfy mathematical conditions that make the method valid, so it isn't just any similarity score.)
7.3 Common Kernels
| Kernel | Use case |
|---|---|
| Linear | Straight-line relationships |
| Polynomial | Curved relationships of a chosen degree |
| RBF (Radial Basis Function / Gaussian) | Flexible, smooth curves; the default in scikit-learn and the usual starting point |
| Sigmoid | Non-linear; used less often |
The RBF kernel is a common starting point for non-linear SVR, but it is not guaranteed to be the best choice for every dataset.
7.4 The RBF kernel and gamma (γ)
Its formula is:
Nearby points get a similarity close to 1; distant points get close to 0. Gamma controls how quickly one observation's influence fades with distance.
| Gamma | Each point's influence | Resulting curve | Risk |
|---|---|---|---|
| Small | Reaches far | Smooth, gentle | Underfitting |
| Large | Very local | Wiggly, hugs individual points | Overfitting |
scikit-learn's default is gamma='scale', which is 1 / (n_features × variance of X). With one standardized feature that equals 1.
7.5 Linear SVR vs. Non-Linear SVR at a Glance
| Linear SVR | Non-linear SVR (RBF) | |
|---|---|---|
| Code | SVR(kernel='linear') |
SVR(kernel='rbf') |
| Regression function | Straight line | Smooth curve |
| Tube | Straight | Follows the curve |
| ε, C, slack variables | Same | Same |
| Support vectors | Same idea | Same idea |
| Extra setting | None | γ (gamma) |
The tube, slack variables, epsilon, and C remain part of the SVR idea. The kernel changes the kind of relationship the model can represent.
8. Why Feature Scaling Matters
Feature scaling is especially important for SVR. To understand why, we need to look at two things:
- The distances used by kernels such as RBF.
- The target units used by epsilon and the error penalty.
8.1 What is feature scaling?
Feature scaling transforms numerical values so that their magnitudes are on comparable scales.
In our example:
- Position level ranges from 1 to 10.
- Salary ranges from $45,000 to $1,000,000.
Those values have very different magnitudes.
A common scaling method is standardization:
where:
- is the original value.
- is the mean.
- is the standard deviation.
After standardization, the data is centered around zero and measured in standard deviations.
8.2 Why scale X?
The RBF kernel uses distances:
If one feature has much larger numerical values than another, it can dominate the distance calculation.
Scaling input features helps prevent this and makes distances more meaningful.
8.3 Why consider scaling y?
Epsilon and the slack penalties are measured in target units. Scikit-learn's defaults are:
epsilon = 0.1
C = 1.0Against raw salaries:
- A tube half-width of 0.1 on a salary of $1,000,000 is a tolerance of ten cents. The tube is paper-thin.
- With C = 1, the model's coefficients are capped, so the function can only move a limited distance from its intercept. That is nowhere near enough to reach salaries in the hundreds of thousands, so the default RBF model typically returns a nearly flat curve that ignores the data. Linear Regression doesn't have this problem because its coefficients can grow as large as needed.
After standardizing y, the same epsilon of 0.1 is about $28,000, and C = 1 operates on a workable size.
Try it: fit
SVR(kernel='rbf')on the unscaled salaries and plot the result next to the scaled version. Seeing the flat curve is the best way to remember this.
Important distinction: scaling X is particularly important for distance-based kernels such as RBF. Scaling y is not mathematically mandatory, but it is usually necessary in practice when the target has a large range or the default epsilon is inappropriate.
8.4 Use separate scalers
X and y represent different quantities, so fit separate scalers:
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_y = StandardScaler()
X_scaled = sc_X.fit_transform(X)
y_scaled = sc_y.fit_transform(y.reshape(-1, 1))Each scaler learns the mean and standard deviation of the data passed to it. When predicting, remember the two-way mapping:
- Scale new inputs with
sc_X. - Convert predictions back to the original target units with
sc_y.
scaled_pred = model.predict(sc_X.transform([[6.5]]))
salary = sc_y.inverse_transform(
scaled_pred.reshape(-1, 1)
)8.5 Avoid data leakage
In a real machine learning workflow, split your dataset before fitting scalers.
The correct sequence is:
- Split the data into training and test sets.
- Fit each scaler using only the training data.
- Transform the training data.
- Transform the test data using those same fitted scalers.
- Train the model using the transformed training data.
- Evaluate it on the transformed test data.
Why? If you fit a scaler on the whole dataset first, information about the test set influences preprocessing. That is data leakage. For our tiny demonstration dataset, we use all rows to illustrate the algorithm, which does not tell us how well the model generalizes.
8.6 Quick recap of scaling rules
| Situation | Scale it? |
|---|---|
| One-hot dummy variables (0/1) | No, already a small range |
| Binary target (0/1) | No, already a small range |
| Target with huge values vs. features | Yes |
| Train/test split | Fit on the training set only, then apply to the test set |
9. Practical Implementation
Imagine you work in an HR department. You want to hire a candidate who previously worked at another company. The candidate says they were a Region Manager for 2 years (between level 6 and level 7 on our scale, so roughly level 6.5) and earned $160,000 per year, and they expect the same salary at your company.
Is that reasonable, or a bluff?
We'll use SVR to estimate what a level 6.5 position should pay and compare it with the claim.
9.1 Import Libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd| Library | Purpose |
|---|---|
| NumPy | Numerical operations and array manipulation |
| Matplotlib | Visualizing the regression results |
| Pandas | Creating and manipulating the dataset |
9.2 Create the Dataset
Our dataset has only ten observations, so we can create it directly using a Pandas DataFrame.
data = {
"Position": [
"Business Analyst",
"Junior Consultant",
"Senior Consultant",
"Manager",
"Country Manager",
"Region Manager",
"Partner",
"Senior Partner",
"C-level",
"CEO"
],
"Level": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"Salary": [
45000, 50000, 60000, 80000, 110000,
150000, 200000, 300000, 500000, 1000000
]
}
dataset = pd.DataFrame(data)
datasetRunning this displays:
| Position | Level | Salary |
|---|---|---|
| Business Analyst | 1 | 45000 |
| Junior Consultant | 2 | 50000 |
| Senior Consultant | 3 | 60000 |
| Manager | 4 | 80000 |
| Country Manager | 5 | 110000 |
| Region Manager | 6 | 150000 |
| Partner | 7 | 200000 |
| Senior Partner | 8 | 300000 |
| C-level | 9 | 500000 |
| CEO | 10 | 1000000 |
Why do we have both Position and Level?
Level is a numerical representation of each position. For this example, we use the level as the input feature and salary as the target. The text column Position is not needed by this model.
Our target level 6.5 sits between Region Manager (6, $150,000) and Partner (7, $200,000), which gives a rough range to sanity-check the prediction.
9.3 Create X and y
target_column = "Salary"
X = dataset.drop(columns=[target_column, "Position"]).values
y = dataset[target_column].values
print(X.shape) # (10, 1) — the Level column
print(y.shape) # (10,) — the Salary column9.4 Reshape y into a 2D Array
y = y.reshape(len(y), 1)
print(y.shape) # (10, 1)Why? StandardScaler().fit_transform() expects a 2D array; a 1D vector raises an error. len(y) is the number of rows and 1 the number of columns.
9.5 Feature Scaling (Both X and y)
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_y = StandardScaler()
X = sc_X.fit_transform(X)
y = sc_y.fit_transform(y)
print(X)
print(y)What to expect: X from about -1.57 (level 1) to +1.57 (level 10); y from about -0.72 (1M). Separate scalers are used because X and y have different distributions and units.
9.6 Build and Train the Model
from sklearn.svm import SVR
regressor = SVR(kernel="rbf")
regressor.fit(X, y.ravel())What is happening?
SVRimports the Support Vector Regression implementation.kernel="rbf"allows the model to learn a non-linear relationship.fit()trains the model using the scaled inputs and targets.y.ravel()converts the target from shape(10, 1)to(10,), whichSVR.fit()expects.- Defaults:
C=1.0,epsilon=0.1,gamma='scale'. Because y is standardized, epsilon is now in standardized salary units, not dollars.
9.7 Predict a new salary
Let's predict the salary for position level 6.5.
pred = regressor.predict(sc_X.transform([[6.5]]))
print(pred)Two things to notice:
- The input must be scaled with
sc_X.transform(...), because the model was trained on scaled data. Never usefit_transform()on new data, since that would calculate a different mean and standard deviation. - Double brackets
[[6.5]]→ a 2D array, whichpredictrequires.
The raw prediction is in scaled salary space, so it isn't useful yet.
9.8 Convert the prediction back to dollars
The model predicts in scaled target units. We need to inverse-transform the result to get a salary in dollars.
salary = sc_y.inverse_transform(pred.reshape(-1, 1))
print(salary)sc_y.inverse_transform(...) returns real dollars, and .reshape(-1, 1) avoids a format error since scikit-learn wants a 2D array.
Result: approximately $170,370 (re-run to confirm on your machine). That sits between Region Manager ($150,000) and Partner ($200,000), which is what we'd expect for level 6.5.
The candidate claims $160,000, about $10,000 (roughly 6%) below the model's estimate. So the claim is reasonable, not a bluff.
Keep in mind that this is an estimate from ten data points. Treat it as a sanity check, not proof.
🔑 Key rule: whenever the target was scaled, you must apply
inverse_transformto get predictions in original units.
9.9 Visualize the Results
# Scaled → original
X_orig = sc_X.inverse_transform(X)
y_orig = sc_y.inverse_transform(y.reshape(-1, 1))
# Predictions → original
y_pred = sc_y.inverse_transform(regressor.predict(X).reshape(-1, 1))
plt.scatter(X_orig, y_orig, color="red", label="Actual salaries")
plt.plot(X_orig, y_pred, color="blue", label="SVR prediction")
plt.title("Truth or Bluff (SVR)")
plt.xlabel("Position Level")
plt.ylabel("Salary")
plt.legend()
plt.show()Xandyare still scaled, so we inverse-transform both to plot them on their original axes.- The predictions are also inverse-transformed back to real salary values.
- Red dots = actual salaries. Blue line = SVR curve.
What you should see: The blue SVR curve follows the red points closely, except for the CEO point (level 10), which sits far above the curve. With the default C = 1, the model prefers a smooth function over bending sharply to reach one extreme point, so the CEO salary acts like an outlier. Try SVR(kernel="rbf", C=100) and watch the curve move toward it.
10. Common Confusions
| Question | Remember |
|---|---|
| Does epsilon control the penalty strength? | No. It controls the width of the acceptable error margin. |
| Does C change the tube width? | No. C changes the cost of errors outside the tube. |
| Are all observations support vectors? | No. Only observations that influence the fitted function are support vectors. |
| Are slack variables prediction errors? | They measure only the amount beyond the epsilon margin. |
| Does a kernel directly create new target values? | No. It helps the model represent relationships in a transformed feature space. |
| Must y always be scaled? | No, but scaling it is often useful because epsilon and the slack penalties depend on target units. |
| Should a new input be fit-scaled again? | No. Use the scaler already fitted on the training data. |
11. Quick Recap: Concepts to Remember
| Concept | Explanation |
|---|---|
| SVR | A regression algorithm based on the Support Vector Machine framework |
| Epsilon () | Half-width of the tolerance tube |
| Epsilon-insensitive tube | Region where prediction errors are not penalized |
| Controls the penalty strength for errors outside the tube | |
| Support vectors | Observations that influence the fitted function |
| Slack variables | Measure how far observations extend beyond the tube |
| Kernel | Allows the model to represent different kinds of relationships |
| RBF kernel | A common choice for flexible non-linear relationships |
| Feature scaling | Important for distance-based kernels such as RBF |
| Target scaling | Often useful because epsilon and slack penalties use target units |
transform() |
Applies an already-fitted scaler to new data |
inverse_transform() |
Converts scaled values back to their original units |
ravel() |
Flattens a 2D target array into the 1D shape expected by SVR.fit() |
12. Check Your Understanding
Try answering these questions without looking back at the tutorial.
- What problem is SVR designed to solve?
- How does SVR treat prediction errors differently from ordinary Linear Regression?
- If epsilon increases, what happens to the tolerance tube?
- If C increases while epsilon stays the same, what changes?
- Why are slack variables needed?
- What makes an observation a support vector?
- Why might we choose an RBF kernel instead of a linear kernel?
- Why is scaling X important for an RBF kernel?
- Why is scaling y usually necessary for SVR in practice?
- Why must we use the training scaler to transform a new observation?
- Why do we inverse-transform the model's prediction?
- Why isn't evaluating on the training data enough?
Answers
- Predicting continuous numerical values.
- Linear Regression minimizes squared residuals, so every point contributes. SVR ignores errors inside its epsilon margin and penalizes only the amount outside it.
- The tube becomes wider, so more observations may fall inside it.
- The penalty for violations gets stronger; the tube width does not change.
- They quantify how far observations lie beyond the tube.
- It lies on or outside the tube and helps determine the fitted function. (Points strictly inside generally don't.)
- An RBF kernel can represent non-linear relationships.
- RBF uses distances, so features with large numerical scales can dominate those distances.
- Epsilon and the slack penalties are measured in target units, so scaling can make their values easier to work with.
- The model was trained using the transformation learned from the training data.
- The model's output is in scaled target units, and inverse transformation returns it to the original units.
- It measures performance on data the model has already seen, so it does not tell us reliably how well the model generalizes.
13. Final Takeaway
The central difference between Linear Regression and Support Vector Regression is how they handle prediction errors:
- Linear Regression minimizes the sum of squared residuals, so every observation contributes to the objective.
- SVR allows errors inside an acceptable margin and penalizes only the amount by which observations fall outside that margin, while controlling model complexity.
Remember these ideas:
- Epsilon defines what counts as close enough.
- C controls how strongly the model penalizes errors outside that margin.
- Kernels such as RBF (with gamma) let SVR represent non-linear relationships.
- Scale X and y with separate scalers, and inverse-transform predictions.
In practice, avoid data leakage, tune ε, C, and gamma together, and evaluate on data the model didn't train on.
Next topic: Kernel SVM and the Kernel Trick, the idea that lets kernel-based models represent complex relationships without explicitly constructing every transformed feature.