I am using statsmodels (open to other python options) to run some linear regression. My problem is that I need the regression to have no intercept and constraint the coefficients in the range (0,1) and also sum to 1.
I tried something like this (for the sum of 1, at least):
from statsmodels.formula.api import glm
import pandas as pd
df = pd.DataFrame({'revised_guess':[0.6], "self":[0.55], "alter_1":[0.45], "alter_2":[0.2],"alter_3":[0.8]})
mod = glm("revised_guess ~ self + alter_1 + alter_2 + alter_3 - 1", data=df)
res = mod.fit_constrained(["self + alter_1 + alter_2 + alter_3 = 1"],
start_params=[0.25,0.25,0.25,0.25])
res.summary()
but still struggling to enforce the 'non-negative' coefficients constraint.
sklearn.linear_model.LinearRegression
– Harlotryx
has a negative relationship with youry
, what do you mean by constraining its coefficient into the (0,1) range? How can you revert a negative relationship to a positive one? – Ytterbia