我使用statsmodels遞增了參數WLS regression functions。如何從統計模型中的WLS迴歸的二維參數獲得測試預測
我有我宣佈這樣一個10x3數據集X:
X = np.array([[1,2,3],[1,2,3],[4,5,6],[1,2,3],[4,5,6],[1,2,3],[1,2,3],[4,5,6],[4,5,6],[1,2,3]])
這是我的數據集,我有一個10X2 endog
載體,看起來像這樣:導入後
z =
[[ 3.90311860e-322 2.00000000e+000]
[ 0.00000000e+000 2.00000000e+000]
[ 0.00000000e+000 -2.00000000e+000]
[ 0.00000000e+000 2.00000000e+000]
[ 0.00000000e+000 -2.00000000e+000]
[ 0.00000000e+000 2.00000000e+000]
[ 0.00000000e+000 2.00000000e+000]
[ 0.00000000e+000 -2.00000000e+000]
[ 0.00000000e+000 -2.00000000e+000]
[ 0.00000000e+000 2.00000000e+000]]
現在import statsmodels.api as sm
我這樣做:
g = np.zeros([3, 2]) # g(x) is a function that will store the regression parameters
mod_wls = sm.WLS(z, X)
temp_g = mod_wls.fit()
print temp_g.params
而且我得到這個輸出:
[[ -5.92878775e-323 -2.77777778e+000]
[ -4.94065646e-324 -4.44444444e-001]
[ 4.94065646e-323 1.88888889e+000]]
早些時候,從the answer to this question,我能夠預測使用numpy.dot
測試數據X_test
的值,如下所示:
np.dot(X_test, temp_g.params)
予理解的是,很容易地自它的endog矢量,y
是一維陣列。但是,當我的endog矢量,在這種情況下,z
是2D時,它是如何工作的? 當我嘗試上面的線爲一維版本中,我得到以下錯誤:
self._check_integrity()
File "C:\Users\app\Anaconda\lib\site-packages\statsmodels\base\data.py", line 247, in _check_integrity
raise ValueError("endog and exog matrices are different sizes")
ValueError: endog and exog matrices are different sizes
@ user333700是否可以使用參數來構建新的迴歸模型,然後使用** predict()**函數? – user961627