3.1.7. Cross validation of time series data

3.1.7. Cross validation of time series data

Time series data is characterised by the correlation between observations that are near in time (autocorrelation). However, classical cross-validation techniques such as KFold and ShuffleSplit assume the samples are independent and identically distributed, and would result in unreasonable correlation between training and testing instances (yielding poor estimates of generalisation error) on time series data. Therefore, it is very important to evaluate our model for time series data on the “future” observations least like those that are used to train the model. To achieve this, one solution is provided by TimeSeriesSplit.

3.1.7.1. Time Series Split

TimeSeriesSplit is a variation of k-fold which returns first  folds as train set and the  th fold as test set. Note that unlike standard cross-validation methods, successive training sets are supersets of those that come before them. Also, it adds all surplus data to the first training partition, which is always used to train the model.

This class can be used to cross-validate time series data samples that are observed at fixed time intervals.

Example of 3-split time series cross-validation on a dataset with 6 samples:

>>>

>>> from sklearn.model_selection import TimeSeriesSplit

>>> X = np.array([[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]])
>>> y = np.array([1, 2, 3, 4, 5, 6])
>>> tscv = TimeSeriesSplit(n_splits=3)
>>> print(tscv)
TimeSeriesSplit(n_splits=3)
>>> for train, test in tscv.split(X):
...     print("%s %s" % (train, test))
[0 1 2] [3]
[0 1 2 3] [4]
[0 1 2 3 4] [5]
时间: 2024-08-06 16:05:42

3.1.7. Cross validation of time series data的相关文章

交叉验证(Cross Validation)原理小结

交叉验证是在机器学习建立模型和验证模型参数时常用的办法.交叉验证,顾名思义,就是重复的使用数据,把得到的样本数据进行切分,组合为不同的训练集和测试集,用训练集来训练模型,用测试集来评估模型预测的好坏.在此基础上可以得到多组不同的训练集和测试集,某次训练集中的某样本在下次可能成为测试集中的样本,即所谓"交叉". 那么什么时候才需要交叉验证呢?交叉验证用在数据不是很充足的时候.比如在我日常项目里面,对于普通适中问题,如果数据样本量小于一万条,我们就会采用交叉验证来训练优化选择模型.如果样本

R: Kriging interpolation and cross validation 克里金插值及交叉验证浅析

克里金插值的基本介绍可以参考ARCGIS的帮助文档[1]. 其本质就是根据已知点的数值,确定其周围点(预测点)的数值.最直观的方法就是找到已知点和预测点数值之间的关系,从而预测出预测点的数值.比如IDW插值方法,就是假设已知点和预测点的值跟它们相对距离成反比.克里金插值的精妙之处在于它不仅考虑了已知点和预测点的距离关系,还考虑了这些已知点之间的自相关关系. 如何衡量已知点之间的自相关关系呢?通常使用的就是半变异函数,其公式如下[1]: Semivariogram(distance h) = 0.

cross validation交叉验证

交叉验证是一种检测model是否overfit的方法.最常用的cross validation是k-fold cross validation. 具体的方法是: 1.将数据平均分成k份,0,1,2,,,k-1 2.使用1~k-1份数据训练模型,然后使用第0份数据进行验证. 3.然后将第1份数据作为验证数据.进行k个循环.就完成了k-fold cross validation 这个交叉验证的方法的特点是:所有的数据都参与了验证,也都参与了训练,没有浪费数据.

交叉验证的缺陷及改进(Cross Validation done wrong)

本文主要是对我们使用交叉验证可能出现的一个问题进行讨论,并提出修正方案. 本文地址:http://blog.csdn.net/shanglianlm/article/details/47207173 交叉验证(Cross validation)在统计学习中是用来估计你设计的算法精确度的一个极其重要的工具.本文主要展示我们在使用交叉验证时可能出现的一个问题,并提出修正的方法. 下面主要使用 Python scikit-learn 框架做演示. 先验理论(Theory first) 交叉验证将数据集

Cross Validation done wrong

Cross Validation done wrong Cross validation is an essential tool in statistical learning 1 to estimate the accuracy of your algorithm. Despite its great power it also exposes some fundamental risk when done wrong which may terribly bias your accurac

交叉验证(Cross Validation)

假设我们需要从某些候选模型中选择最适合某个学习问题的模型,我们该如何选择?以多元回归模型为例:,应该如何确定k的大小,使得该模型对解决相应的分类问题最为有效?如何在偏倚(bias)和方差(variance)之间寻求最佳的平衡点?更进一步,我们同样需要知道如何在加权回归模型中选择适当的波长参数,或者在基于范式的SVM模型中选择适当的参数C? 我们假设模型集合为有限集,我们的目的就是从这d个模型中,选择最有效的模型. 假设样本集为S,根据经验风险最小化原则(ERM),可能会使用这样的算法: 1.在S

关于K-fold cross validation 下不同的K的选择的疑惑?

在K-fold cross validation 下 比较不同的K的选择对于参数选择(模型参数,CV意义下的估计的泛化误差)以及实际泛化误差的影响.更一般的问题,在实际模型选择问题中,选择几重交叉验证比较合适? 交叉验证的背景知识: CV是用来验证模型假设(hypothesis)性能的一种统计分析方法,基本思想是在某种意义下将原始数据进行分组,一部分作为训练集,一部分作为验证集,使用训练集对每个hypothesis进行训练,再用验证集对每个hypothesis的性能进行评估,然后选取性能最好的h

vehicle time series data analysis

以HADOOP为代表的云计算提供的只是一个算法运行环境,为大数据的并行计算提供了在现有软硬件水平下最好的(近似)方法,并不能解决大数据应用中的所有问题.从具体应用而言,通过物联网方式接入IT圈的数据供应商(Data Provider)所面临的首要问题是数据分析的算法,其次才是算法的并行计算. 以汽车厂商(OEM,Tire1,Vendor,TSP)为例,所面临的大数据问题在 4V(Volume,Velocity,Variety,Veracity/Value)中,最突出的差异是Velocity,即实

[Machine Learning with Python] Cross Validation and Grid Search: An Example of KNN

Train model: from sklearn.model_selection import GridSearchCV param_grid = [ # try 6 (3×2) combinations of hyperparameters {'n_neighbors': [3, 5, 7], 'weights': ['uniform','distance']} ] knn_clf = KNeighborsClassifier() # train across 3 folds, that's