SKLearner Home | About | Contact | Examples

Configure SVC "coef0" Parameter

The coef0 parameter in scikit-learn’s SVC class controls the independent term in the kernel function for polynomial and sigmoid kernels.

Support Vector Machines (SVMs) are powerful classification algorithms that can handle complex non-linear decision boundaries by using kernel functions to transform the input space.

The coef0 parameter is used with the polynomial (poly) and sigmoid (sigmoid) kernels. It represents the trade-off between the influence of higher-order versus lower-order terms in the polynomial.

The default value for coef0 is 0.0.

In practice, values between 0.0 and 1.0 are commonly used, with higher values giving more weight to higher-order polynomial terms.

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score

# Generate synthetic dataset
X, y = make_classification(n_samples=1000, n_features=10, n_informative=5,
                           n_redundant=0, n_clusters_per_class=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 coef0 values
coef0_values = [0.0, 0.5, 1.0]
accuracies = []

for coef0 in coef0_values:
    svc = SVC(kernel='poly', degree=3, coef0=coef0, random_state=42)
    svc.fit(X_train, y_train)
    y_pred = svc.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred)
    accuracies.append(accuracy)
    print(f"coef0={coef0}, Accuracy: {accuracy:.3f}")

Running the example gives an output like:

coef0=0.0, Accuracy: 0.970
coef0=0.5, Accuracy: 0.970
coef0=1.0, Accuracy: 0.980

The key steps in this example are:

  1. Generate a synthetic binary classification dataset with informative features and non-linearly separable classes
  2. Split the data into train and test sets
  3. Train SVC models with polynomial kernel and different coef0 values
  4. Evaluate the accuracy of each model on the test set

Some tips and heuristics for setting coef0:

Issues to consider:



See Also