함께하는 데이터 분석

[ML] 여러모델 평가지표 본문

데이터분석 공부/ML | DL

[ML] 여러모델 평가지표

JEONGHEON 2024. 3. 17. 17:25
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.linear_model import LogisticRegression
from xgboost import XGBClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier

rfc = RandomForestClassifier()
dtc = DecisionTreeClassifier()
lrc = LogisticRegression(solver='liblinear')
xgb = XGBClassifier()
nbc = GaussianNB()
knn_4 = KNeighborsClassifier(n_neighbors=4)

model = [rfc, dtc, lrc, xgb, nbc, knn_4]
model_names = ['RandomForest', 'DecisionTree', 'LogisticRegression', 'XGBoost', 'NaiveBayes', '4NN']

from sklearn.metrics import accuracy_score, recall_score, precision_score, f1_score, roc_auc_score

pred = []
for m in model:
    m.fit(X_train, y_train)
    pred.append(m.predict(X_test))

for m, p in zip(model_names, pred):
    print('-----'+m+'-----')
    print('Accuracy:', round(accuracy_score(y_test, p), 4), end = ' / ')
    print('Recall:', round(recall_score(y_test, p), 4), end = ' / ')
    print('Precision:', round(precision_score(y_test, p), 4), end = ' / ')
    print('F1 Score:', round(f1_score(y_test, p), 4), end = ' / ')
    print('ROC AUC Score:', round(roc_auc_score(y_test, p), 4))
    print()

'데이터분석 공부 > ML | DL' 카테고리의 다른 글

[ML] CatBoost  (0) 2023.01.23
[ML] XGBoost  (0) 2023.01.20
[ML] LightGBM  (0) 2023.01.20
[ML] 분류 모델 성능 평가 지표  (0) 2023.01.17
[ML] Gradient Boosting Machine  (0) 2023.01.15