Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core]ts.update method may not support target_transforms,lag_transforms and date_features #292

Closed
MrTangsai opened this issue Jan 5, 2024 · 1 comment · Fixed by #293
Labels

Comments

@MrTangsai
Copy link

What happened + What you expected to happen

Hi, me again, long time no see.
I want to maintain a stable model and update subsequent prediction results based on new data every day, I use ts.update() to get it , but encounter the following issues:

  1. When transformed the target like target_transforms=[Differences([1])] then update the subsequent value, but the data used in the actual model has not been differentiated, I saw the source code, under update method, self.ga changed but not consider the situation when if self.target_transforms is not None
  2. When add lag_transforms or date_features , get a bug TypeError: 'Series' object is not callable

Versions / Dependencies

  1. mlforecast: 0.11.4
  2. python: 3.8.16
  3. os: Ubuntu

Reproduction script

situation 1 code is below:

import pandas as pd
from mlforecast import MLForecast
from mlforecast.target_transforms import Differences

from lightgbm import LGBMRegressor
from IPython.display import display
def inspect_input(new_x):
    """Displays the model inputs to inspect them"""
    display(new_x)
    return new_x
df = pd.read_csv('https://datasets-nixtla.s3.amazonaws.com/air-passengers.csv', parse_dates=['ds'])
fcst = MLForecast(
    models=[LGBMRegressor(verbose=-1)],
    freq='MS',  # our serie has a monthly frequency
    lags=[1, 12],
    target_transforms=[Differences([1])],
)
fcst.fit(df, )
print(fcst.predict(1, before_predict_callback=inspect_input))
new_df = pd.DataFrame([['AirPassengers', '1961-01-01', 500]], columns=['unique_id', 'ds', 'y'])
new_df.ds = pd.to_datetime(new_df.ds)
fcst.ts.update(new_df)
print(fcst.predict(1, before_predict_callback=inspect_input))

then the result is below:
image

situation 2 code is below:

import pandas as pd
from mlforecast import MLForecast
from mlforecast.target_transforms import Differences

from lightgbm import LGBMRegressor
from window_ops.rolling import rolling_mean, rolling_std

from IPython.display import display
def inspect_input(new_x):
    """Displays the model inputs to inspect them"""
    display(new_x)
    return new_x
df = pd.read_csv('https://datasets-nixtla.s3.amazonaws.com/air-passengers.csv', parse_dates=['ds'])

fcst = MLForecast(
    models=[LGBMRegressor(verbose=-1)],
    freq='B',  # our serie has a monthly frequency
    lags=[1, 12],
    # lag_transforms={
    #     1: [(rolling_mean, 5), (rolling_mean, 3), (rolling_std, 5), (rolling_std, 3)],
    # },
    date_features=['dayofweek'],
    target_transforms=[Differences([1])],
)
fcst.fit(df, )
print(fcst.predict(1, before_predict_callback=inspect_input))
new_df = pd.DataFrame([['AirPassengers', '1961-01-01', 500]], columns=['unique_id', 'ds', 'y'])
new_df.ds = pd.to_datetime(new_df.ds)
fcst.ts.update(new_df)
print(fcst.predict(1, before_predict_callback=inspect_input))

then the result is below:
image

Issue Severity

High: It blocks me from completing my task.

@jmoralez
Copy link
Member

jmoralez commented Jan 5, 2024

Hey @MrTangsai, thanks again for the excellent report and sorry for the troubles. #293 should fix both errors. We'll make a release soon and in the meantime you can install from github (pip install git+https://github.com/Nixtla/mlforecast).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants