zoukankan      html  css  js  c++  java
  • 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 k folds as train set and the (k+1) 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]
  • 相关阅读:
    动手篇:简易的首页登陆界面
    情感交流篇:HTML页面如何与后端联系
    MD5加密处理
    处女篇:自用C#后端SqlHelper.cs类
    动手篇:简单的注册界面与防SQL注入(续)
    十二省联考2019 字符串问题
    PKUWC2020游记
    uoj435 Simple Tree
    CF1303G Sum of Prefix Sums
    AGC069F Flags
  • 原文地址:https://www.cnblogs.com/zle1992/p/6915276.html
Copyright © 2011-2022 走看看