Implementation:Rapidsai Cuml SVR API
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Support_Vector_Machines |
| Last Updated | 2026-02-08 12:00 GMT |
Overview
Provides the GPU-accelerated Support Vector Regression (SVR) API in cuML, supporting both dense and sparse CSR inputs for fitting epsilon-insensitive regression models with configurable kernel functions.
Description
The svr.hpp header declares the SVR fitting functions in the ML::SVM namespace. SVR uses the same underlying SMO solver as SVC but with an epsilon-insensitive loss function suitable for regression tasks.
Two templated functions are provided:
svrFit(dense): Fits a support vector regressor on dense column-major input data. Each row is a feature vector. The function accepts SVM training parameters (including epsilon for the insensitive tube), kernel parameters, and optional sample weights. It populates anSvmModelwith the trained support vectors, dual coefficients, and bias, and returns the number of solver iterations.
svrFitSparse(sparse): Fits a support vector regressor on sparse CSR-format input data, with the same parameter set plus CSR components (indptr, indices, data, nnz).
For prediction, the svcPredict function from svc.hpp is reused, as the prediction logic is identical between classification and regression (the difference is only in how labels are interpreted).
Usage
Use SVR when performing regression tasks with SVM-style epsilon-insensitive loss. Choose between dense and sparse input variants depending on the data format. SVR is particularly effective when the relationship between features and targets is non-linear and can be captured by kernel functions (RBF, polynomial, etc.). For linear-only regression, consider the linear SVM API for better performance.
Code Reference
Source Location
- Repository: Rapidsai_Cuml
- File:
cpp/include/cuml/svm/svr.hpp
Signature
namespace ML {
namespace SVM {
template <typename math_t>
int svrFit(const raft::handle_t& handle,
math_t* X,
int n_rows,
int n_cols,
math_t* y,
const SvmParameter& param,
ML::matrix::KernelParams& kernel_params,
SvmModel<math_t>& model,
const math_t* sample_weight = nullptr);
template <typename math_t>
int svrFitSparse(const raft::handle_t& handle,
int* indptr,
int* indices,
math_t* data,
int n_rows,
int n_cols,
int nnz,
math_t* y,
const SvmParameter& param,
ML::matrix::KernelParams& kernel_params,
SvmModel<math_t>& model,
const math_t* sample_weight = nullptr);
} // namespace SVM
} // namespace ML
Import
#include <cuml/svm/svr.hpp>
I/O Contract
Inputs
svrFit (dense)
| Name | Type | Required | Description |
|---|---|---|---|
| handle | const raft::handle_t& | Yes | cuML handle for GPU resources |
| X | 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 |
| y | math_t* | Yes | Device pointer to target values [n_rows] |
| param | const SvmParameter& | Yes | SVM training parameters (C, epsilon, tol, max_iter, etc.) |
| kernel_params | ML::matrix::KernelParams& | Yes | Kernel type and parameters |
| sample_weight | const math_t* | No | Optional device pointer to sample weights [n_rows] (default: nullptr) |
svrFitSparse (sparse)
| Name | Type | Required | Description |
|---|---|---|---|
| handle | const raft::handle_t& | Yes | cuML handle |
| indptr | int* | Yes | Device pointer to CSR row offsets [n_rows + 1] |
| indices | int* | Yes | Device pointer to CSR column indices [nnz] |
| data | math_t* | Yes | Device pointer to CSR values [nnz] |
| n_rows | int | Yes | Number of training samples |
| n_cols | int | Yes | Number of features |
| nnz | int | Yes | Number of non-zero entries |
| y | math_t* | Yes | Device pointer to target values [n_rows] |
| param | const SvmParameter& | Yes | SVM training parameters |
| kernel_params | ML::matrix::KernelParams& | Yes | Kernel parameters |
| sample_weight | const math_t* | No | Optional sample weights [n_rows] (default: nullptr) |
Outputs
| Name | Type | Description |
|---|---|---|
| model | SvmModel<math_t>& | Trained SVR model containing support vectors, dual coefficients, and bias |
| return value | int | Number of solver iterations run during fitting |
Usage Examples
#include <cuml/svm/svr.hpp>
#include <cuml/svm/svc.hpp> // for svcPredict (used for SVR prediction)
raft::handle_t handle;
int n_rows = 5000;
int n_cols = 100;
float* d_X; // device [n_rows x n_cols], column-major
float* d_y; // device [n_rows] target values
// Configure SVM parameters (C, epsilon for SVR)
ML::SVM::SvmParameter param;
param.C = 1.0f;
param.tol = 1e-3f;
param.epsilon = 0.1f; // epsilon-insensitive tube width
// Configure RBF kernel
ML::matrix::KernelParams kernel_params;
kernel_params.kernel = ML::matrix::KernelType::RBF;
kernel_params.gamma = 0.01f;
// Train SVR
ML::SVM::SvmModel<float> model;
int n_iter = ML::SVM::svrFit<float>(handle, d_X, n_rows, n_cols, d_y,
param, kernel_params, model);
// Predict using svcPredict (shared with SVC)
float* d_preds; // device [n_rows]
ML::SVM::svcPredict<float>(handle, d_X, n_rows, n_cols,
kernel_params, model, d_preds,
200.0f, // buffer_size
false); // predict_class=false for regression values
// Free model buffers
ML::SVM::svmFreeBuffers<float>(handle, model);