2014-06-27 75 views
0

我有兩個單獨的數據庫 - 溫度分貝與小時數據和房屋分貝與逐分鐘數據爲hvac使用。我試圖將hvac數據繪製爲一週,一個月和一年的溫度系列,但由於增量與溫度db不匹配,所以我遇到了麻煩。我嘗試過使最小二乘法適合,但是a)不知道如何在熊貓中做一個,以及b)在一兩天後變得非常不準確。有什麼建議麼?熊貓迴歸

+1

它看起來像你應該能夠做的熊貓時間序列。如果你可以發佈一些數據的例子,你到目前爲止的代碼以及你期望的輸出應該是什麼,那麼問題可能會更清楚。 – aquavitae

回答

3

pandastimeseries是完美的這個應用程序。你可以合併一系列不同的採樣頻率,並且pandas將完美對齊它們。然後,您可以對數據進行降採樣並進行預迴歸,即使用statsmodels。一個模擬的例子:

In [288]: 

idx1=pd.date_range('2001/01/01', periods=10, freq='D') 
idx2=pd.date_range('2001/01/01', periods=500, freq='H') 
df1 =pd.DataFrame(np.random.random(10), columns=['val1']) 
df2 =pd.DataFrame(np.random.random(500), columns=['val2']) 
df1.index=idx1 
df2.index=idx2 
In [291]: 

df3=pd.merge(df1, df2, left_index=True, right_index=True, how='inner') 
df4=df3.resample(rule='D') 
In [292]: 

print df4 
       val1  val2 
2001-01-01 0.399901 0.244800 
2001-01-02 0.014448 0.423780 
2001-01-03 0.811747 0.070047 
2001-01-04 0.595556 0.679096 
2001-01-05 0.218412 0.116764 
2001-01-06 0.961310 0.040317 
2001-01-07 0.058964 0.606843 
2001-01-08 0.075129 0.407842 
2001-01-09 0.833003 0.751287 
2001-01-10 0.070072 0.559986 

[10 rows x 2 columns] 
In [294]: 

import statsmodels.formula.api as smf 
mod = smf.ols(formula='val1 ~ val2', data=df4) 
res = mod.fit() 
print res.summary() 
          OLS Regression Results        
============================================================================== 
Dep. Variable:     val1 R-squared:      0.061 
Model:       OLS Adj. R-squared:     -0.056 
Method:     Least Squares F-statistic:     0.5231 
Date:    Fri, 27 Jun 2014 Prob (F-statistic):    0.490 
Time:      10:46:34 Log-Likelihood:    -3.3643 
No. Observations:     10 AIC:        10.73 
Df Residuals:      8 BIC:        11.33 
Df Model:       1           
============================================================================== 
       coef std err   t  P>|t|  [95.0% Conf. Int.] 
------------------------------------------------------------------------------ 
Intercept  0.5405  0.224  2.417  0.042   0.025  1.056 
val2   -0.3502  0.484  -0.723  0.490  -1.467  0.766 
============================================================================== 
Omnibus:      3.509 Durbin-Watson:     2.927 
Prob(Omnibus):     0.173 Jarque-Bera (JB):    1.232 
Skew:       0.399 Prob(JB):      0.540 
Kurtosis:      1.477 Cond. No.       4.69 
==============================================================================