Is there any library to perform a Multivariate Multiple Regression (a Multiple Regression with multiple dependent variables) in Python?
Greetings and thanks in advance
Is there any library to perform a Multivariate Multiple Regression (a Multiple Regression with multiple dependent variables) in Python?
Greetings and thanks in advance
You can try the modules in sklearn, the response variable can be 2 or more dimensional, and i think it works for OLS (linear regression), lasso, ridge.. The models in statsmodels can only do 1 response (just checked).
Example dataset:
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()
df = pd.DataFrame(data= iris['data'],
columns= iris['feature_names'] )
df.shape
(150, 4)
Now we do the fit:
from sklearn import linear_model
clf = linear_model.LinearRegression()
clf.fit(df[['sepal length (cm)']],df[['petal length (cm)','petal width (cm)']])
clf.coef_
array([[1.85843298],
[0.75291757]])
You can see the coefficients are the same as when you fit one response in this case:
clf.fit(df[['sepal length (cm)']],df[['petal width (cm)']])
clf.coef_
array([[0.75291757]])