I have 3 independent variables that I want to fit to a form:
y= a + b*x1 + c*x2 + d*x3
where I can arbitrarily impose constraints on a, b, c, and d.
I somewhat understand how to do this in cvxpy but my linear algebra education was 10 years ago and I can't seem to find an example on SO or other places on the web that include an intercept in a multilinear regression...
The code in this previous SO answer is almost what I want except doesn't seem to support the intercept...: https://stackoverflow.com/a/39853507/13128034
from cvxpy import *
a = np.array([1.2, 2.3, 4.2])
b = np.array([1, 5, 6])
c = np.array([5.4, 6.2, 1.9])
m = np.vstack([a,b,c])
y = np.array([5.3, 0.9, 5.6])
X = Variable(m.shape[0])
constraints = [X >= 0, sum_entries(X) == 1.0]
product = m.T * diag(X)
diff = sum_entries(product, axis=1) - y
problem = Problem(Minimize(norm(diff)), constraints)
problem.solve(verbose=True)
print(problem.value)
print(X.value)
I assume I just need to modify the m and X arrays in this example to include an intercept?