시작하기무료로 시작하기

colsample_bytree 튜닝하기

이제 "colsample_bytree"를 튜닝해 보겠습니다. scikit-learn의 RandomForestClassifierRandomForestRegressor를 써 보셨다면, 이와 같은 개념을 max_features라는 이름으로 보셨을 거예요. xgboostsklearn 모두에서 이 매개변수(이름은 다르지만)는 특정 트리의 각 분기에서 선택할 특징의 비율을 지정합니다. xgboost에서는 colsample_bytree를 0과 1 사이의 부동소수점 값으로 지정해야 합니다.

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

XGBoost로 익히는 Extreme Gradient Boosting

강의 보기

연습 안내

  • 0.1, 0.5, 0.8, 1 값을 담을 리스트 colsample_bytree_vals를 생성하세요.
  • 이전에 max_deptheta로 했던 것과 똑같이 "colsample_bytree"를 체계적으로 변경하면서 교차 검증을 수행하세요.

실습형 인터랙티브 연습

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

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

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

# Create list of hyperparameter values: colsample_bytree_vals
____ = ____
best_rmse = []

# Systematically vary the hyperparameter value 
for curr_val in ____:

    ____ = ____
    
    # Perform cross-validation
    cv_results = xgb.cv(dtrain=housing_dmatrix, params=params, nfold=2,
                 num_boost_round=10, early_stopping_rounds=5,
                 metrics="rmse", as_pandas=True, seed=123)
    
    # 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(colsample_bytree_vals, best_rmse)), columns=["colsample_bytree","best_rmse"]))
코드 편집 및 실행