Why the code stops running and how to fix the bug?

Viewed 28

I am trying to use pycaret python package from conda to do some timeseries forecasting on a multivariate dataset. The main function containing the process is pasted here for future reference.

def ml_modelling(train, test):
    # Now that we have done the train-test-split, we are ready to train a
    # machine learning model on the train data, score it on the test data and
    # evaluate the performance of our model. In this example, I will use
    # PyCaret; an open-source, low-code machine learning library in Python that
    # automates machine learning workflows.
    numerical_columns = list(train.select_dtypes(include=[np.number]).columns.values)
    targets = [col for col in numerical_columns if col.startswith('Number')]
    for target_var in targets:
        numerical_features = [col for col in numerical_columns if col != target_var]

        # Now, let's initialise the setup using Pycaret's new object-oriented
        # API. The Setup function initializes the training environment and
        # creates a transformation pipeline. It takes two mandatory parameters:
        # data and target, all the other parameters are optional.
        # exp = TSForecastingExperiment()
        s = setup(data=train,
                  test_data=test,
                  target=target_var,
                  fold_strategy='timeseries',
                  numeric_features=numerical_features,
                  fold=5,
                  transform_target=True,
                  session_id=123)

        # By using the experiment function models, we can list all the available
        # time series models in PyCaret. Some of the models like BATS and TBATS
        # are disabled by default, to enable them we need to set turbo = False
        # exp.models()

        # Now to train machine learning models, you just need to run one line
        best = compare_models(sort='MAE')
        print(f'Output from compare_models for column {target_var}: \n', best)
        # there are more statements under this line....

However, after running the code, it stops and after killiing the python, there is a specific error message

IntProgress(value=0, description='Processing: ', max=3)


Initiated  . . . . . . . . . . . . . . . . . .              17:55:57
Status     . . . . . . . . . . . . . . . . . .  Loading Dependencies


Initiated  . . . . . . . . . . . . . . . . . .                     17:55:57
Status     . . . . . . . . . . . . . . . . . .  Preparing Data for Modeling


Initiated  . . . . . . . . . . . . . . . . . .                     17:55:57
Status     . . . . . . . . . . . . . . . . . .  Preparing Data for Modeling


Initiated  . . . . . . . . . . . . . . . . . .            17:55:57
Status     . . . . . . . . . . . . . . . . . .  Preprocessing Data


Initiated  . . . . . . . . . . . . . . . . . .            17:55:57
Status     . . . . . . . . . . . . . . . . . .  Preprocessing Data
Text(value="Following data types have been inferred automatically, if they are correct press enter to continue or type 
'quit' otherwise.", layout=Layout(width='100%'))
           Data Type
Series       Numeric
Year         Numeric
Month        Numeric
Day          Numeric
Weekday  Categorical
Number1        Label
Number2      Numeric
Number3      Numeric
Number4      Numeric
Number5      Numeric
Number6      Numeric

Traceback (most recent call last):
  File "c:\Users\username\OneDrive\Desktop\project\project.py", line 52, in <module>
    main()
  File "c:\Users\username\OneDrive\Desktop\project\project.py", line 45, in main
    ml_modelling(train, test)
  File "c:\Users\username\OneDrive\Desktop\project\utilities.py", line 1016, in ml_modelling
    s = setup(data=train,
  File "C:\Users\username\anaconda3\envs\ashur\lib\site-packages\pycaret\regression.py", line 571, in setup
    return pycaret.internal.tabular.setup(
  File "C:\Users\username\anaconda3\envs\ashur\lib\site-packages\pycaret\internal\tabular.py", line 1308, in setup        
    train_data = prep_pipe.fit_transform(train_data)
  File "C:\Users\username\anaconda3\envs\ashur\lib\site-packages\sklearn\pipeline.py", line 414, in fit_transform
    Xt = self._fit(X, y, **fit_params_steps)
  File "C:\Users\username\anaconda3\envs\ashur\lib\site-packages\sklearn\pipeline.py", line 336, in _fit
    X, fitted_transformer = fit_transform_one_cached(
  File "C:\Users\username\anaconda3\envs\ashur\lib\site-packages\joblib\memory.py", line 349, in __call__
    return self.func(*args, **kwargs)
  File "C:\Users\username\anaconda3\envs\ashur\lib\site-packages\sklearn\pipeline.py", line 870, in _fit_transform_one    
    res = transformer.fit_transform(X, y, **fit_params)
  File "C:\Users\username\anaconda3\envs\ashur\lib\site-packages\pycaret\internal\preprocess.py", line 413, in fit_transform
    data = self.fit(data)
  File "C:\Users\username\anaconda3\envs\ashur\lib\site-packages\pycaret\internal\preprocess.py", line 320, in fit        
    self.response = input()
KeyboardInterrupt
0 Answers
Related