尽管形状相同,但Python形状未对齐

时间:2018-08-10 12:53:18

标签: python statsmodels

我会承认,遇到常见错误ValueError: shapes *value* and *value* not aligned时我经常感到困惑,并且使用Statsmodels库运行的一些最新代码使我再次感到困惑。

我运行smModel = smf.ols(formula='leads ~ sessions', data=trainingRegressionData).fit()没问题,但是在print(smModel.summary())时遇到以下错误:

ValueError: shapes (181,61) and (181,61) not aligned: 61 (dim 1) != 181 (dim 0)

现在trainingRegressionData<class 'pandas.core.frame.DataFrame'>,形状是(181, 2),所以我不确定摘要如何吐出61列,但是即使这样,形状也一样那么为什么错误会说未对齐?

对于上述问题的任何帮助以及有关调试形状错误的解释,将不胜感激。

完全错误:

ValueError                                Traceback (most recent call last)
<ipython-input-14-6777963ed99f> in <module>()
----> 1 print(smModel.summary())

~/.pyenv/versions/3.6.5/lib/python3.6/site-packages/statsmodels/regression/linear_model.py in summary(self, yname, xname, title, alpha)
   2374             top_left.append(('Covariance Type:', [self.cov_type]))
   2375 
-> 2376         top_right = [('R-squared:', ["%#8.3f" % self.rsquared]),
   2377                      ('Adj. R-squared:', ["%#8.3f" % self.rsquared_adj]),
   2378                      ('F-statistic:', ["%#8.4g" % self.fvalue]),

~/.pyenv/versions/3.6.5/lib/python3.6/site-packages/statsmodels/tools/decorators.py in __get__(self, obj, type)
     95         if _cachedval is None:
     96             # Call the "fget" function
---> 97             _cachedval = self.fget(obj)
     98             # Set the attribute in obj
     99             # print("Setting %s in cache to %s" % (name, _cachedval))

~/.pyenv/versions/3.6.5/lib/python3.6/site-packages/statsmodels/regression/linear_model.py in rsquared(self)
   1541     def rsquared(self):
   1542         if self.k_constant:
-> 1543             return 1 - self.ssr/self.centered_tss
   1544         else:
   1545             return 1 - self.ssr/self.uncentered_tss

~/.pyenv/versions/3.6.5/lib/python3.6/site-packages/statsmodels/tools/decorators.py in __get__(self, obj, type)
     95         if _cachedval is None:
     96             # Call the "fget" function
---> 97             _cachedval = self.fget(obj)
     98             # Set the attribute in obj
     99             # print("Setting %s in cache to %s" % (name, _cachedval))

~/.pyenv/versions/3.6.5/lib/python3.6/site-packages/statsmodels/regression/linear_model.py in ssr(self)
   1513     def ssr(self):
   1514         wresid = self.wresid
-> 1515         return np.dot(wresid, wresid)
   1516 
   1517     @cache_readonly

ValueError: shapes (181,61) and (181,61) not aligned: 61 (dim 1) != 181 (dim 0)

trainingRegressionData的头尾:

[181 rows x 2 columns]>
    sessions leads
366      197    33
367      408    71
368      404    59
369      412    60
...
544      357    58
545      285    48
546      275    38

[181 rows x 2 columns]

0 个答案:

没有答案