1

,试图预测未来的比特币的价格,我跑进以下困境:如何使用Python来预测多维时间序列,sklearn未知的X值

我只能预测在y标签(例如开放式价格)通过提供我用来训练我的模型的所有X功能。然而,我需要的是对未来的预测,这意味着我的X特征值也是未知的。

这是我的数据的一个片段(6特征列,1个标签):

    Open High  Low HL-PCT PCT-change \ 

2016年1月1日00:00:00 430.89 432.58 429.82 0.642129 -0.030161
2016年1月1日01:00:00 431.51 432.01 429.08 0.682856 0.348829
2016年1月1日02:00:00 430.00 431.69 430.00 0.393023 -0.132383
2016年1月1日03:00:00 430.50 433.37 430.03 0.776690 -0.662252
2016- 01-01 04:00:00 433.34 435.72 432.55 0.732863 -0.406794
201 6-01-01 05:00:00 435.11 436.00 434.47 0.352153 -0.066605
2016-01-01 06:00:00 435.44 435.44 430.08 1.246280 0.440569
2016-01-01 07:00:00 434.71 436.00 433.50 0.576701 0.126681
2016年1月1日08:00:00 433.82 434.19 431.00 0.740139 -0.059897
2016年1月1日09:00:00 433.99 433.99 431.23 0.640030 0.460648

    Volume (BTC) Label 

2016年1月1日00:00 :00 41.32 434.87
2016-01-01 01:00:00 31.21 434.44
2016-01-01 02:00:00 12.25 433.47
2016年1月1日03:00:00 74.98 431.80
2016年1月1日04:00:00 870.80 433.28
2016年1月1日05:00:00 78.53 433.31
2016年1月1日06 :00:00 177.11 433.39
2016年1月1日07:00:00 158.45 432.61
2016年1月1日08:00:00 210.59 432.80
2016年1月1日09:00:00 129.68 432.17

这是我的代码:

#First get my own data 
symbols = ["bitstamp_hourly_2016"] 
timestamp = pd.date_range(start='2016-01-01 00:00', end='2016-12-23 09:00', 
         freq='1h', periods=None) 

df_all = bf.get_data2(symbols, timestamp)  
#Feature Slicing 
df = df_all[['Open', 'High', 'Low', 'Close', 'Volume (BTC)']]  

df.loc[:,'HL-PCT'] = (df['High'] - df['Low'])/df['Low']*100.0 
df.loc[:,'PCT-change'] = (df['Open'] - df['Close'])/df['Close']*100.0 

#only relevant features 
df= df[['Open','High', 'Low', 'HL-PCT', 'PCT-change', 'Volume (BTC)']] 

df.fillna(-99999, inplace=True) 

#cut off the last 24 hours 
forecast_out = int(math.ceil(0.0027*len(df))) 

forecast_col = 'Open' 
df['Label'] = df[forecast_col].shift(-forecast_out) 

#X Features and y Label 
X = np.array(df.drop(['Label'],1)) 
X = preprocessing.scale(X) 

#Last 24 hours 
X_lately = X[-forecast_out:] 
X = X[:-forecast_out] 
y = np.array(df['Label']) 
y = y[:-forecast_out] 

#Train and Test set 
test_size= int(math.ceil(0.3*len(df))) 
X_train, y_train = X[:-test_size], y[:-test_size] 
X_test, y_test= X[-test_size:], y[-test_size:] 

#use linear regression 
clf = LinearRegression(n_jobs=-1) 
clf.fit(X_train, y_train) 

#BIG QUESTION: WHAT TO INSERT HERE TO GET THE REAL FUTURE VALUES 
prediction = clf.predict(X_lately) 

# The coefficients 
print('Coefficients: \n', clf.coef_) 
# The mean squared error 
print("Mean squared error: %.4f" 
     % np.mean((clf.predict(X_test) - y_test) ** 2)) 
# Explained variance score: 1 is perfect prediction 
print('Variance score: %.4f' % clf.score(X_test, y_test)) 

结果:

How many Hours were predicted: 24 
Coefficients: [ 5.30676009e+00 1.05641430e+02 1.44632212e+01  1.47255264e+00 
-1.52247332e+00 -6.26777634e-03] 
Mean squared error: 133.4017 
Variance score: 0.9717 

我想要做的是:给只是一个新的日期,使用训练模型,并从过去的知识,给我一个合理的结果为让说,在未来24小时(实际的未来,我没有数据)。 到目前为止,我只能使用clf.predict()的过去数据。

这应该有可能以某种方式与回归线,但如何?我也可以使用Date作为我的X数据框,但这不会使我的模型无用吗?

感谢

回答

0

如果你想坚持到线性回归,而不是用单纯的日期,你可以尝试预测(与你喜欢的任何模型)模型的回归系数,然后用预测进行线性回归值。

反正它似乎建议您所需要的类型不是编程有关的,我觉得你的问题是更适合https://stats.stackexchange.com/

+0

哦好的,谢谢。我会尽我所能 – kafe1012