Binary classification using ensemble model

preview_player
Показать описание
Machine learning models:

Data Set:

Ensemble Model Code:
accuracy_ensemble, precision_ensemble, recall_ensemble = {}, {}, {}
models_ensemble = {}

def evaluate(model, X_train, X_val, Y_train, y_val,key):

# Prediction

# Calculate Accuracy, Precision and Recall Metrics
accuracy_ensemble[key]= accuracy_score(predictions, y_val)
precision_ensemble[key] = precision_score(predictions, y_val)
recall_ensemble[key] = recall_score(predictions, y_val)

auc = roc_auc_score(y_val, Y_predict)
print('Classification Report:')
print(classification_report(y_val,predictions,digits=4))

from xgboost import XGBClassifier

tree = XGBClassifier()
models_ensemble['Bagging'] = BaggingClassifier(base_estimator=tree, n_estimators=40, random_state=0)

evaluate(models_ensemble['Bagging'], X_train, X_val, Y_train, Y_val,'Bagging')

models_ensemble['AdaBoostClassifier'] = AdaBoostClassifier(n_estimators=10)
evaluate(models_ensemble['AdaBoostClassifier'], X_train, X_val, Y_train, Y_val,'AdaBoostClassifier')

models_ensemble['Gradient Boost'] = GradientBoostingClassifier(n_estimators=100, random_state=42)
evaluate(models_ensemble['Gradient Boost'], X_train, X_val, Y_train, Y_val,'Gradient Boost')

clf1 = ExtraTreesClassifier()
clf2 = RandomForestClassifier()
clf3 = XGBClassifier()
clf4 = DecisionTreeClassifier()
models_ensemble['Soft Voting'] = VotingClassifier(estimators=[('ExTrees', clf1), ('Random Forest', clf2), ('XGB', clf3),('Decision Tree',clf4)], voting='soft')
evaluate(models_ensemble['Soft Voting'],X_train, X_val, Y_train, Y_val,'Soft Voting')

clf1 = ExtraTreesClassifier()
clf2 = RandomForestClassifier()
clf3 = XGBClassifier()
clf4 = DecisionTreeClassifier()
models_ensemble['Hard Voting'] = VotingClassifier(estimators=[('ExTrees', clf1), ('Random Forest', clf2), ('XGB', clf3),('Decision Tree',clf4)], voting='hard')
evaluate(models_ensemble['Hard Voting'],X_train, X_val, Y_train, Y_val,'Hard Voting')

models_ensemble['Stacked'] = StackingClassifier(estimators=[('m1', models['Xgboost']),
('m2', models['Extra Tree Classifier']), ('m3', models['Random Forest']),('m4',models['Decision Trees'])],final_estimator=LinearSVC())

evaluate(models_ensemble['Stacked'], X_train, X_val, Y_train, Y_val,'Stacked')

import pandas as pd

Рекомендации по теме
Комментарии
Автор

What a great instructor you are! Thanks

AbubakarMahmudSheriff-igcm
Автор

Good one. Please make a Deep learning series as well!

KaleemUllah-qihf
Автор

Really practical approach please keep uploading more . Can you please make some videos explaining the inner workings and math of these ensemble models. Thank you .

ayanmominulislam
Автор

Thank you mam for the great video! Some doubts about feature scaling.
1) Shouldn't we do the feature scaling after train_test split?
2) the code you suggested will do the feature scaling of all the label encoded variables also. Shouldn't we do the feature scaling of only numeric variables?

yashodharpathak
Автор

Superb content ma'am. 👍👍 Keep on sharing such videos

yibenthung
Автор

Very informative video, madam. Can you upload a video related to the non-CSV dataset and make a video related to disease detection using a non-CSV or image dataset?

palurikrishnaveni