Implementation:Rapidsai Cuml SVC API
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Support_Vector_Machines |
| Last Updated | 2026-02-08 12:00 GMT |
Overview
Provides the GPU-accelerated C-Support Vector Classification (SVC) API in cuML, supporting both dense and sparse inputs with configurable kernel functions, using the Sequential Minimal Optimization (SMO) algorithm.
Description
The svc.hpp header declares the full SVC API in the ML::SVM namespace, offering both a stateless functional API and a stateful class-based wrapper:
Stateless API:
svcFit: Fits an SVM classifier on dense column-major input data using the SMO algorithm. Returns the number of iterations and populates anSvmModelwith support vectors, dual coefficients, and bias.svcFitSparse: Fits an SVM classifier on sparse CSR-format input data.svcPredict: Predicts class labels or decision function values for dense input using a trained model.svcPredictSparse: Predicts for sparse CSR-format input.svmFreeBuffers: Deallocates device memory owned by theSvmModelstruct.
Stateful Class (SVC):
The SVC template class provides a scikit-learn-like interface wrapping the stateless API. It maintains the kernel parameters, SVM parameters, and trained model state internally. Methods include:
fit: Fits the classifier with optional sample weights.predict: Predicts class labels.decisionFunction: Returns raw decision function values.
The constructor accepts penalty C, tolerance, kernel parameters (LINEAR, POLYNOMIAL, RBF, or TANH), cache size, maximum iterations, and convergence settings.
Usage
Use the SVC API for binary or multiclass classification tasks where kernel-based SVMs are appropriate. Choose the stateful SVC class for a convenient scikit-learn-like workflow, or the stateless functions for more control. Use sparse variants when input data is in CSR format. This is the kernel SVM implementation; for linear-only SVMs, the linear.hpp API with its L-BFGS optimizer is more efficient.
Code Reference
Source Location
- Repository: Rapidsai_Cuml
- File:
cpp/include/cuml/svm/svc.hpp
Signature
namespace ML {
namespace SVM {
template <typename math_t>
int svcFit(const raft::handle_t& handle,
math_t* input, int n_rows, int n_cols, math_t* labels,
const SvmParameter& param,
ML::matrix::KernelParams& kernel_params,
SvmModel<math_t>& model,
const math_t* sample_weight);
template <typename math_t>
int svcFitSparse(const raft::handle_t& handle,
int* indptr, int* indices, math_t* data,
int n_rows, int n_cols, int nnz, math_t* labels,
const SvmParameter& param,
ML::matrix::KernelParams& kernel_params,
SvmModel<math_t>& model,
const math_t* sample_weight);
template <typename math_t>
void svcPredict(const raft::handle_t& handle,
math_t* input, int n_rows, int n_cols,
ML::matrix::KernelParams& kernel_params,
const SvmModel<math_t>& model,
math_t* preds, math_t buffer_size, bool predict_class);
template <typename math_t>
void svcPredictSparse(const raft::handle_t& handle,
int* indptr, int* indices, math_t* data,
int n_rows, int n_cols, int nnz,
ML::matrix::KernelParams& kernel_params,
const SvmModel<math_t>& model,
math_t* preds, math_t buffer_size, bool predict_class);
template <typename math_t>
void svmFreeBuffers(const raft::handle_t& handle, SvmModel<math_t>& m);
template <typename math_t>
class SVC {
public:
ML::matrix::KernelParams kernel_params;
SvmParameter param;
SvmModel<math_t> model;
SVC(raft::handle_t& handle, math_t C = 1, math_t tol = 1.0e-3,
ML::matrix::KernelParams kernel_params = {ML::matrix::KernelType::LINEAR, 3, 1, 0},
math_t cache_size = 200, int max_iter = -1, int nochange_steps = 1000,
rapids_logger::level_enum verbosity = rapids_logger::level_enum::info);
~SVC();
void fit(math_t* input, int n_rows, int n_cols, math_t* labels,
const math_t* sample_weight = nullptr);
void predict(math_t* input, int n_rows, int n_cols, math_t* preds);
void decisionFunction(math_t* input, int n_rows, int n_cols, math_t* preds);
};
} // namespace SVM
} // namespace ML
Import
#include <cuml/svm/svc.hpp>
I/O Contract
Inputs
svcFit (dense)
| Name | Type | Required | Description |
|---|---|---|---|
| handle | const raft::handle_t& | Yes | cuML handle |
| input | math_t* | Yes | Device pointer to input data in column-major format [n_rows x n_cols] |
| n_rows | int | Yes | Number of training samples |
| n_cols | int | Yes | Number of features |
| labels | math_t* | Yes | Device pointer to class labels [n_rows] |
| param | const SvmParameter& | Yes | SVM training parameters (C, tol, max_iter, etc.) |
| kernel_params | ML::matrix::KernelParams& | Yes | Kernel type and parameters (LINEAR, POLYNOMIAL, RBF, TANH) |
| sample_weight | const math_t* | No | Optional device pointer to sample weights [n_rows] |
svcPredict
| Name | Type | Required | Description |
|---|---|---|---|
| handle | const raft::handle_t& | Yes | cuML handle |
| input | math_t* | Yes | Device pointer to input data [n_rows x n_cols] |
| n_rows | int | Yes | Number of samples |
| n_cols | int | Yes | Number of features |
| kernel_params | ML::matrix::KernelParams& | Yes | Kernel parameters |
| model | const SvmModel<math_t>& | Yes | Trained SVM model |
| buffer_size | math_t | Yes | Temporary buffer size in MiB |
| predict_class | bool | Yes | True to predict class labels, false for decision function values |
Outputs
| Name | Type | Description |
|---|---|---|
| model (fit) | SvmModel<math_t>& | Trained model with support vectors, dual coefficients, and bias |
| return value (fit) | int | Number of solver iterations |
| preds (predict) | math_t* | Device array of predictions [n_rows] |
Usage Examples
#include <cuml/svm/svc.hpp>
raft::handle_t handle;
// Using the stateful SVC class
ML::SVM::SVC<float> svc(handle,
1.0f, // C
1e-3f, // tol
{ML::matrix::KernelType::RBF, 3, 0.1f, 0.0f},
200.0f, // cache_size
-1, // max_iter (unlimited)
1000); // nochange_steps
// Fit
float* d_X; // device [n_rows x n_cols], column-major
float* d_labels; // device [n_rows]
int n_rows = 5000;
int n_cols = 100;
svc.fit(d_X, n_rows, n_cols, d_labels);
// Predict
float* d_preds; // device [n_rows]
svc.predict(d_X, n_rows, n_cols, d_preds);
// Or get decision function values
svc.decisionFunction(d_X, n_rows, n_cols, d_preds);