0
$\begingroup$

I am new to sklearn and the TimeseriesSplit, I appologize in advance if that's a dumb question. I cannot find nowhere a way to solve my issue. To my understanding a sample is a row in the timeseries, which my dataset have 40, but I keep getting the error:

ValueError: Cannot have number of folds =3 greater than the number of samples: 0.

I have the following time serie named series:

2017-03-31     0
2017-04-30     0
2017-05-31     0
2017-06-30     0
2017-07-31     0
2017-08-31     0
2017-09-30     0
2017-10-31     0
2017-11-30     0
2017-12-31     0
2018-01-31     1
2018-02-28     0
2018-03-31     0
2018-04-30     0
2018-05-31    80
2018-06-30     0
2018-07-31     5
2018-08-31     0
2018-09-30     0
2018-10-31     1
2018-11-30    92
2018-12-31     0
2019-01-31     0
2019-02-28    16
2019-03-31     0
2019-04-30     0
2019-05-31    30
2019-06-30     0
2019-07-31    13
2019-08-31     0
2019-09-30     0
2019-10-31     0
2019-11-30     0
2019-12-31     0
2020-01-31     0
2020-02-29     0
2020-03-31     0
2020-04-30    10
2020-05-31     0
2020-06-30     0
Freq: M, Name: 100121, dtype: int64

and I want to pass it into TimeseriesSplit

def timeseriesCVscore(params, series, loss_function=mean_squared_error, slen=6):
    """
        Returns error on CV  

        params - vector of parameters for optimization
        series - dataset with timeseries
        slen - season length for Holt-Winters model
    """
    
    errors = []
    values = series
    alpha, beta, gamma = params

 
    tscv = TimeSeriesSplit(n_splits=2)

    
    for train, test in tscv.split(values):
        model = HoltWinters(series=values[train], slen=slen,
                            alpha=alpha, beta=beta, gamma=gamma, n_preds=len(test))

I have tried passing it as a dataframe, I have tried as np.array, nothing seems to do the trick. What could I be missing out?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.