radix-ai / conformal-tights

👖 Conformal Tights adds conformal prediction of coherent quantiles and intervals to any scikit-learn regressor or Darts forecaster
MIT License
78 stars 3 forks source link

'DartsForecaster' object has no attribute '_get_model_container' #25

Open antara-c opened 1 month ago

antara-c commented 1 month ago

Hi, I am trying to run conformal tights on my local machine, however even after a pip install conformal tights and pip install darts, I get the above error message (in title). Is there something I'm missing?

lsorber commented 1 month ago

Hi @antara-c, thanks for the report. Could you provide a minimal reproducible example please?

antara-c commented 4 weeks ago

Hi @lsorber , sure here's the bit that throws an error to me

forecaster = DartsForecaster( model=conformal_predictor, lags=5 * 24, # Add the last 5 days of the target to the prediction features lags_future_covariates=[0], # Add the current timestamp's covariates to the prediction features

categorical_future_covariates=X_categoricals, # Convert these covariates to pd.Categorical

)

Fit the forecaster

forecaster.fit(y1_train, future_covariates=X1_train)

Make a probabilistic forecast 5 days into the future by predicting a set of conformally calibrated

quantiles at each time step and drawing 500 samples from them

quantiles = (0.025, 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.975) forecast = forecaster.predict( n=5 * 24, future_covariates=X1_test, num_samples=500, quantiles=quantiles )

I'm not using categorical variables This is the error

AttributeError Traceback (most recent call last) Cell In[67], line 1 ----> 1 forecaster = DartsForecaster( 2 model=conformal_predictor, 3 lags=5 * 24, # Add the last 5 days of the target to the prediction features 4 lags_future_covariates=[0], # Add the current timestamp's covariates to the prediction features 5 #categorical_future_covariates=X_categoricals, # Convert these covariates to pd.Categorical 6 ) 8 # Fit the forecaster 9 forecaster.fit(y1_train, future_covariates=X1_train)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\conformal_tights_darts_forecaster.py:104, in DartsForecaster.init(self, model, lags, lags_past_covariates, lags_future_covariates, output_chunk_length, output_chunk_shift, add_encoders, multi_models, use_static_covariates, categorical_past_covariates, categorical_future_covariates, categorical_static_covariates) 102 # Initialise _LikelihoodMixin. 103 self.likelihood = "quantile" --> 104 self._model_container = self._get_model_container() 105 self._rng = check_random_state(model.random_state) # Generator for sampling. 106 # Initialise darts.models.RegressionModel.

AttributeError: 'DartsForecaster' object has no attribute '_get_model_container'

lsorber commented 4 weeks ago

Hi @antara-c, I'll need a bit more information to be able to help you with this:

  1. Could you share the output of pip list in your environment?
  2. Could you provide a full example that I can run locally to reproduce the issue? This can be a .py or .ipynb file.
lsorber commented 3 weeks ago

Hi @antara-c, we just released v0.4.0 which brings a number of improvements. Specifically, https://github.com/radix-ai/conformal-tights/pull/26 may help address the issue you reported. If that solves it for you, please let me know so that I can close this issue, thank you! If not, please provide the information I requested above 👆.

antara-c commented 3 weeks ago

hi, I upgraded the version of conformal tights and still get the above error

pip list as you requested Package Version


adagio 0.2.4 aiohttp 3.9.5 aiosignal 1.3.1 antlr4-python3-runtime 4.11.1 appdirs 1.4.4 asttokens 2.4.1 attrs 23.2.0 catboost 1.2.5 certifi 2024.2.2 charset-normalizer 3.3.2 cloudpickle 3.0.0 colorama 0.4.6 comm 0.2.2 conformal-tights 0.4.0 contourpy 1.2.1 coreforecast 0.0.8 cycler 0.12.1 Cython 3.0.10 debugpy 1.8.1 decorator 5.1.1 executing 2.0.1 filelock 3.13.4 fonttools 4.51.0 frozenlist 1.4.1 fs 2.4.16 fsspec 2024.3.1 fugue 0.8.7 fugue-sql-antlr 0.2.0 graphviz 0.20.3 h5py 3.11.0 holidays 0.47 idna 3.7 intel-openmp 2021.4.0 ipykernel 6.29.4 ipython 8.23.0 ipywidgets 8.1.2 jedi 0.19.1 Jinja2 3.1.3 joblib 1.4.0 jupyter_client 8.6.1 jupyter_core 5.7.2 jupyterlab_widgets 3.0.10 kiwisolver 1.4.5 lightning-utilities 0.11.2 llvmlite 0.42.0 MarkupSafe 2.1.5 matplotlib 3.8.4 matplotlib-inline 0.1.7 missingno 0.5.2 mkl 2021.4.0 mpmath 1.3.0 multidict 6.0.5 nest-asyncio 1.6.0 networkx 3.3 nfoursid 1.0.1 numba 0.59.1 numpy 1.26.4 packaging 24.0 pandas 2.2.2 parso 0.8.4 patsy 0.5.6 pillow 10.3.0 platformdirs 4.2.1 plotly 5.22.0 pmdarima 2.0.4 prompt-toolkit 3.0.43 protobuf 5.26.1 psutil 5.9.8 pure-eval 0.2.2 pyarrow 16.0.0 Pygments 2.17.2 pyod 1.1.3 pyparsing 3.1.2 python-dateutil 2.9.0.post0 pytorch-lightning 2.2.3 pytz 2024.1 pywin32 306 PyYAML 6.0.1 pyzmq 26.0.2 qpd 0.4.4 requests 2.31.0 roerich 0.6.0 ruptures 1.1.9 scikit-base 0.7.7 scikit-learn 1.4.2 scipy 1.13.0 seaborn 0.13.2 shap 0.45.0 six 1.16.0 sktime 0.28.0 slicer 0.0.7 sqlglot 23.11.2 stack-data 0.6.3 statsforecast 1.7.4 statsmodels 0.14.2 sympy 1.12 tbats 1.1.3 tbb 2021.12.0 tenacity 8.2.3 tensorboardX 2.6.2.2 threadpoolctl 3.4.0 torch 2.3.0 torchaudio 2.3.0 torchmetrics 1.3.2 torchvision 0.18.0 tornado 6.4 tqdm 4.66.2 traitlets 5.14.3 triad 0.9.6 typing_extensions 4.11.0 tzdata 2024.1 u8darts 0.29.0 urllib3 2.2.1 utilsforecast 0.1.7 wcwidth 0.2.13 widgetsnbextension 4.0.10 xarray 2024.3.0 xgboost 2.0.3 yarl 1.9.4

I will not be able to share the py file due to constraints. I am able to produce the first graph though (https://pypi.org/project/conformal-tights/) so I would understand if you need to close this due to the lack of the source code. Thanks

lsorber commented 3 weeks ago

All right, I'd like to help but it's fairly difficult to debug this without having an example that I can use to reproduce the issue locally.

If you want to proceed, I'd need to know the following:

  1. Can you share how you created the conformal_predictor you passed to DartsForecaster?
  2. Is isinstance(forecaster, darts.models.forecasting.regression_model._LikelihoodMixin) true?
  3. Is hasattr(darts.models.forecasting.regression_model._LikelihoodMixin, "_get_model_container") true?
  4. Is hasattr(forecaster, "_get_model_container") true?

The answers to (2)-(4) should be yes. If the answer is no to any of these, that will give us a clue as to where the issue is.