Nixtla / mlforecast

Scalable machine 🤖 learning for time series forecasting.
https://nixtlaverse.nixtla.io/mlforecast
Apache License 2.0
908 stars 90 forks source link

[core/auto] Cannot reproduce Hyperparameter Tuning tutorial due to an import error on v0.13.0 #359

Closed ds-qst closed 5 months ago

ds-qst commented 5 months ago

What happened + What you expected to happen

When trying to import from mlforecast.auto in a notebook I receive an ImportError: cannot import name '_get_model_name' from 'mlforecast.core'

Trying to reproduce the hyperparameter tuning guide (https://nixtlaverse.nixtla.io/mlforecast/docs/how-to-guides/hyperparameter_optimization.html#imports)

Versions / Dependencies

mlforecast is 0.13.0.

Reproduction script

import os import tempfile

import lightgbm as lgb import optuna import pandas as pd 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 from utilsforecast.plotting import plot_series

from mlforecast import MLForecast from mlforecast.auto import ( AutoLightGBM, AutoMLForecast, AutoModel, AutoRidge, ridge_space, ) from mlforecast.lag_transforms import ExponentiallyWeightedMean, RollingMean

Issue Severity

High: It blocks me from completing my task.

jmoralez commented 5 months ago

Hey. How did you install the package? It's very unlikely that it has an incompatibility within itself, you may have mixed installs.

ds-qst commented 5 months ago

Hey. How did you install the package? It's very unlikely that it has an incompatibility within itself, you may have mixed installs.

Just installed with a normal "pip install mlforecast". I also did some test imports:

from mlforecast.core import _name_models from mlforecast.core import Freq

Does not return an error, but from mlforecast.core import _get_model_name

returns ImportError: cannot import name '_get_model_name' from 'mlforecast.core'

I'm using python 3.10

jmoralez commented 5 months ago

It's here https://github.com/Nixtla/mlforecast/blob/3eb62908cdb58d2c73684ecdb5f9c0aca767242b/mlforecast/core.py#L105

Is that the full error?

ds-qst commented 5 months ago

Yes, that's why I'm confused.

The full error, when running the import from the tutorial is: 20 21 from . import MLForecast ---> 22 from .core import Freq, _get_model_name, _name_models 23 from .lag_transforms import ExponentiallyWeightedMean, RollingMean 24 from .optimization import _TrialToConfig, mlforecast_objective

ImportError: cannot import name '_get_model_name' from 'mlforecast.core' (/home//venv/lib/python3.10/site-packages/mlforecast/core.py)

I checked the core.py already, but no luck importing it. image

Also proof of the version:

image

jmoralez commented 5 months ago

Hmm, I'm not able to reproduce the issue. I just opened that notebook in colab, added %pip install datasetsforecast mlforecast as the top cell and ran all without a problem.

bryanwhiting commented 4 months ago

I've just had this same issue. v0.13.2

image
bryanwhiting commented 4 months ago

I had pre-installed AutoGluon, which had different package requirements for mlforecast and utilsforecast. I did

! pip install --upgrade mlforecast
! pip install --upgrade utilsforecast

and now i can import properly