source

AutoRandomForest

 AutoRandomForest (config:Optional[Callable[[optuna.trial._trial.Trial],Di
                   ct[str,Any]]]=None)

Structure to hold a model and its search space

TypeDefaultDetails
configOptionalNonefunction that takes an optuna trial and produces a configuration

source

AutoElasticNet

 AutoElasticNet (config:Optional[Callable[[optuna.trial._trial.Trial],Dict
                 [str,Any]]]=None)

Structure to hold a model and its search space

TypeDefaultDetails
configOptionalNonefunction that takes an optuna trial and produces a configuration

source

AutoLasso

 AutoLasso (config:Optional[Callable[[optuna.trial._trial.Trial],Dict[str,
            Any]]]=None)

Structure to hold a model and its search space

TypeDefaultDetails
configOptionalNonefunction that takes an optuna trial and produces a configuration

source

AutoRidge

 AutoRidge (config:Optional[Callable[[optuna.trial._trial.Trial],Dict[str,
            Any]]]=None)

Structure to hold a model and its search space

TypeDefaultDetails
configOptionalNonefunction that takes an optuna trial and produces a configuration

source

AutoLinearRegression

 AutoLinearRegression (config:Optional[Callable[[optuna.trial._trial.Trial
                       ],Dict[str,Any]]]=None)

Structure to hold a model and its search space

TypeDefaultDetails
configOptionalNonefunction that takes an optuna trial and produces a configuration

source

AutoCatboost

 AutoCatboost (config:Optional[Callable[[optuna.trial._trial.Trial],Dict[s
               tr,Any]]]=None)

Structure to hold a model and its search space

TypeDefaultDetails
configOptionalNonefunction that takes an optuna trial and produces a configuration

source

AutoXGBoost

 AutoXGBoost (config:Optional[Callable[[optuna.trial._trial.Trial],Dict[st
              r,Any]]]=None)

Structure to hold a model and its search space

TypeDefaultDetails
configOptionalNonefunction that takes an optuna trial and produces a configuration

source

AutoLightGBM

 AutoLightGBM (config:Optional[Callable[[optuna.trial._trial.Trial],Dict[s
               tr,Any]]]=None)

Structure to hold a model and its search space

TypeDefaultDetails
configOptionalNonefunction that takes an optuna trial and produces a configuration

source

random_forest_space

 random_forest_space (trial:optuna.trial._trial.Trial)

source

elastic_net_space

 elastic_net_space (trial:optuna.trial._trial.Trial)

source

lasso_space

 lasso_space (trial:optuna.trial._trial.Trial)

source

ridge_space

 ridge_space (trial:optuna.trial._trial.Trial)

source

linear_regression_space

 linear_regression_space (trial:optuna.trial._trial.Trial)

source

catboost_space

 catboost_space (trial:optuna.trial._trial.Trial)

source

xgboost_space

 xgboost_space (trial:optuna.trial._trial.Trial)

source

lightgbm_space

 lightgbm_space (trial:optuna.trial._trial.Trial)

source

AutoModel

 AutoModel (model:sklearn.base.BaseEstimator,
            config:Callable[[optuna.trial._trial.Trial],Dict[str,Any]])

Structure to hold a model and its search space

TypeDetails
modelBaseEstimatorscikit-learn compatible regressor
configCallablefunction that takes an optuna trial and produces a configuration

source

AutoMLForecast

 AutoMLForecast
                 (models:Union[List[__main__.AutoModel],Dict[str,__main__.
                 AutoModel]], freq:Union[int,str], season_length:int, init
                 _config:Optional[Callable[[optuna.trial._trial.Trial],Dic
                 t[str,Any]]]=None, fit_config:Optional[Callable[[optuna.t
                 rial._trial.Trial],Dict[str,Any]]]=None,
                 num_threads:int=1)

Hyperparameter optimization helper

TypeDefaultDetails
modelsUnionAuto models to be optimized.
freqUnionpandas’ or polars’ offset alias or integer denoting the frequency of the series.
season_lengthintLength of the seasonal period. This is used for producing the feature space.
init_configOptionalNoneFunction that takes an optuna trial and produces a configuration passed to the MLForecast constructor.
fit_configOptionalNoneFunction that takes an optuna trial and produces a configuration passed to the MLForecast fit method.
num_threadsint1Number of threads to use when computing the features.

source

AutoMLForecast.fit

 AutoMLForecast.fit
                     (df:Union[pandas.core.frame.DataFrame,polars.datafram
                     e.frame.DataFrame], n_windows:int, h:int,
                     num_samples:int, refit:Union[bool,int]=False, loss:Op
                     tional[Callable[[Union[pandas.core.frame.DataFrame,po
                     lars.dataframe.frame.DataFrame],Union[pandas.core.fra
                     me.DataFrame,polars.dataframe.frame.DataFrame]],float
                     ]]=None, id_col:str='unique_id', time_col:str='ds',
                     target_col:str='y',
                     study_kwargs:Optional[Dict[str,Any]]=None,
                     optimize_kwargs:Optional[Dict[str,Any]]=None)

Carry out the optimization process. Each model is optimized independently and the best one is trained on all data

TypeDefaultDetails
dfUnionSeries data in long format.
n_windowsintNumber of windows to evaluate.
hintForecast horizon.
num_samplesintNumber of trials to run
refitUnionFalseRetrain model for each cross validation window.
If False, the models are trained at the beginning and then used to predict each window.
If positive int, the models are retrained every refit windows.
lossOptionalNoneFunction that takes the validation and train dataframes and produces a float.
If None will use the average SMAPE across series.
id_colstrunique_idColumn that identifies each serie.
time_colstrdsColumn that identifies each timestep, its values can be timestamps or integers.
target_colstryColumn that contains the target.
study_kwargsOptionalNoneKeyword arguments to be passed to the optuna.Study constructor.
optimize_kwargsOptionalNoneKeyword arguments to be passed to the optuna.Study.optimize method.
ReturnsAutoMLForecastobject with best models and optimization results

source

AutoMLForecast.predict

 AutoMLForecast.predict (h:int, X_df:Union[pandas.core.frame.DataFrame,pol
                         ars.dataframe.frame.DataFrame,NoneType]=None)

“Compute forecasts

TypeDefaultDetails
hintNumber of periods to predict.
X_dfUnionNoneDataframe with the future exogenous features. Should have the id column and the time column.
ReturnsUnionPredictions for each serie and timestep, with one column per model.

source

AutoMLForecast.save

 AutoMLForecast.save (path:Union[str,pathlib.Path])

Save AutoMLForecast objects

TypeDetails
pathUnionDirectory where artifacts will be stored.
ReturnsNone
from datasetsforecast.m4 import M4, M4Evaluation, M4Info
from sklearn.linear_model import Ridge
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import OneHotEncoder
def train_valid_split(group):
    df, *_ = M4.load(directory='data', group=group)
    df['ds'] = df['ds'].astype('int')
    horizon = M4Info[group].horizon
    valid = df.groupby('unique_id').tail(horizon).copy()
    train = df.drop(valid.index).reset_index(drop=True)
    return train, valid
ridge_pipeline = make_pipeline(
    ColumnTransformer(
        [('encoder', OneHotEncoder(), ['unique_id'])],
        remainder='passthrough',
    ),
    Ridge()
)
auto_ridge = AutoModel(ridge_pipeline, lambda trial: {f'ridge__{k}': v for k, v in ridge_space(trial).items()})
optuna.logging.set_verbosity(optuna.logging.ERROR)
group = 'Weekly'
train, valid = train_valid_split(group)
train['unique_id'] = train['unique_id'].astype('category')
valid['unique_id'] = valid['unique_id'].astype(train['unique_id'].dtype)
info = M4Info[group]
h = info.horizon
season_length = info.seasonality
auto_mlf = AutoMLForecast(
    freq=1,
    season_length=season_length,
    models={
        'lgb': AutoLightGBM(),
        'ridge': auto_ridge,
    },
    fit_config=lambda trial: {'static_features': ['unique_id']},
    num_threads=2,
)
auto_mlf.fit(
    df=train,
    n_windows=2,
    h=h,
    num_samples=2,
    optimize_kwargs={'timeout': 60},
)
auto_mlf.predict(h)
unique_iddslgbridge
0W1218035529.43522436110.921202
1W1218135521.76489436195.175757
2W1218235537.41726836107.528852
3W1218335538.05820636027.139248
4W1218435614.61121136092.858489
4662W99229215071.53697815319.146221
4663W99229315058.14527815299.549555
4664W99229415042.49343415271.744712
4665W99229515042.14484615250.070504
4666W99229615038.72904415232.127800