0

We are getting the following error after running either check_stats() or compare_models() functions from PyCaret versiob 3.0.x;

"_CURRENT_EXPERIMENT global variable is not set. Please run setup() first."

Is there any pointer that how this can be resolved?

Regards

Adil

i had run the check_stats() function, it gave me the same as mentioned above, further when i had run the compare_model() function, it also gave me the same error. Although when i see the documentation, it had clearly shown the output in the form of pandas dataframe

1 Answers1

1

From your error, that means you didn't run the setup() step. So you need to run setup() first. PyCaret will do something behind the scene (preprocess, train/test split, etc.) with the data that you provide then you can do compare_models(), check_stats(), etc. You can learn more about PyCaret with Time Series from the official tutorial here

from pycaret.datasets import get_data
from pycaret.time_series import TSForecastingExperiment

# Get sample data
y = get_data('airline', verbose=False)

# Setup Experiment
exp = TSForecastingExperiment()
exp.setup(data=y, fh=12)

# Diagnostics plot (acf, pacf, qq-plot, etc.)
exp.plot_model(plot='diagnostics')  

# Check Statisticals Test
exp.check_stats()

# Compare Models
best = exp.compare_models()
Tatchai S.
  • 315
  • 1
  • 3
  • 9
  • i had already run the setup as you had describe in the above code i.e., exp = TSForecastingExperiment() exp.setup(data=y, fh=12) but still i am not able to move forward. Thanks for the response. – user3634141 Apr 13 '23 at 07:37
  • Can you share the code? – Tatchai S. Apr 13 '23 at 07:40
  • Please see the code below; from pycaret.time_series import * exp = TSForecastingExperiment() type(exp) exp = TSForecastingExperiment() exp.setup(data=df_sstore, target='Transactions', fold=3, fh=1, session_id=42) # # check statistical tests on original data check_stats() # ValueError: _CURRENT_EXPERIMENT global variable is not set. Please run setup() first. – user3634141 Apr 13 '23 at 08:01
  • I had change the import statement with a specific import for TSForecastingExperiment class but the results remain the same and getting the same error. – user3634141 Apr 13 '23 at 08:17
  • You need to call exp.check_stats() because you setup() on exp object – Tatchai S. Apr 13 '23 at 08:19
  • PyCaret has Functional API and OOP API. 1. In OOP, you create an experiment object and setup on it then you need to use that object to call the function, for example, exp.check_stats() 2. In Functional, you call setup() directly without the experiment object so you can call check_stats() in the same way – Tatchai S. Apr 13 '23 at 08:29
  • Spot on, thanks a lot. it get resolved now. Any suggestion on using the categorical feature so that i don't need to run on the individual basis of the categorical feature element? – user3634141 Apr 13 '23 at 08:32
  • Try to use the Category Encoders library to encode categorical feature it helps a lot and comes with latest methods like Summary Encoder – Tatchai S. Apr 13 '23 at 08:40
  • do you have any reference or examples of using the Category Encoders? – user3634141 Apr 13 '23 at 09:20
  • You can find examples and benchmarks from https://www.kaggle.com/code/subinium/11-categorical-encoders-and-benchmark – Tatchai S. Apr 13 '23 at 12:58