Large sparse classification
Classify text or other high-dimensional sparse feature vectors.
Scikit-Learn · Class
LinearSVC is a linear support-vector classifier implemented with liblinear. It supports dense and sparse inputs, flexible penalties and losses, and one-vs-the-rest multiclass classification.
LinearSVC learns a linear decision boundary for classification using liblinear. It supports dense or sparse data and handles multiple classes with one-vs-the-rest training.
class sklearn.svm.LinearSVC(*, penalty='l2', loss='squared_hinge', dual='auto', tol=0.0001, C=1.0, multi_class='ovr', fit_intercept=True, intercept_scaling=1, class_weight=None, verbose=0, random_state=None, max_iter=1000)| Name | Type | Description |
|---|---|---|
penalty | str, default='l2' | Selects the penalty type: 'l1' or 'l2'. |
loss | str, default='squared_hinge' | Chooses 'hinge' or 'squared_hinge' loss. |
dual | bool or 'auto', default='auto' | Whether to solve the dual optimization problem; 'auto' chooses automatically. |
tol | float, default=1e-4 | Tolerance for stopping criterion. |
C | float, default=1.0 | Regularization parameter; smaller values mean stronger regularization. |
multi_class | str, default='ovr' | Multiclass strategy: 'ovr' or 'crammer_singer'. |
fit_intercept | bool, default=True | Whether to fit the intercept. |
intercept_scaling | float, default=1 | Scaling applied to the synthetic intercept feature. |
class_weight | dict, 'balanced', or None, default=None | Class weights, or 'balanced' to derive them from class frequencies. |
verbose | int, default=0 | Verbosity level. |
random_state | int, RandomState instance, or None, default=None | Seed controlling solver randomness. |
max_iter | int, default=1000 | Maximum number of solver iterations. |
A fitted LinearSVC estimator with learned coefficients and intercept; prediction methods return class labels or decision scores.
from sklearn.svm import LinearSVC
X = [[0, 0], [1, 1], [1, 0], [0, 1]]
y = [0, 0, 1, 1]
model = LinearSVC(random_state=0, max_iter=10_000)
model.fit(X, y)
print(model.predict([[0.9, 0.1]]))Creates a linear classifier, fits it to labeled samples, and predicts a class for a new sample.
Classify text or other high-dimensional sparse feature vectors.
Obtain a compact model with fewer active feature weights.
Train a linear classifier across several target categories.
LinearSVC is a linear support-vector classifier implemented with liblinear. Compared with SVC using a linear kernel, it offers different penalty and loss choices and is intended to scale better to many samples.
Follow-up: How are multiclass problems handled? The estimator trains one classifier per class in a one-vs-the-rest scheme.
C controls the regularization strength inversely: smaller values apply stronger regularization, while larger values allow the model to fit the training data more closely. The default is 1.0.
Follow-up: What does class_weight do? It changes the weight of classes in the objective; balanced weighting derives weights from class frequencies.
The estimator exposes coef_ for the learned feature weights and intercept_ for the intercept. decision_function returns confidence scores, while predict maps samples to class labels.
Follow-up: What is a useful sparse-model configuration? Select penalty='l1' with a compatible loss to obtain sparse coefficient vectors.
sklearn.svm.SVCsklearn.linear_model.LogisticRegressionsklearn.svm.NuSVC