Search code examples
pythonpython-3.xjupyter-notebooklinear-regressionstatsmodels

PatsyError: Error evaluating factor: NameError: name 'wheel' is not defined


Trying to use the formula module in statsmodels to make linear regression model.

import statsmodels.api as sm
import statsmodels.formula.api as smf
import pandas as pd


cars = pd.concat([y_train, X_train], axis = 1)
cars.head()
model = smf.ols(formula ='price ~ symboling + wheel-base + length + width + height + curb-weight + engine-size + bore + stroke + compression-ratio + horsepower + peak-rpm + city-mpg + highway-mpg + cylinder',data=cars)
results = model.fit()
print(results.summary())

Solution

  • I solved the errors by renaming my column header using underscore instead of the hyphen that it had. Hyphen must have triggered some expression in the code which i don't know anything about.