Hi, I'm trying to access the fitted values during ...
# mlforecast
j
Hi, I'm trying to access the fitted values during training of a lgbm regression model. However, I experience an index error that to me is quite strange. Below I have made a mini example of the problem, which only occurs when I set
max_horizon
larger than 10 (it works for 10 and lower).
Copy code
from mlforecast import MLForecast
from lightgbm import LGBMRegressor
import pandas as pd
df = pd.concat([
    pd.DataFrame({
        'id': ['A'] * 1000,
        'ds': pd.date_range(start='2020-01-01', periods=1000, freq='H'),
        'y': range(1000)
    }),
    pd.DataFrame({
        'id': ['B'] * 1000,
        'ds': pd.date_range(start='2020-01-01', periods=1000, freq='H'),
        'y': range(1000)
    })
])
fcst = MLForecast(
    models=LGBMRegressor(),
    freq='H',
    lags=[1, 2, 3],
)
fcst.fit(df, id_col='id', time_col='ds', target_col='y', max_horizon=11, fitted=True )
in_sample_predictions = fcst.forecast_fitted_values()
print(in_sample_predictions)
Copy code
File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.9/site-packages/mlforecast/forecast.py:412, in MLForecast._compute_fitted_values(self, base, X, y, id_col, time_col, target_col, max_horizon)
    409 for horizon in range(max_horizon):
    410     horizon_base = ufp.copy_if_pandas(base, deep=True)
    411     horizon_base = ufp.assign_columns(
--> 412         horizon_base, target_col, y[:, horizon]
    413     )
    414     horizon_fitted_values.append(horizon_base)
    415 for name, horizon_models in self.models_.items():

IndexError: index 10 is out of bounds for axis 1 with size 10
👍 1
j
Hey. This was fixed in 0.13.0, can you upgrade to that version?
🙌 1
j
Great, thanks a lot!