# SVC

### *class* cuml.svm.SVC(C-Support Vector Classification)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/svm/svc.py#L18)

Construct an SVC classifier for training and predictions.

* **Parameters:**
  **C**
  : Penalty parameter C

  **kernel**
  : Specifies the kernel function. Possible options: ‘linear’, ‘poly’,
    ‘rbf’, ‘sigmoid’, ‘precomputed’. When using ‘precomputed’, X is
    expected to be a precomputed kernel matrix of shape
    (n_samples, n_samples) at fit time, and (n_samples_test,
    n_samples_train) at predict time. A valid kernel matrix should be
    symmetric and positive semi-definite; cuML does not validate these
    properties.

  **degree**
  : Degree of polynomial kernel function.

  **gamma**
  : Coefficient for rbf, poly, and sigmoid kernels. You can specify the
    numeric value, or use one of the following options:
    - ‘auto’: gamma will be set to `1 / n_features`
    - ‘scale’: gamma will be se to `1 / (n_features * X.var())`

  **coef0**
  : Independent term in kernel function, only significant for poly and
    sigmoid

  **tol**
  : Tolerance for stopping criterion.

  **cache_size**
  : Size of the kernel cache during training in MiB. Increase it to improve
    the training time, at the cost of higher memory footprint. After
    training the kernel cache is deallocated.
    During prediction, we also need a temporary space to store kernel
    matrix elements (this can be significant if n_support is large).
    The cache_size variable sets an upper limit to the prediction
    buffer as well.

  **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])`

  **max_iter**
  : Limit the number of total iterations in the solver. Default of -1 for
    “no limit”.

  **decision_function_shape**
  : Multiclass classification strategy. `'ovo'` uses [OneVsOneClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsOneClassifier.html)
    while `'ovr'` selects [OneVsRestClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html)

  **nochange_steps**
  : We monitor how much our stopping criteria changes during outer
    iterations. If it does not change (changes less then 1e-3\*tol)
    for nochange_steps consecutive steps, then we stop training.

  **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.

  **random_state: int (default = None)**
  : Seed for random number generator (used only when `probability=True`).

  **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.
* **Attributes:**
  **n_support_**
  : The total number of support vectors. Note: this will change in the
    future to represent number support vectors for each class (like
    in Sklearn, see [https://github.com/NVIDIA/cuml/issues/956](https://github.com/NVIDIA/cuml/issues/956) )

  **support_**
  : Device array of support vector indices

  **support_vectors_**
  : Device array of support vectors. For kernel=’precomputed’, this
    attribute is empty (shape (0, 0)) since the original feature vectors
    are not available.

  **dual_coef_**
  : Device array of coefficients for support vectors

  **intercept_**
  : The constant in the decision function

  **fit_status_**
  : 0 if SVM is correctly fitted

  **n_iter_**
  : Number of outer iterations run by the solver for each model fit.

  [`coef_`](#cuml.svm.SVC.coef_)
  : SVMBase.coef_(self)

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

  **class_weight_**
  : Class weight multipliers, computed based on the `class_weight`
    parameter.

  **n_classes_**
  : Number of classes

### Methods

| [`decision_function`](#cuml.svm.SVC.decision_function)(X)       | Calculates the decision function values for X.   |
|-----------------------------------------------------------------------------|--------------------------------------------------|
| [`fit`](#cuml.svm.SVC.fit)(X, y[, sample_weight]) | Fit the model with X and y.                      |
| [`predict`](#cuml.svm.SVC.predict)(X)                 | Predicts the class labels for X.                 |

### Notes

The solver uses the SMO method to fit the classifier. We use the Optimized
Hierarchical Decomposition [[1]](#r93eb4b3677ac-1) variant of the SMO algorithm, similar to
[[2]](#r93eb4b3677ac-2).

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

### References

### Examples

```python
>>> import cupy as cp
>>> from cuml.svm import SVC
>>> X = cp.array([[1,1], [2,1], [1,2], [2,2], [1,3], [2,3]],
...              dtype=cp.float32);
>>> y = cp.array([-1, -1, 1, -1, 1, 1], dtype=cp.float32)
>>> clf = SVC(kernel='poly', degree=2, gamma='auto', C=1)
>>> clf.fit(X, y)
SVC(C=1, degree=2, gamma='auto', kernel='poly')
>>> print("Predicted labels:", clf.predict(X))
Predicted labels: [-1. -1.  1. -1.  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 !! -->

#### *property* coef_

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

#### decision_function(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/svm/svc.py#L422)

Calculates the decision function values for X.

For precomputed kernels, X should be a kernel matrix of shape
(n_samples_test, n_samples_train) where n_samples_train is the
number of samples used during fit.

* **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:**
  **results**
  : Decision function values
    <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) → [SVC](#cuml.svm.SVC)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/svm/svc.py#L341)

Fit the model with X and y.

* **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 any dtype.
    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 !! -->

#### *property* intercept_

A descriptor for enabling `output_type` reflection on an attribute.

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

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

Predicts the class labels for X. The returned y values are the class
labels associated to sign(decision_function(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:**
  **preds**
  : Predicted values
    <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 !! -->

#### *property* support_

A descriptor for enabling `output_type` reflection on an attribute.

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