You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm encountering a type mismatch issue when passing a list of models (regressors) to the MLForecast class. The documentation states that the models parameter can be either a single regressor or a list of regressors as in https://github.com/Nixtla/mlforecast/blob/main/mlforecast/forecast.py#L126. However, when passing a list of models or the model alone, I receive a type error indicating that Argument of type "list[LGBMRegressor]" cannot be assigned to parameter "models" of type "Models" in function "init"
Python 3.10.12
mlforecast 0.13.4
According to the documentation:
Parameters
models : regressor or list of regressors
Models that will be trained and used to compute the forecasts.
Sample code:
# Import necessary librariesfrommlforecastimportMLForecastimportlightgbmaslgbfromsklearn.linear_modelimportLinearRegressionimportpandasaspd# Create a simple DataFrame to simulate datatrain_df=pd.DataFrame({
'ds': pd.date_range(start='2020-01-01', periods=100, freq='D'),
'y': range(100),
})
# Define a list of modelsmodels= [
lgb.LGBMRegressor(random_state=0, verbosity=-1),
LinearRegression(),
]
# Initialize MLForecast with the list of modelstry:
fcst=MLForecast(models=models, freq='D')
print("Model initialized successfully.")
exceptTypeErrorase:
print(f"Encountered an error: {e}")
the above code works fine without warning, but when using
it gives respective pylance warnings as below in vscode:
Argumentoftype"list[LGBMRegressor]"cannotbeassignedtoparameter"models"oftype"Models"infunction"__init__"Type"list[LGBMRegressor]"isincompatiblewithtype"Models""list[LGBMRegressor]"isincompatiblewith"BaseEstimator""list[LGBMRegressor]"isincompatiblewith"List[BaseEstimator]"Typeparameter"_T@list"isinvariant, but"LGBMRegressor"isnotthesameas"BaseEstimator"Considerswitchingfrom"list"to"Sequence"whichiscovariant
"list[LGBMRegressor]" is incompatible with "Dict[str, BaseEstimator]"Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)orArgumentoftype"LGBMRegressor"cannotbeassignedtoparameter"models"oftype"Models"infunction"__init__"Type"LGBMRegressor"isincompatiblewithtype"Models""LGBMRegressor"isincompatiblewith"BaseEstimator""LGBMRegressor"isincompatiblewith"List[BaseEstimator]""LGBMRegressor"isincompatiblewith"Dict[str, BaseEstimator]"Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)
Could you please look into why that is happening despite the documentation?
Link
No response
The text was updated successfully, but these errors were encountered:
Hey @sumamjose, thanks for using mlforecast. This seems to be related to LightGBM, it seems that the linter picks up the dummy classes defined in the compat module instead of the scikit learn ones. Here's a minimal example (without mlforecast) where we can see the issue:
Feel free to open an issue there, it seems that what XGBoost does (defining those dummy base classes as object instead) works.
Description
I'm encountering a type mismatch issue when passing a list of models (regressors) to the MLForecast class. The documentation states that the models parameter can be either a single regressor or a list of regressors as in https://github.com/Nixtla/mlforecast/blob/main/mlforecast/forecast.py#L126. However, when passing a list of models or the model alone, I receive a type error indicating that Argument of type "list[LGBMRegressor]" cannot be assigned to parameter "models" of type "Models" in function "init"
Python 3.10.12
mlforecast 0.13.4
According to the documentation:
Parameters
models : regressor or list of regressors
Models that will be trained and used to compute the forecasts.
Sample code:
the above code works fine without warning, but when using
or
it gives respective pylance warnings as below in vscode:
Could you please look into why that is happening despite the documentation?
Link
No response
The text was updated successfully, but these errors were encountered: