Week10 - Colab
Week10 - Colab
DecisionTreeClassifier
param_grid_dt = {
'max_depth': [None, 5, 10],
'min_samples_split': [2, 5, 10],
}
dt_classifier = DecisionTreeClassifier(random_state=42)
grid_search_dt = GridSearchCV(estimator=dt_classifier, param_grid=param_grid_dt, cv=5, n_jobs=-1)
grid_search_dt.fit(X_train, y_train)
best_dt_classifier = grid_search_dt.best_estimator_
y_pred_dt = best_dt_classifier.predict(X_test)
accuracy 1.00 30
macro avg 1.00 1.00 1.00 30
weighted avg 1.00 1.00 1.00 30
[[10 0 0]
[ 0 9 0]
[ 0 0 11]]
Accuracy of Decision Tree Classifier: 1.00%
RandomForestClassifier
param_grid_rf = {
'n_estimators': [10, 50, 100],
'max_depth': [None, 5, 10],
'min_samples_split': [2, 5, 10],
}
rf_classifier = RandomForestClassifier(random_state=42)
grid_search_rf = GridSearchCV(estimator=rf_classifier, param_grid=param_grid_rf, cv=5, n_jobs=-1)
grid_search_rf.fit(X_train, y_train)
best_rf_classifier = grid_search_rf.best_estimator_
y_pred_rf = best_rf_classifier.predict(X_test)
https://colab.research.google.com/drive/1mcEppbuL3E5LEkCmYd6osgwfnL_KCjT8#scrollTo=O3j1q3bTZBX_&printMode=true 1/3
15/10/2024, 16:18 week10 - Colab
accuracy 1.00 30
macro avg 1.00 1.00 1.00 30
weighted avg 1.00 1.00 1.00 30
[[10 0 0]
[ 0 9 0]
[ 0 0 11]]
Accuracy of Random Forest Classifier: 1.00%
BaggingClassifier
param_grid_bagging = {
'n_estimators': [10, 50, 100],
'max_samples': [0.5, 1.0],
'max_features': [0.5, 1.0],
}
bagging_classifier = BaggingClassifier(random_state=42)
grid_search_bagging = GridSearchCV(estimator=bagging_classifier, param_grid=param_grid_bagging, cv=5, n_jobs=-1)
grid_search_bagging.fit(X_train, y_train)
accuracy 1.00 30
macro avg 1.00 1.00 1.00 30
weighted avg 1.00 1.00 1.00 30
[[10 0 0]
[ 0 9 0]
[ 0 0 11]]
Accuracy of Bagging Classifier: 1.00%
GradientBoostingClassifier
param_grid_gb = {
'n_estimators': [50, 100],
'learning_rate': [0.01, 0.1, 0.2],
'max_depth': [3, 5, 7],
}
gb_classifier = GradientBoostingClassifier(random_state=42)
grid_search_gb = GridSearchCV(estimator=gb_classifier, param_grid=param_grid_gb, cv=5, n_jobs=-1)
https://colab.research.google.com/drive/1mcEppbuL3E5LEkCmYd6osgwfnL_KCjT8#scrollTo=O3j1q3bTZBX_&printMode=true 2/3
15/10/2024, 16:18 week10 - Colab
grid_search_gb.fit(X_train, y_train)
accuracy 1.00 30
macro avg 1.00 1.00 1.00 30
weighted avg 1.00 1.00 1.00 30
https://colab.research.google.com/drive/1mcEppbuL3E5LEkCmYd6osgwfnL_KCjT8#scrollTo=O3j1q3bTZBX_&printMode=true 3/3