Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn BaseSVC

From Leeroopedia


Knowledge Sources
Domains Machine Learning, Support Vector Machines
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for providing the base class infrastructure for all libsvm-based support vector machine estimators provided by scikit-learn.

Description

BaseSVC and BaseLibSVM are the abstract base classes for SVM classification and regression estimators in scikit-learn. BaseLibSVM wraps the libsvm library and provides the core fitting and prediction machinery including kernel computation, support vector extraction, and sparse data handling. BaseSVC extends it with classification-specific functionality including decision function shapes (one-vs-rest, one-vs-one), class weight handling, and probability calibration via Platt scaling. The module also provides utility functions for liblinear-based SVMs.

Usage

Use BaseSVC and BaseLibSVM as foundation classes when understanding the SVM implementation architecture. End users should use the concrete subclasses such as SVC, NuSVC, SVR, or LinearSVC instead of instantiating these base classes directly.

Code Reference

Source Location

Signature

class BaseLibSVM(BaseEstimator, metaclass=ABCMeta):
    def __init__(
        self,
        kernel,
        degree,
        gamma,
        coef0,
        tol,
        C,
        nu,
        epsilon,
        shrinking,
        probability,
        cache_size,
        class_weight,
        verbose,
        max_iter,
        random_state,
    ):

class BaseSVC(ClassifierMixin, BaseLibSVM, metaclass=ABCMeta):
    def __init__(
        self,
        kernel,
        degree,
        gamma,
        coef0,
        tol,
        C,
        nu,
        shrinking,
        probability,
        cache_size,
        class_weight,
        verbose,
        max_iter,
        decision_function_shape,
        random_state,
        break_ties,
    ):

Import

from sklearn.svm._base import BaseLibSVM, BaseSVC

I/O Contract

Inputs

Name Type Required Description
kernel str or callable Yes Kernel type: 'linear', 'poly', 'rbf', 'sigmoid', 'precomputed', or callable
degree int Yes Degree of the polynomial kernel function
gamma str or float Yes Kernel coefficient for 'rbf', 'poly', and 'sigmoid'
coef0 float Yes Independent term in kernel function
tol float Yes Tolerance for stopping criterion
C float Yes Regularization parameter
nu float Yes Upper bound on training errors fraction (for Nu-SVM variants)
shrinking bool Yes Whether to use the shrinking heuristic
probability bool Yes Whether to enable probability estimates
cache_size float Yes Size of the kernel cache in MB
class_weight dict or str or None Yes Weights associated with classes
verbose bool Yes Enable verbose output
max_iter int Yes Maximum number of iterations (-1 for no limit)
decision_function_shape str Yes Decision function shape: 'ovr' or 'ovo' (BaseSVC only)
random_state int, RandomState, or None Yes Random state for probability estimation
break_ties bool Yes Whether to break ties according to decision_function values (BaseSVC only)

Outputs

Name Type Description
support_ ndarray Indices of support vectors
support_vectors_ ndarray Support vectors
n_support_ ndarray Number of support vectors for each class
dual_coef_ ndarray Dual coefficients of support vectors in the decision function
coef_ ndarray Weights assigned to features (linear kernel only)
intercept_ ndarray Constants in the decision function
fit_status_ int 0 if correctly fitted, 1 otherwise
classes_ ndarray Unique class labels (BaseSVC)
n_features_in_ int Number of features seen during fit

Usage Examples

Basic Usage

from sklearn.svm import SVC
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

# BaseSVC is abstract; use SVC directly
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

clf = SVC(kernel="rbf", C=1.0, gamma="scale")
clf.fit(X_train, y_train)
print(f"Accuracy: {clf.score(X_test, y_test):.3f}")
print(f"Support vectors: {clf.n_support_}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment