This documentation is for scikit-learn version 0.10Other versions

Citing

If you use the software, please consider citing scikit-learn.

This page

8.24.2.6. sklearn.svm.sparse.LinearSVC

class sklearn.svm.sparse.LinearSVC(penalty='l2', loss='l2', dual=True, tol=0.0001, C=1.0, multi_class=False, fit_intercept=True, intercept_scaling=1, scale_C=False)

Linear Support Vector Classification, Sparse Version

Similar to SVC with parameter kernel=’linear’, but uses internally liblinear rather than libsvm, so it has more flexibility in the choice of penalties and loss functions and should be faster for huge datasets.

See sklearn.svm.SVC for a complete list of parameters

Notes

For best results, this accepts a matrix in csr format (scipy.sparse.csr), but should be able to convert from any array-like object (including other sparse representations).

Methods

decision_function(X) Return the decision function of X according to the trained
fit(X, y[, class_weight]) Fit the model using X, y as training data.
fit_transform(X[, y]) Fit to data, then transform it
predict(X) Predict target values of X according to the fitted model.
score(X, y) Returns the mean accuracy on the given test data and labels.
set_params(**params) Set the parameters of the estimator.
transform(X[, threshold])
__init__(penalty='l2', loss='l2', dual=True, tol=0.0001, C=1.0, multi_class=False, fit_intercept=True, intercept_scaling=1, scale_C=False)
decision_function(X)

Return the decision function of X according to the trained model.

Parameters :

X : sparse matrix, shape = [n_samples, n_features]

Returns :

T : array-like, shape = [n_samples, n_class]

Returns the decision function of the sample for each class in the model.

fit(X, y, class_weight=None)

Fit the model using X, y as training data.

Parameters :

X : sparse matrix, shape = [n_samples, n_features]

Training vector, where n_samples in the number of samples and n_features is the number of features.

y : array, shape = [n_samples]

Target vector relative to X

Returns :

self : object

Returns an instance of self.

fit_transform(X, y=None, **fit_params)

Fit to data, then transform it

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.

Parameters :

X : numpy array of shape [n_samples, n_features]

Training set.

y : numpy array of shape [n_samples]

Target values.

Returns :

X_new : numpy array of shape [n_samples, n_features_new]

Transformed array.

Notes

This method just calls fit and transform consecutively, i.e., it is not an optimized implementation of fit_transform, unlike other transformers such as PCA.

predict(X)

Predict target values of X according to the fitted model.

Parameters :X : sparse matrix, shape = [n_samples, n_features]
Returns :C : array, shape = [n_samples]
score(X, y)

Returns the mean accuracy on the given test data and labels.

Parameters :

X : array-like, shape = [n_samples, n_features]

Training set.

y : array-like, shape = [n_samples]

Labels for X.

Returns :

z : float

set_params(**params)

Set the parameters of the estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns :self :