JoaquinAmatRodrigo / skforecast

Time series forecasting with machine learning models
https://skforecast.org
BSD 3-Clause "New" or "Revised" License
992 stars 113 forks source link

grid_search_forecaster_multiseries - error #738

Open AVPokrovsky opened 3 days ago

AVPokrovsky commented 3 days ago

Hi, when number of data_m columns exceed 7 the error appears. It worked on previous versions.

ValueError: cannot set WRITEABLE flag to True of this array

        results_grid = grid_search_forecaster_multiseries(
                forecaster         = forecaster,
                series             = data_m,
                param_grid         = param_grid,
                steps              = steps,
                metric             = opt_target_list,
                # metric             = 'mean_absolute_error',
                # metric             = custom_metric_acc_M,
                # metric             = custom_metric_prof_M,  
                initial_train_size = len(data.loc[start_train:end_train, 'adjclose']), # Model is trained with trainign data
                fixed_train_size   = False,
                levels = 'adjclose',
                exog                = None,
                lags_grid          = lags_grid,
                refit              = False,
                return_best        = True,
                verbose            = False                       
                )
JoaquinAmatRodrigo commented 3 days ago

Hi @AVPokrovsky, Could you add a reproducible example with dummy data? What version of skforecast are you using?

JoaquinAmatRodrigo commented 3 days ago

This code should run:


from skforecast.model_selection_multiseries import grid_search_forecaster_multiseries
from skforecast.ForecasterAutoregMultiSeries import ForecasterAutoregMultiSeries
from sklearn.ensemble import RandomForestRegressor
import pandas as pd
import numpy as np

# Data
# ==============================================================================
np.random.seed(1)
data = pd.DataFrame(
    np.random.normal(loc = 0, scale = 1, size = (1096, 10)),
    index = pd.date_range(start='2012-01-01', periods=1096, freq='D'),
    columns = ['item' + str(i) for i in range(1, 11)]
)
end_train = '2014-07-15 23:59:00'

# Create Forecaster Multi-Series
# ==============================================================================
forecaster = ForecasterAutoregMultiSeries(
                 regressor          = RandomForestRegressor(random_state=123),
                 lags               = 24,
             )

# Grid search Multi-Series
# ==============================================================================
lags_grid = [24, 48]
param_grid = {
    'n_estimators': [10, 20],
    'max_depth': [3, 7]
}

results_grid = grid_search_forecaster_multiseries(
        forecaster         = forecaster,
        series             = data,
        param_grid         = param_grid,
        steps              = 7,
        metric             = 'mean_absolute_error', 
        initial_train_size = len(data.loc[:end_train,]),
        fixed_train_size   = False,
        exog               = None,
        lags_grid          = lags_grid,
        refit              = False,
        return_best        = True,
        verbose            = False                       
)
AVPokrovsky commented 3 days ago

Hi, SVR() was used. May be it depends on forecaster. Sometimes it works with 7 columns, sometimes with 6. I use the last skforecast version. I am bit busy now, I will try to send you example later on.

AVPokrovsky commented 3 days ago

Some more info, may be it helps to simulate the error

param_grid = {'kernel':[ 'rbf', 'sigmoid']} lags_grid = [1, 2, 5, 10, 20, 40, [1, 3, 5, 7]]

Name: skforecast Version: 0.12.1