繁体   English   中英

用scikit学习时间序列预测

[英]Time series forecasting with scikit learn

我是基于SVM的预测的完全新手,所以在这里寻找一些指导。 我正在尝试使用scikit-learn的SVM库来设置用于预测时间序列的python代码。

我的数据包含过去24小时间隔30分钟的X值,我需要预测下一个时间戳的y值。 这就是我设置的 -

SVR(kernel='linear', C=1e3).fit(X, y).predict(X)

但是为了使这个预测起作用,我需要下一个时间戳的X值,这是不可用的。 如何设置此值以预测未来的y值?

你应该这样使用SVR

# prepare model and set parameters
svr_model = SVR(kernel='linear', C=1e3)
# fit your model with the training set
svr_model.fit(TRAINIG_SET, TAINING_LABEL)
#predict on a test set
svr_model.predict(TEST_SET)

所以,这里的问题是你有一套训练集,但没有测试集来测量模型的准确性。 唯一的解决方案是使用训练集的一部分作为测试集ex: 80% for train 20% for test

编辑

希望我很好地理解你的意见。

因此,您想预测火车组中最后一小时的下一个标签,以下是您想要的示例:

from sklearn.svm import SVR
import random
import numpy as np

'''
data: the train set, 24 elements
label: label for each time
'''

data = [10+y for  y in [x * .5 for x in range(24)]]
label =  [z for z in [random.random()]*24]

# reshaping the train set and the label ...

DATA = np.array([data]).T
LABEL = np.array(label)

# Declaring model and fitting it

clf  = SVR(kernel='linear', C=1e3)
clf.fit(DATA, LABEL)

# predict the next label 

to_predict = DATA[DATA[23,0]+0.5]

print clf.predict(to_predict)

>> 0.94407674

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM