cvxreg.models.CSVR

cvxreg.models.CSVR(*, c=1.0, epsilon=0.1, shape='convex', monotonic=None, fit_intercept=True, solver='ecos')

Convex Support Vector Regression (CSVR) model.

CSVR fit a convex function with coefficients \(\boldsymbol{\xi}_1,\ldots,\boldsymbol{\xi}_n\) from the data. \(\boldsymbol{\xi}_i\) is d-dimensional vector and n is the number of observations. The optimization problem is:

\[\begin{split}\min_{\boldsymbol{\xi}_1,\ldots,\boldsymbol{\xi}_n; \boldsymbol{\theta}, \pi, \pi^*} & \frac{1}{2}\sum_{i=1}^n \|\boldsymbol{\xi}_i\|_2^2 + c * \sum_{i=1}^n (\pi_i + \pi_i^*) \\\\ s.t. & y_i - \theta_i \leq \epsilon + \pi_i, i=1,\ldots,n \\\\ & \theta_i - y_i \leq \epsilon + \pi_i^*, i=1,\ldots,n \\\\ & \theta_i + \boldsymbol{\xi}_i^T (\boldsymbol{x}_j - \boldsymbol{x}_i) \geq \theta_j, i,j=1,\ldots,n\end{split}\]

where \(\boldsymbol{x}_i\) is the i-th observation, \(y_i\) is the i-th target value, \(\theta_i\) is the value of \(f(\boldsymbol{x}_i)\), \(\boldsymbol{\xi}_i\) is the coefficient at the i-th observation, and \(c\) is the regularization parameter.

Parameters

Parameters

Options

c

Float, default: 1.0. c must be non-negative Float, i.e. in \([0, inf)\).

The regularization parameter.

epsilon

Float, default: 0.1. epsilon must be non-negative Float, i.e. in \([0, inf)\).

The epsilon parameter in the epsilon-insensitive loss function.

shape

Selection: {convex, concave}, default: convex

The shape of the function to be fitted.

monotonic

Selection: {increasing, decreasing}, default: None

Whether to constrain the function monotonic.

fit_intercept

Boolean, default: True

Whether to fit the intercept.

solver

Selection: {ecos, osqp, scs, cvxopt, mosek, gurobi, cplex, copt}, default: ecos

The solver to use. There three open-source solvers: ecos, osqp, scs, and five commercial solvers: cvxopt, mosek, gurobi, cplex, copt.

To use commercial solvers, you need to install them first, see Install.

Attributes

Attributes

Type

coef_

numpy.ndarray

The coefficients of the fitted function.

intercept_

numpy.ndarray

The intercept of the fitted function.

Examples

import numpy as np
from cvxreg.models import CSVR
X = np.array([[1, 1], [1, 2], [2, 2]])
y = [1, 2, 3]
csvr = CSVR()
csvr.fit(X, y)
print(csvr.coef_)
# [[-2.72282908e-09 -9.16695789e-09]
#  [-4.73065053e-09  4.99999982e-01]
#  [ 9.99992687e-01  4.99999982e-01]]
print(csvr.intercept_)
# [ 1.40000369  0.9000037  -0.09998899]

Methods

Methods

Type

fit(X, y)

Fit model with solver.

X of shape (n_samples, n_features)

y of shape (n_samples,)

predict(X)

Predict using the convex regression model.

X of shape (n_samples, n_features)

See examples: Examples.