Python में Tree-Based Models के साथ Machine Learning
Elie Kawerk
Data Scientist
GB एक व्यापक सर्च प्रक्रिया शामिल करता है.
हर CART को बेहतरीन split points और features खोजने के लिए train किया जाता है.
इससे CARTs वही split points और शायद वही features दोहरा सकते हैं.
हर tree को training data की rows के एक random subset पर train किया जाता है.
सैंपल की गई instances (training set का 40%-80%) बिना replacement के ली जाती हैं.
Split points चुनते समय features भी (बिना replacement) sample किए जाते हैं.
परिणाम: ensemble में और विविधता.
प्रभाव: trees के ensemble में और variance जोड़ना.

# Import models and utility functions
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error as MSE
# Set seed for reproducibility
SEED = 1
# Split dataset into 70% train and 30% test
X_train, X_test, y_train, y_test = train_test_split(X,y,
test_size=0.3,
random_state=SEED)
# Instantiate a stochastic GradientBoostingRegressor 'sgbt' sgbt = GradientBoostingRegressor(max_depth=1, subsample=0.8, max_features=0.2, n_estimators=300, random_state=SEED)# Fit 'sgbt' to the training set sgbt.fit(X_train, y_train) # Predict the test set labels y_pred = sgbt.predict(X_test)
# Evaluate test set RMSE 'rmse_test'
rmse_test = MSE(y_test, y_pred)**(1/2)
# Print 'rmse_test'
print('Test set RMSE: {:.2f}'.format(rmse_test))
Test set RMSE: 3.95
Python में Tree-Based Models के साथ Machine Learning