使用KNN模型的意义在于根据已有的信用卡使用意图数据,建立一个分类器,以便对新的信用卡使用意图进行分类预测。该模型的输入为训练集和测试集,输出为分类预测结果和模型评估指标。

代码中,首先定义了一个knn分类器,并在训练集上进行拟合。然后,使用训练好的模型对训练集和测试集进行预测,并计算了预测结果的ROC曲线下面积(ROC score)、分类报告(包括precision、recall、f1-score等指标)和混淆矩阵(confusion matrix)等模型评估指标。

print('****************************************************')
print('Results for model :  KNN')
from sklearn import neighbors
KNN=neighbors.KNeighborsClassifier(n_neighbors=5)
KNN.fit(x_train, y_train)
y_train_pred = KNN.predict(x_train)
y_train_prob = KNN.predict_proba(x_train)[:, 1] 
print('ROC score for train is :', roc_auc_score(y_train, y_train_prob))
print('Classification report for train:
')
print(classification_report(y_train, y_train_pred))
print(confusion_matrix(y_train, y_train_pred))
y_test_pred = KNN.predict(x_test)
y_test_prob = KNN.predict_proba(x_test)[:, 1]
print('ROC score for test is :', roc_auc_score(y_test, y_test_prob))
print('Classification report for test :
')
print(classification_report(y_test, y_test_pred))
print(confusion_matrix(y_test, y_test_pred))

根据结果来看,模型在训练集上的ROC score为0.878,说明该模型的分类效果较好;在测试集上的ROC score为0.710,分类效果稍微下降。同时,从分类报告和混淆矩阵来看,模型对于负样本(即不使用信用卡)的预测效果较好,但对于正样本(即使用信用卡)的预测效果较差,存在一定的误判率。因此,可以考虑对模型进行调参或使用其他分类算法来提高分类效果。

信用卡使用意图预测:KNN模型的应用与评估

原文地址: https://www.cveoy.top/t/topic/fVLU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录