Skip to content

Commit 9e8bf51

Browse files
Update Part 4 Boosting (Adaboost, GB, SGB)
1 parent d539486 commit 9e8bf51

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Part 4 Boosting (Adaboost, GB, SGB)

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,30 @@ adb_clf_roc_auc_score = roc_auc_score(y_test, y_pred_proba)
3131
# Print adb_clf_roc_auc_score
3232
print('ROC AUC score: {:.2f}'.format(adb_clf_roc_auc_score))
3333

34+
35+
# Gradient Boosting in sklearn
36+
# Import models and utility functions
37+
from sklearn.ensemble import GradientBoostingRegressor
38+
from sklearn.model_selection import train_test_split
39+
from sklearn.metrics import mean_squared_error as MSE
40+
41+
# Set seed for reproducibility
42+
SEED = 1
43+
44+
# Split dataset into 70% train and 30% test
45+
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,random_state=SEED)
46+
47+
# Instantiate a GradientBoostingRegressor 'gbt'
48+
gbt = GradientBoostingRegressor(n_estimators=300, max_depth=1, random_state=SEED)
49+
50+
# Fit 'gbt' to the training set
51+
gbt.fit(X_train, y_train)
52+
53+
# Predict the test set labels
54+
y_pred = gbt.predict(X_test)
55+
56+
# Evaluate the test set RMSE
57+
rmse_test = MSE(y_test, y_pred)**(1/2)
58+
59+
# Print the test set RMSE
60+
print('Test set RMSE: {:.2f}'.format(rmse_test))

0 commit comments

Comments
 (0)