시작하기무료로 시작하기

max_depth 튜닝

이 연습 문제에서는 각 부스팅 라운드의 트리가 성장할 수 있는 최대 깊이를 결정하는 매개변수인 max_depth를 튜닝해 보겠습니다. 값이 작으면 얕은 트리가, 값이 크면 깊은 트리가 만들어집니다.

이 연습은 강의의 일부입니다

XGBoost로 익히는 Extreme Gradient Boosting

강의 보기

연습 안내

  • max_depths라는 리스트를 만들어 다음 "max_depth" 값들을 저장하세요: 2, 5, 10, 20.
  • for 루프를 사용해 max_depths 리스트를 반복하세요.
  • for 루프의 각 반복에서 "max_depth"를 체계적으로 변화시키고, 얼리 스토핑(5 라운드)이 있는 2-폴드 교차 검증, 부스팅 라운드 10, 평가 지표 "rmse", seed123으로 설정해 실행하세요. 출력은 DataFrame이 되도록 하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Create your housing DMatrix
housing_dmatrix = xgb.DMatrix(data=X,label=y)

# Create the parameter dictionary
params = {"objective":"reg:squarederror"}

# Create list of max_depth values
max_depths = ____
best_rmse = []

# Systematically vary the max_depth
for curr_val in ____:

    params["____"] = ____
    
    # Perform cross-validation
    cv_results = ____
    
    
    
    # Append the final round rmse to best_rmse
    best_rmse.append(cv_results["test-rmse-mean"].tail().values[-1])

# Print the resultant DataFrame
print(pd.DataFrame(list(zip(max_depths, best_rmse)),columns=["max_depth","best_rmse"]))
코드 편집 및 실행