我一直在关注有关Udemy的机器学习教程。我正在使用statsmodels.formula.api
库,但类OLS
不在其中,并且我猜它已经移动了,因为我找到了一个说要使用statsmodels.api
的线程并将其导入。问题是,当我在下面的代码fit()
上运行sm.OLS()
方法时,出现错误'NoneType' Object has no attribute 'shape'
。这是代码和错误。
import statsmodels.api as sm
X = np.append(arr = np.ones((len(X), 1)).astype(int), values = X , axis = 1)
X_opt = X[:, [0, 1, 2, 3, 4, 5]]
regressor_OLS = sm.OLS(endog = y, exorg = X_opt).fit()
[C0行错误
regressor_OLS = sm.OLS(endog = y, exorg = X_opt).fit()
注意:如果像在运行AttributeError: 'NoneType' object has no attribute 'shape'
中一样排除.fit()
,它可以正常运行,但不是我想要的结果。
更改为
regressor_OLS = sm.OLS(endog = y, exorg = X_opt)
这是因为初始化后必须安装回归器。