작성
·
109
0
안녕하세요 , 항상 고생많으십니다.
다름이 아니라 , hyperopt 마지막 실습 중에 다음의 코드에서 오류가 발생합니다. hyperopt version도 실습과 같은데, 왜 이런 오류가 발생하는지 몰라서 질문드립니다.
from hyperopt import fmin, tpe, Trials
trial_val = Trials()
best = fmin(fn=objective_func,
space=xgb_search_space,
algo=tpe.suggest,
max_evals=50, # 최대 반복 횟수를 지정합니다.
trials=trial_val, rstate=np.random.default_rng(seed=9))
print('best:', best)
오류문
---------------------------------------------------------------------------
AllTrialsFailed Traceback (most recent call last)
Cell In[21], line 4
1 from hyperopt import fmin, tpe, Trials
3 trial_val = Trials()
----> 4 best = fmin(fn=objective_func,
5 space=xgb_search_space,
6 algo=tpe.suggest,
7 max_evals=50, # 최대 반복 횟수를 지정합니다.
8 trials=trial_val, rstate=np.random.default_rng(seed=9))
9 print('best:', best)
File ~\anaconda3\envs\sklearn_env\lib\site-packages\hyperopt\fmin.py:540, in fmin(fn, space, algo, max_evals, timeout, loss_threshold, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin, points_to_evaluate, max_queue_len, show_progressbar, early_stop_fn, trials_save_file)
537 fn = __objective_fmin_wrapper(fn)
539 if allow_trials_fmin and hasattr(trials, "fmin"):
--> 540 return trials.fmin(
541 fn,
542 space,
543 algo=algo,
544 max_evals=max_evals,
545 timeout=timeout,
546 loss_threshold=loss_threshold,
547 max_queue_len=max_queue_len,
548 rstate=rstate,
549 pass_expr_memo_ctrl=pass_expr_memo_ctrl,
550 verbose=verbose,
551 catch_eval_exceptions=catch_eval_exceptions,
552 return_argmin=return_argmin,
553 show_progressbar=show_progressbar,
554 early_stop_fn=early_stop_fn,
555 trials_save_file=trials_save_file,
556 )
558 if trials is None:
559 if os.path.exists(trials_save_file):
File ~\anaconda3\envs\sklearn_env\lib\site-packages\hyperopt\base.py:671, in Trials.fmin(self, fn, space, algo, max_evals, timeout, loss_threshold, max_queue_len, rstate, verbose, pass_expr_memo_ctrl, catch_eval_exceptions, return_argmin, show_progressbar, early_stop_fn, trials_save_file)
666 # -- Stop-gap implementation!
667 # fmin should have been a Trials method in the first place
668 # but for now it's still sitting in another file.
669 from .fmin import fmin
--> 671 return fmin(
672 fn,
673 space,
674 algo=algo,
675 max_evals=max_evals,
676 timeout=timeout,
677 loss_threshold=loss_threshold,
678 trials=self,
679 rstate=rstate,
680 verbose=verbose,
681 max_queue_len=max_queue_len,
682 allow_trials_fmin=False, # -- prevent recursion
683 pass_expr_memo_ctrl=pass_expr_memo_ctrl,
684 catch_eval_exceptions=catch_eval_exceptions,
685 return_argmin=return_argmin,
686 show_progressbar=show_progressbar,
687 early_stop_fn=early_stop_fn,
688 trials_save_file=trials_save_file,
689 )
File ~\anaconda3\envs\sklearn_env\lib\site-packages\hyperopt\fmin.py:593, in fmin(fn, space, algo, max_evals, timeout, loss_threshold, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin, points_to_evaluate, max_queue_len, show_progressbar, early_stop_fn, trials_save_file)
589 if len(trials.trials) == 0:
590 raise Exception(
591 "There are no evaluation tasks, cannot return argmin of task losses."
592 )
--> 593 return trials.argmin
594 if len(trials) > 0:
595 # Only if there are some successful trail runs, return the best point in
596 # the evaluation space
597 return space_eval(space, trials.argmin)
File ~\anaconda3\envs\sklearn_env\lib\site-packages\hyperopt\base.py:620, in Trials.argmin(self)
618 @property
619 def argmin(self):
--> 620 best_trial = self.best_trial
621 vals = best_trial["misc"]["vals"]
622 # unpack the one-element lists to values
623 # and skip over the 0-element lists
File ~\anaconda3\envs\sklearn_env\lib\site-packages\hyperopt\base.py:611, in Trials.best_trial(self)
605 candidates = [
606 t
607 for t in self.trials
608 if t["result"]["status"] == STATUS_OK and not np.isnan(t["result"]["loss"])
609 ]
610 if not candidates:
--> 611 raise AllTrialsFailed
612 losses = [float(t["result"]["loss"]) for t in candidates]
613 if len(losses) == 0:
AllTrialsFailed:
답변 3
0
0
안녕하십니까,
아래 사항 확인 부탁드립니다.
실습 코드를 변경없이 사용하신건가요? 만약 변경하셨다면 변경된 부분을 여기에 올려봐 주십시요.
사용하시는 scikit learn 버전이 1.0.2 인지 확인 부탁드립니다.
감사합니다.
음, 저는 문제 없이 수행됩니다만,
아래로 numpy와 pandas 버전도 확인 부탁드립니다.
import numpy as np
import pandas as pd
print(np.__version__)
print(pd.__version__)
저는 numpy 1.22.4, pandas 1.3.4 입니다.
0
안녕하세요, 인프런 AI 인턴입니다.
Hyperopt를 사용하면서 “AllTrialsFailed” 오류를 겪고 계시군요. 이 오류는 모든 시도가 실패했을 때 발생합니다. 보통 다음과 같은 이유로 인해 발생하게 됩니다:
objective_func
함수가 올바른 값을 반환하지 않거나, 에러가 발생하고 있습니다. 함수가 반드시 STATUS_OK
와 loss
값을 포함한 dict
를 반환하는지 확인해 주세요. 예시:def objective_func(params):
# 예를 들어, XGBoost의 경우 적절한 loss를 계산하고 반환합니다
loss = 계산된_손실
return {‘loss’: loss, ‘status’: STATUS_OK}
“`
Parameter Space Issues: xgb_search_space
에서 정의한 파라미터의 값이 유효하지 않거나 범위를 벗어날 때도 이런 문제가 발생할 수 있습니다. 파라미터 공간이 적절하게 정의되었는지 점검해 주세요.
환경 문제: 현재 환경에서 필요한 라이브러리의 버전이 맞지 않는 경우에도 문제가 생길 수 있습니다. 사용하신 환경이 hyperopt
, numpy
및 관련 라이브러리의 호환되는 버전을 제공하는지 확인해 보시기 바랍니다.
종속성 문제: 의존하고 있는 다른 라이브러리나 코드에 의한 오류가 있을 수 있습니다. 이러한 경우, objective_func
내에서 다른 코드나 라이브러리 함수에 오류가 있을 수 있어 각 부분의 테스트가 필요합니다.
아래 게시물을 통해 관련된 문제 해결 방법과 비슷한 사례를 확인하실 수 있습니다:
- 최적화 함수 에러: 이 링크에서 비슷한 형태의 오류와 그에 대한 해결 방법을 확인할 수 있습니다.
위의 사항들을 점검한 뒤에도 문제가 지속된다면, 추가적인 코드와 오류 메시지를 공유해 주시면 더욱 상세히 도움 드릴 수 있을 것 같습니다.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.
안녕하세요,
위에서 보시는 것처럼 변경 없이 사용하였고, 실습코드도 그대로 사용하였습니다.
이외에 체크해볼 문제가 있을까요?
감사합니다.