하이퍼파라미터 개요

Python에서의 하이퍼파라미터 튜닝

Alex Scriven

Data Scientist

하이퍼파라미터란?

하이퍼파라미터:

  • 모델링 전에 사용자가 설정하는 값(옛 라디오의 다이얼처럼)
    • 하이퍼파라미터는 ‘튜닝’합니다!
  • 알고리즘이 스스로 학습하지 않습니다

다이얼이 있는 옛 라디오

Python에서의 하이퍼파라미터 튜닝

랜덤 포레스트의 하이퍼파라미터

간단한 랜덤 포레스트 추정기를 만들고 출력해 봅시다:

rf_clf = RandomForestClassifier()
print(rf_clf)

RandomForestClassifier(n_estimators='warn', criterion='gini', max_depth=None, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, min_samples_leaf=1, min_samples_split=2, min_weight_fraction_leaf=0.0, n_jobs=None, oob_score=False, random_state=None, verbose=0,bootstrap=True, class_weight=None, warm_start=False)

더 알아보기: http://scikit-learn.org

Python에서의 하이퍼파라미터 튜닝

단일 하이퍼파라미터

n_estimators 파라미터를 보겠습니다.

자료형 및 기본값:

n_estimators : integer, optional (default=10)

정의:

The number of trees in the forest.

Python에서의 하이퍼파라미터 튜닝

하이퍼파라미터 설정하기

추정기 생성 시 일부 하이퍼파라미터를 설정합니다:

rf_clf = RandomForestClassifier(n_estimators=100, criterion='entropy')
print(rf_clf)
RandomForestClassifier(n_estimators=100, criterion='entropy',
            max_depth=None, max_features='auto', max_leaf_nodes=None,
            min_impurity_decrease=0.0, min_impurity_split=None,
            min_samples_leaf=1, min_samples_split=2,
            min_weight_fraction_leaf=0.0, n_jobs=None,
            oob_score=False, random_state=None, verbose=0,bootstrap=True,
            class_weight=None, warm_start=False)
Python에서의 하이퍼파라미터 튜닝

로지스틱 회귀의 하이퍼파라미터

로지스틱 회귀의 하이퍼파라미터를 확인합니다:

log_reg_clf = LogisticRegression()

print(log_reg_clf) LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True, intercept_scaling=1, max_iter=100, multi_class='warn', n_jobs=None, penalty='l2', random_state=None, solver='warn', tol=0.0001, verbose=0, warm_start=False)

이 알고리즘은 튜닝할 하이퍼파라미터가 더 적습니다!

Python에서의 하이퍼파라미터 튜닝

하이퍼파라미터 중요도

 

어떤 하이퍼파라미터는 더 중요합니다.

일부는 성능 향상에 도움이 되지 않습니다:

랜덤 포레스트 분류기에서:

  • n_jobs
  • random_state
  • verbose

모든 하이퍼파라미터를 ‘학습’하는 것이 합리적이진 않습니다

Python에서의 하이퍼파라미터 튜닝

랜덤 포레스트: 핵심 하이퍼파라미터

 

중요한 하이퍼파라미터:

  • n_estimators (값을 크게)
  • max_features (여러 값 시도)
  • max_depth & min_sample_leaf (과적합에 중요)
  • (가능하면) criterion

참고: 이는 가이드일 뿐입니다

Python에서의 하이퍼파라미터 튜닝

중요한 하이퍼파라미터를 찾는 방법?

 

학습 자료:

  • 학술 논문
  • 신뢰할 수 있는 블로그·튜토리얼(예: DataCamp)
  • Scikit-learn 모듈 문서
  • 실무 경험
Python에서의 하이퍼파라미터 튜닝

연습해 봅시다!

Python에서의 하이퍼파라미터 튜닝

Preparing Video For Download...