# LinearSVC

### *class* cuml.svm.LinearSVC(, penalty='l2', loss='squared_hinge', C=1.0, fit_intercept=True, penalized_intercept=False, class_weight=None, tol=0.0001, max_iter=1000, linesearch_max_iter=100, lbfgs_memory=5, n_streams=1, multi_class='ovr', verbose=False, output_type=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/svm/linear_svc.py#L19)

Linear Support Vector Classification.

Similar to SVC with parameter kernel=’linear’, but implemented using a
linear solver. This enables flexibility in penalties and loss functions,
and can scale better for larger problems.

* **Parameters:**
  **penalty**
  : The norm used in the penalization.

  **loss**
  : The loss function.

  **C**
  : Regularization parameter. The strength of the regularization is
    inversely proportional to C. Must be strictly positive.

  **fit_intercept**
  : Whether to fit the bias term. Set to False if you expect that the
    data is already centered.

  **penalized_intercept**
  : When true, the bias term is treated the same way as other features;
    i.e. it’s penalized by the regularization term of the target function.
    Enabling this feature forces an extra copying the input data X.

  **class_weight**
  : Weights to modify the parameter C for class i to `class_weight[i]*C`.
    The string ‘balanced’ is also accepted, in which case
    `class_weight[i] = n_samples / (n_classes * n_samples_of_class[i])`

  **tol**
  : Tolerance for the stopping criterion.

  **max_iter**
  : Maximum number of iterations for the underlying solver.

  **linesearch_max_iter**
  : Maximum number of linesearch (inner loop) iterations for
    the underlying (QN) solver.

  **lbfgs_memory**
  : Number of vectors approximating the hessian for the underlying QN
    solver (l-bfgs).

  **n_streams**
  : Number of parallel streams used for fitting.

  **multi_class**
  : Multiclass classification strategy. Currently only ‘ovr’ is supported.

  **verbose**
  : Sets logging level. It must be one of `cuml.common.logger.level_*`.
    See [Verbosity Levels](../../cuml/index.html.md#verbosity-levels) for more info.

  **output_type**
  : Return results and set estimator attributes to the indicated output
    type. If None, the output type set at the module level
    (`cuml.global_settings.output_type`) will be used. See
    [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration) for more info.
* **Attributes:**
  **coef_**
  : Weights assigned to the features (coefficients in the primal problem).

  **intercept_**
  : The constant factor in the decision function. If
    `fit_intercept=False` this is instead a float with value 0.0.

  **classes_**
  : A sorted array of the class labels.

  **n_iter_**
  : The maximum number of iterations run across all classes during the fit.

### Methods

| [`fit`](#cuml.svm.LinearSVC.fit)(X, y[, sample_weight])   | Fit the model according to the given training data.   |
|-------------------------------------------------------------------------------|-------------------------------------------------------|
| [`predict`](#cuml.svm.LinearSVC.predict)(X)                   | Predict class labels for samples in X.                |

### Notes

The model uses the quasi-newton (QN) solver to find the solution in the
primal space. Thus, in contrast to generic [`SVC`](../cuml.svm.SVC/index.html.md#cuml.svm.SVC)
model, it does not compute the support coefficients/vectors.

Check the solver’s documentation for more details
`Quasi-Newton (L-BFGS/OWL-QN)`.

For additional docs, see [scikitlearn’s LinearSVC](https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC.html).

### Examples

```pycon
>>> import cupy as cp
>>> from cuml.svm import LinearSVC
>>> X = cp.array([[1,1], [2,1], [1,2], [2,2], [1,3], [2,3]],
...              dtype=cp.float32);
>>> y = cp.array([0, 0, 1, 0, 1, 1], dtype=cp.float32)
>>> clf = LinearSVC(penalty='l1', C=1).fit(X, y)
>>> print("Predicted labels:", clf.predict(X))
Predicted labels: [0 0 1 0 1 1]
```

<!-- !! processed by numpydoc !! -->

#### as_sklearn()[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/interop.py#L206)

Convert this estimator into an equivalent scikit-learn (or scikit-learn
extension) estimator.

* **Returns:**
  sklearn.base.BaseEstimator
  : A scikit-learn compatible estimator instance that mirrors the trained
    state of the current estimator.

<!-- !! processed by numpydoc !! -->

#### decision_function(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/linear_model/base.py#L43)

Predict confidence scores for samples.

* **Parameters:**
  **X**
  : Dense or sparse matrix with dtype float32 or float64.
    Acceptable dense formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **scores**
  : Confidence scores
    <br/>
    For more information on how to configure cuML’s output type,
    refer to: [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration).

<!-- !! processed by numpydoc !! -->

#### fit(X, y, sample_weight=None) → [LinearSVC](#cuml.svm.LinearSVC)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/svm/linear_svc.py#L222)

Fit the model according to the given training data.

* **Parameters:**
  **X**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **y**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **sample_weight**
  : The weights for each observation in X. If None, all observations
    are assigned equal weight.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

<!-- !! processed by numpydoc !! -->

#### *classmethod* from_sklearn(model)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/interop.py#L222)

Create a cuml estimator from a scikit-learn estimator.

* **Parameters:**
  **model**
  : A compatible scikit-learn (or scikit-learn extension) estimator.
* **Returns:**
  cls
  : A new instance of this cuml estimator class that mirrors the
    state of the input estimator.

### Notes

`output_type` of the estimator is set to “numpy” by default, as these
cannot be inferred from training arguments. If something different is
required, then please use cuml’s output_type configuration utilities.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L191)

Returns a dict of all params owned by this class. If the child class
has appropriately overridden the `_get_param_names` method and does not
need anything other than what is there in this method, then it doesn’t
have to override this method

<!-- !! processed by numpydoc !! -->

#### predict(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/svm/linear_svc.py#L265)

Predict class labels for samples in X.

* **Parameters:**
  **X**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **y_pred**
  : Predicted class labels.
    <br/>
    For more information on how to configure cuML’s output type,
    refer to: [Output Data Type Configuration](../../cuml/index.html.md#output-data-type-configuration).

<!-- !! processed by numpydoc !! -->

#### score(X, y, sample_weight=None, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/mixins.py#L101)

Scoring function for classifier estimators based on mean accuracy.

* **Parameters:**
  **X**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **y**
  : Dense matrix with dtype float32 or float64.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.

  **sample_weight**
  : The weights for each observation in X. If None, all observations
    are assigned equal weight.
    Acceptable formats: CUDA array interface compliant objects like
    CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas
    DataFrame/Series.
* **Returns:**
  **score**
  : Accuracy of self.predict(X) wrt. y (fraction where y == pred_y)

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/internals/base.py#L200)

Accepts a dict of params and updates the corresponding ones owned by
this class. If the child class has appropriately overridden the
`_get_param_names` method and does not need anything other than what is,
there in this method, then it doesn’t have to override this method

<!-- !! processed by numpydoc !! -->
