Welcome to cvxreg’s documentation!

Convex Regression for machine learning.

cvxreg is an open source Python package implementing convex regression models for machine learning. It is built on top of the CVXPY package for convex optimization problems. It lets you implement the convex regression models in a few lines of code. It is well documented and tested. It is compatible with Python 3.7+ and runs on Linux, MacOS X and Windows.

For example, the following code estimates a convex function with CR model:

import numpy as np
from cvxreg.models import CR

# Generate data
np.random.seed(0)
n, d, SNR = 100, 3, 3
x = np.random.uniform(low=-1, high=1, size=(n, d))
y_true = np.linalg.norm(x, axis=1)**2 + 3

sigma = np.sqrt(np.var(y_true, ddof=1, axis=0)/SNR)
nse = np.random.normal(0, sigma, n)
y = y_true + nse

# Fit CR model
cr = CR()
cr.fit(x, y)

# print the coefficients
print(cr.coef_)
# print the intercept
print(cr.intercept_)
# predict the response
y_pred = cr.predict([[0.2, 0.3, 0.5]])