Skip to content

tune_model failing in pycaret.time_series #1665

@moezali1

Description

@moezali1

I think there are two problems:

(1) The n_iter parameter is not taking effect in the tune_model function. Based on the message printed, I can tell.
(2) The tune_model function is failing.

import pandas as pd
data = pd.read_csv('pycaret_downloads.csv')
data['Date'] = pd.to_datetime(data['Date'])# data = data.asfreq('D')
data.set_index('Date', inplace=True, drop=True)

from pycaret.time_series import *
s = setup(data = data['Total'], fh = 14, session_id = 123)

arima = create_model('auto_arima')

tuned_arima = tune_model(arima, n_iter = 50)

Fitting 3 folds for each of 2 candidates, totalling 6 fits
[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.

_RemoteTraceback Traceback (most recent call last)
_RemoteTraceback:
"""
Traceback (most recent call last):
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\joblib\externals\loky\process_executor.py", line 431, in _process_worker
r = call_item()
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\joblib\externals\loky\process_executor.py", line 285, in call
return self.fn(*self.args, **self.kwargs)
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\joblib_parallel_backends.py", line 595, in call
return self.func(*args, **kwargs)
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\joblib\parallel.py", line 262, in call
return [func(*args, **kwargs)
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\joblib\parallel.py", line 262, in
return [func(*args, **kwargs)
File "C:\Users\owner\pycaret\pycaret\internal\pycaret_experiment\time_series_experiment.py", line 284, in _fit_and_score
forecaster.fit(y_train, X_train, **fit_params)
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\sktime\forecasting\base_base.py", line 180, in fit
self._fit(y=y_inner, X=X_inner, fh=fh)
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\sktime\forecasting\base\adapters_pmdarima.py", line 49, in _fit
self.forecaster.fit(y, X=X, **fit_params)
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\pmdarima\arima\auto.py", line 177, in fit
self.model
= auto_arima(
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\pmdarima\arima\auto.py", line 522, in auto_arima
D = nsdiffs(xx, m=m, test=seasonal_test, max_D=max_D,
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\pmdarima\arima\utils.py", line 123, in nsdiffs
dodiff = testfunc(x)
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\pmdarima\arima\seasonality.py", line 592, in estimate_seasonal_differencing_term
stat = self._compute_test_statistic(x)
File "C:\Users\owner\anaconda3\envs\pycaret-ts\lib\site-packages\pmdarima\arima\seasonality.py", line 541, in _compute_test_statistic
raise ValueError("All lag values up to 'maxlag' produced "
ValueError: All lag values up to 'maxlag' produced singular matrices. Consider using a longer series, a different lag term or a different test.
"""

The above exception was the direct cause of the following exception:

ValueError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_16240/1013050410.py in
----> 1 tune_model(arima, n_iter =50)

~\pycaret\pycaret\internal\utils.py in wrapper(*args, **kwargs)
779 if globals_d[name] is None:
780 raise ValueError(message)
--> 781 return func(*args, **kwargs)
782
783 return wrapper

~\pycaret\pycaret\time_series.py in tune_model(estimator, fold, round, n_iter, custom_grid, optimize, custom_scorer, search_algorithm, choose_better, fit_kwargs, return_tuner, verbose, tuner_verbose, **kwargs)
619 """
620
--> 621 return _CURRENT_EXPERIMENT.tune_model(
622 estimator=estimator,
623 fold=fold,

~\pycaret\pycaret\internal\pycaret_experiment\time_series_experiment.py in tune_model(self, estimator, fold, round, n_iter, custom_grid, optimize, custom_scorer, search_algorithm, choose_better, fit_kwargs, return_tuner, verbose, tuner_verbose, display, **kwargs)
1983 )
1984
-> 1985 model_grid.fit(y=data_y, X=data_X, **fit_kwargs)
1986
1987 best_params = model_grid.best_params_

~\pycaret\pycaret\internal\pycaret_experiment\time_series_experiment.py in fit(self, y, X, **fit_params)
416 return results
417
--> 418 self.run_search(evaluate_candidates)
419
420 self.best_index
= results["rank_test_%s" % refit_metric].argmin()

~\pycaret\pycaret\internal\pycaret_experiment\time_series_experiment.py in _run_search(self, evaluate_candidates)
601 def _run_search(self, evaluate_candidates):
602 """Search n_iter candidates from param_distributions"""
--> 603 return evaluate_candidates(
604 ParameterSampler(
605 self.param_distributions, self.n_iter, random_state=self.random_state

~\pycaret\pycaret\internal\pycaret_experiment\time_series_experiment.py in evaluate_candidates(candidate_params)
383 n_jobs=self.n_jobs, verbose=self.verbose, pre_dispatch=self.pre_dispatch
384 )
--> 385 out = parallel(
386 delayed(_fit_and_score)(
387 forecaster=clone(base_forecaster),

~\anaconda3\envs\pycaret-ts\lib\site-packages\joblib\parallel.py in call(self, iterable)
1052
1053 with self._backend.retrieval_context():
-> 1054 self.retrieve()
1055 # Make sure that we get a last message telling us we are done
1056 elapsed_time = time.time() - self._start_time

~\anaconda3\envs\pycaret-ts\lib\site-packages\joblib\parallel.py in retrieve(self)
931 try:
932 if getattr(self._backend, 'supports_timeout', False):
--> 933 self._output.extend(job.get(timeout=self.timeout))
934 else:
935 self._output.extend(job.get())

~\anaconda3\envs\pycaret-ts\lib\site-packages\joblib_parallel_backends.py in wrap_future_result(future, timeout)
540 AsyncResults.get from multiprocessing."""
541 try:
--> 542 return future.result(timeout=timeout)
543 except CfTimeoutError as e:
544 raise TimeoutError from e

~\anaconda3\envs\pycaret-ts\lib\concurrent\futures_base.py in result(self, timeout)
435 raise CancelledError()
436 elif self._state == FINISHED:
--> 437 return self.__get_result()
438
439 self._condition.wait(timeout)

~\anaconda3\envs\pycaret-ts\lib\concurrent\futures_base.py in __get_result(self)
387 if self._exception:
388 try:
--> 389 raise self._exception
390 finally:
391 # Break a reference cycle with the exception in self._exception

ValueError: All lag values up to 'maxlag' produced singular matrices. Consider using a longer series, a different lag term or a different test.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesttime_seriesTopics related to the time series

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions