Hi everyone, I am using MLForecast and wondering i...
# mlforecast
m
Hi everyone, I am using MLForecast and wondering if it is possible to do interaction between lags. As far as i've known, there's only
Combine
that operates two lag_transform. Anybody knows how to create a feature such as
lag_4 * lag_1
or
expanding_mean_4 * lag_12
?
j
Hey. You can define a scikit-learn transformer to do that, you can find an example here
m
Is it not possible to add then in the MLForecast parameters? I am currently making a modular pipeline and hoping that I can create a whole feature engineering module as once. Hoping that I can create a custom function like in here
j
It's not possible with regular arguments. The other approach is defining like a feature engineering function that runs after preprocess, something like:
Copy code
def my_feat_eng(X):
    X['feat1'] = ...
    X['feat2'] = ...
    return X

X, y = mlf.preprocess(df, ..., return_X_y=True)
X2 = my_feat_eng(X)
mlf.fit_models(X2, y)
mlf.predict(..., before_predict_callback=my_feat_eng)
but the scikit-learn pipeline integrates better.
m
Noted, thank you very much for the answer. I will try the second option.