'Linear Regression statsmodel: Missing a required outcome variable
I am using statsmodel
to build a linear regression for salary. It's giving me an error that says I am missing a required outcome variable. Can you tell what I am doing wrong here? My initial model, my_model
seemed working but the ols
fitted model says I am missing a required outcome variable.
my_model = str('Salary ~ X1 + X2')`
my_model = str('')
train_model_fit = smf.ols(my_model, data = X_train).fit()
print(train_model_fit.summary())
X_train['predict_salary'] = train_model_fit.fittedvalues
X_test['predict_salary'] = train_model_fit.predict(X_test)
Solution 1:[1]
[Answering for completeness]
You set the model formula in the first line:
my_model = str('Salary ~ X1 + X2')`
But then you assign an empty string to it:
my_model = str('')
Hence the error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Robert Long |