SKLearner Home | About | Contact | Examples

Configure SVR "tol" Parameter

The tol parameter in scikit-learn’s SVR class controls the tolerance for the optimization convergence.

Support Vector Regression (SVR) is a regression algorithm that tries to find a function that approximates the training data with a given tolerance. The tol parameter determines the tolerance on the optimization process.

A smaller tol leads to tighter convergence criteria and potentially longer training times. Conversely, a larger tol allows for looser approximations and faster training.

The default value for tol is 0.001.

In practice, values between 0.0001 and 0.01 are commonly used depending on the desired precision and computational resources available.

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.svm import SVR
from sklearn.metrics import mean_squared_error

# Generate synthetic dataset
X, y = make_regression(n_samples=1000, n_features=10, noise=0.1, random_state=42)

# Split into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Train with different tol values
tol_values = [0.1, 0.01, 0.001, 0.0001]
mse_scores = []

for tol in tol_values:
    svr = SVR(tol=tol)
    svr.fit(X_train, y_train)
    y_pred = svr.predict(X_test)
    mse = mean_squared_error(y_test, y_pred)
    mse_scores.append(mse)
    print(f"tol={tol}, MSE: {mse:.3f}")

Running the example gives an output like:

tol=0.1, MSE: 12758.146
tol=0.01, MSE: 12758.146
tol=0.001, MSE: 12758.146
tol=0.0001, MSE: 12758.146

The key steps in this example are:

  1. Generate a synthetic regression dataset with noise
  2. Split the data into train and test sets
  3. Train SVR models with different tol values
  4. Evaluate the mean squared error (MSE) of each model on the test set

Some tips and heuristics for setting tol:

Issues to consider:



See Also