加入收藏 | 设为首页 | 会员中心 | 我要投稿 西安站长网 (https://www.029zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

Python分析信用卡反欺诈!骗我程序员,不存在的

发布时间:2019-10-14 19:31:54 所属栏目:教程 来源:一枚程序媛呀
导读:副标题#e# 前言: 本文研究的是大数据量(284807条数据)下模型选择的问题,也参考了一些文献,但大多不够清晰,因此吐血整理本文,希望对大家有帮助; 本文试着从数据分析师的角度,设想拿到数据该如何寻找规律、选哪种模型来构建反欺诈模型?的角度来分析,以

6.2 随机森林模型

  1. from sklearn.ensemble import RandomForestClassifier 
  2. rfmodel=RandomForestClassifier() 
  3. rfmodel.fit(x_train,y_train) 
  4. #查看模型 
  5. print('rfmodel') 
  6. rfmodel 
  7. rfmodel 
  8. RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini', 
  9.  max_depth=None, max_features='auto', max_leaf_nodes=None, 
  10.  min_impurity_decrease=0.0, min_impurity_split=None, 
  11.  min_samples_leaf=1, min_samples_split=2, 
  12.  min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1, 
  13.  oob_score=False, random_state=None, verbose=0, 
  14.  warm_start=False) 
  15. #查看混淆矩阵 
  16. ypred_rf=rfmodel.predict(x_test) 
  17. print('confusion_matrix') 
  18. print(metrics.confusion_matrix(y_test,ypred_rf)) 
  19. confusion_matrix 
  20. [[85291 4] 
  21.  [ 34 114]] 
  22. #查看分类报告 
  23. print('classification_report') 
  24. print(metrics.classification_report(y_test,ypred_rf)) 
  25. classification_report 
  26.  precision recall f1-score support 
  27.  0 1.00 1.00 1.00 85295 
  28.  1 0.97 0.77 0.86 148 
  29. avg / total 1.00 1.00 1.00 85443 
  30. #查看预测精度与决策覆盖面 
  31. print('Accuracy:%f'%(metrics.accuracy_score(y_test,ypred_rf))) 
  32. print('Area under the curve:%f'%(metrics.roc_auc_score(y_test,ypred_rf))) 
  33. Accuracy:0.999625 
  34. Area under the curve:0.902009 

(编辑:西安站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读