0
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix,accuracy_score,accuracy_score,precision_score,recall_score,f1_score
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.ensemble import GradientBoostingClassifier


from sklearn.metrics import roc_curve, roc_auc_score
log1=LogisticRegression()
dt=DecisionTreeClassifier()
rf=RandomForestClassifier()
gb=GradientBoostingClassifier()
extra=ExtraTreesClassifier()
xb=XGBClassifier()
classifiers = [('Logistic Regression',log1), ( 'Decision Tree', dt),
               ('Random Forest',rf),('Gradient Boosting',gb),('Extra Tree classifier',extra)]
for clf_name,clf in classifiers:
    clf.fit(x_train,y_train)
    y_pred=clf.predict(x_test)
    y_pred_proba = clf.predict_proba(x_test)
    accuracy=accuracy_score(y_test,y_pred).round(2)
    precision=precision_score(y_test,y_pred,average='macro').round(2)
    recall=recall_score(y_test,y_pred,average='macro')
    F1_score=f1_score(y_test,y_pred,average='macro').round(2)
    Roc_score=roc_auc_score(y_test, y_pred_proba, multi_class="ovr" ) 
    models_scores_table = pd.DataFrame({clf_name:[accuracy,precision,
                                                  recall,
                                                  F1_score,
                                                  Roc_score]
                                         },
                                       index=['Accuracy', 'Precision', 'Recall', 'F1 Score','roc_auc_score'])


models_scores_table 
models_scores_table  

my output :

    Extra Tree classifier
Accuracy    0.850000
Precision   0.850000
Recall  0.855224
F1 Score    0.850000
roc_auc_score   0.974456
desertnaut
  • 52,940
  • 19
  • 125
  • 157
  • you assign a new DataFrame to models_scores_table in each loop iteration. Instead you want to build it up. For how to doing so, see e.g. https://stackoverflow.com/questions/28056171/how-to-build-and-fill-pandas-dataframe-from-for-loop – JDornheim Mar 14 '22 at 11:52

0 Answers0