我一直收到此错误:
ValueError: shapes (50,6) and (50,6) not aligned: 6 (dim 1) != 50 (dim 0)".
有人对如何“对齐”这些矩阵有任何建议吗?我正在使用Python 3.5.1。
real_x = data.iloc[:,0:4].values real_y= data.iloc[:,4].values le = LabelEncoder() real_x[:,3] = le.fit_transform(real_x[:,3]) oneHE = OneHotEncoder(categorical_features=[3])#categorical features col 3 real_x = oneHE.fit_transform(real_x).toarray() real_x = real_x[:,1:] training_x,test_x,training_y,test_y = train_test_split(real_x,real_y,test_size=0.2,random_state=0) MLR = LinearRegression() MLR.fit(training_x,training_y) Pred_y = MLR.predict(test_x) real_x = np.append(arr=np.ones((50,1)).astype(int),values=real_x, axis=1) x_opt= real_x[:,[0,1,2,3,4]] reg_OLS = sm.OLS(endog=real_x, exog=x_opt).fit() m = reg_OLS.summary() real_x.shape (50, 6) x_opt.shape (50, 5)
我尝试重塑它们,但再次显示错误
x_opt.reshape(50,6) ValueError: cannot reshape array of size 250 into shape (50,6)
这里是完整的错误
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-15-02d59637cd4f> in <module>()
----> 1 m = reg_OLS.summary()
ValueError: shapes (50,6) and (50,6) not aligned: 6 (dim 1) != 50 (dim 0)
我一直收到此错误:ValueError:形状(50,6)和(50,6)不对齐:6(dim 1)!= 50(dim 0)”。有人对如何“对齐”有任何建议吗?这些矩阵?我正在使用Python 3.5.1 ....
OLS仅用于单变量因变量(endog
),您的endg是多变量。statsmodels当前不支持多变量LS版本。