我是靠谱客的博主 炙热口红,最近开发中收集的这篇文章主要介绍Kaggle案例精选——电信客户流失预测(Telecom Customer Churn Prediction)Part Four:模型表现对比6 Model Performance:模型表现数据集下载地址:,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

6 Model Performance:模型表现

构建指标计算函数

from sklearn.metrics import f1_score, cohen_kappa_score, precision_recall_curve, average_precision_score

# 设置模型报告表格
def model_report_df(model, training_x, testing_x, training_y, testing_y, name):
    model.fit(training_x, training_y)
    preds = model.predict(testing_x)
    accracy = accuracy_score(testing_y, preds)
    recallscore = recall_score(testing_y, preds)
    precision = precision_score(testing_y, preds)
    roc_auc = roc_auc_score(testing_y, preds)
    f1score = f1_score(testing_y, preds)
    kappa_metric = cohen_kappa_score(testing_y, preds)

    df = pd.DataFrame({
   
        'Model': [name],
        'Accuracy':[accracy],
        'Recall_score':[recallscore],
        'Precision':[precision],
        'F1_score':[f1score],
        'Area_under_curve':[roc_auc],
        'Kappa_metric':[kappa_metric]
    })
    return df

6.1 模型表现指标计算

# 每个模型的输出值计算
model1 = model_report_df(logit, train_X, test_X, train_Y, test_Y,
                         'Logistic Regression(Baseline_model)')
model2 = model_report_df(logit_smote, os_smote_X, test_X, os_smote_Y, test_Y,
                         'Logistic Regression(SMOTE)')
model3 = model_report_df(logit_rfe, train_X, test_X, train_Y, test_Y,
                         'Logistic Regression(RFE)')

DTree = DecisionTreeClassifier(max_depth=9, random_state=123, splitter='best', criterion='gini')
model4 = model_report_df(DTree, train_X, test_X, train_Y, test_Y,
                         'Decision Tree')
model5 = model_report_df(knn, os_smote_X, test_X, os_smote_Y, test_Y,
                         'KNN Classifier')

rfc = RandomForestClassifier(n_estimators=1000, random_state=123, max_depth=9, criterion='gini')
model6 = model_report_df(rfc, train_X, test_X, train_Y, test_Y,
                         'Random Forest Classifier'</

最后

以上就是炙热口红为你收集整理的Kaggle案例精选——电信客户流失预测(Telecom Customer Churn Prediction)Part Four:模型表现对比6 Model Performance:模型表现数据集下载地址:的全部内容,希望文章能够帮你解决Kaggle案例精选——电信客户流失预测(Telecom Customer Churn Prediction)Part Four:模型表现对比6 Model Performance:模型表现数据集下载地址:所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部