Patsy错误:错误评估因素:名称错误:未定义名称'wheel'



尝试使用统计模型中的公式模块来制作线性回归模型。

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())

我通过使用下划线而不是连字符重命名列标题来解决错误。连字符一定触发了代码中的一些表达式,而我对此一无所知。

最新更新