cvxreg.models.CR¶
cvxreg.models.CR(*, shape='convex', monotonic=None, fit_intercept=True, solver='ecos')
Convex regression (CR) model.¶
CR 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 samples. The optimization problem is:
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.
Parameters¶
Parameters |
Options |
|---|---|
|
Selection: { The shape of the function to be fitted. |
|
Selection: { Whether to constrain the function to be monotonic. |
|
Boolean, default: True Whether to fit the intercept. |
|
Selection: { The solver to use. There three open-source solvers: To use commercial solvers, you need to install them first, see Install. |
Attributes¶
Attributes |
Type |
|---|---|
|
numpy.ndarray The coefficients of the fitted function. |
|
numpy.ndarray The intercept of the fitted function. |
Examples¶
import numpy as np
from cvxreg.models import CR
X = np.array([[1, 1], [1, 2], [2, 2]])
y = [1, 2, 3]
cr = CR()
cr.fit(X, y)
print(cr.coef_)
# [[0.99999721 0.27092186]
# [0.27092381 1.72907812]
# [1.72907904 1.00000423]]
print(cr.intercept_)
# [-0.27091906 -1.72908007 -2.45816658]
Methods¶
Methods |
Type |
|---|---|
|
Fit model with solver. X of shape (n_samples, n_features) y of shape (n_samples,) |
|
Predict using the convex regression model. X of shape (n_samples, n_features) |
See examples: Examples.