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]
  • 相关阅读:
    地址SQL文件
    SpringBoot webjars 映射
    Maven 阿里镜像
    Log4j输出的日志乱码问题
    Redis Client 官方下载地址
    SpringBoot连接Oracle报错,找不到驱动类,application.properties文件中驱动类路径为红色
    Linux Ubuntu 默认root密码
    Java 格式化字符串
    Linux Ubuntu 常见的压缩命令
    使用MD5比较两个文件是否相同
  • 原文地址:https://www.cnblogs.com/zle1992/p/6915276.html
Copyright © 2011-2022 走看看