शुरू करेंमुफ़्त में शुरू करें

colsample_bytree ट्यून करना

अब, "colsample_bytree" को ट्यून करने का समय है। अगर आपने पहले scikit-learn के RandomForestClassifier या RandomForestRegressor के साथ काम किया है, तो आपने इसे देखा होगा, जहाँ इसे max_features कहा जाता है। xgboost और sklearn दोनों में, यह पैरामीटर (नाम अलग होने पर भी) किसी दिए गए ट्री में हर स्प्लिट पर चुनने के लिए फीचर्स के अंश को निर्धारित करता है। xgboost में, colsample_bytree को 0 और 1 के बीच के float के रूप में निर्दिष्ट करना होता है.

यह अभ्यास पाठ्यक्रम का हिस्सा है

XGBoost के साथ Extreme Gradient Boosting

पाठ्यक्रम देखें

अभ्यास निर्देश

  • colsample_bytree_vals नाम की एक सूची बनाएँ जिसमें 0.1, 0.5, 0.8, और 1 वैल्यूज़ हों.
  • "colsample_bytree" को क्रमबद्ध तरीके से बदलें और क्रॉस-वैलिडेशन चलाएँ, बिलकुल वैसा ही जैसा आपने पहले max_depth और eta के साथ किया था.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# 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"]))
कोड संपादित करें और चलाएँ