利用R语言预测银行客户信用的优劣(随机森林方法)

我们选取的数据时1994年德国的一家银行在平定客户信用风险好坏的时候用到的一组变量,共有1000组数据。由于年代久远可能和实际有些出入。数据可以在下面的网址下载。 http://archive.ics.uci.edu/ml/datasets/Statlog+(German+Credit+Data)
主要提供了两组数据,一份是原始数据总共有20个变量,另一分时处理过的数值数据,为了寻求更深层次的数据挖掘我们将分别利用者两组数据。
我们首先简单介绍一下变量
变量1
Status of existing checking account 现有的支票账户状态
A11 : … < 0 DM
A12 : 0 <= … < 200 DM
A13 : … >= 200 DM / salary assignments for at least 1 year
A14 : no checking account
变量2: (numerical) 数值变量(这里应该表示的是贷款期限)
Duration in month 月持续时间
变量3: (qualitative) 质量变量信用历史
Credit history 信用记录
A30 : no credits taken/ all credits paid back duly 无信用记录或所有信用都及时偿还
A31 : all credits at this bank paid back duly 这家银行的所有信用都及时偿还
A32 : existing credits paid back duly till now 直到现在有信用及时偿还
A33 : delay in paying off in the past 过去存在延迟支付
A34 : critical account/ other credits existing (not at this bank) 关键账户/在其他银行存在信用记录
变量4: (qualitative) 质量变量
Purpose 贷款目的
A40 : car (new) 新车
A41 : car (used) 旧车
A42 : furniture/equipment 家具/设备
A43 : radio/television 收音机/电视
A44 : domestic appliances 家用电器
A45 : repairs 维修
A46 : education 教育
A47 : (vacation - does not exist ) 空白—不存在
A48 : retraining 再教育
A49 : business 商业
A410 : others 其他
变量5: (numerical) 数值变量
Credit amount 信贷额度
Attibute 6: (qualitative) 质量变量
Savings account/bonds 存款
A61 : … < 100 DM
A62 : 100 <= … < 500 DM
A63 : 500 <= … < 1000 DM
A64 : .. >= 1000 DM
A65 : unknown/ no savings account 未知/无存款
变量7: (qualitative) 质量变量
Present employment since 就业状态
A71 : unemployed 失业
A72 : … < 1 year
A73 : 1 <= … < 4 years
A74 : 4 <= … < 7 years
A75 : .. >= 7 years
变量8: (numerical) 数值变量
Installment rate in percentage of disposable income 分期费率在可支配收入的百分比
变量9: (qualitative)
Personal status and sex 个人状态和性别
A91 : male : divorced/separated 男/离异/分居
A92 : female : divorced/separated/married 女/离异/分居/已婚
A93 : male : single 男/单身
A94 : male : married/widowed 男/已婚/丧偶
A95 : female : single 女/单身
变量10: (qualitative) 质量变量
Other debtors / guarantors 其他债务/担保
A101 : none 无
A102 : co-applicant 共同申请人
A103 : guarantor 担保人
变量11: (numerical)
Present residence since 目前自住宅
变量12: (qualitative)
Property 财产
A121 : real estate 房产
A122 : if not A121 : building society savings agreement/ life insurance 储蓄/

  • 8
    点赞
  • 78
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在R软件中,您可以使用一些评估指标来检验随机森林模型的优劣。下面是一个示例代码: ```R # 假设您已经拟合了一个随机森林模型 model # 预测训练集的结果 train_pred <- predict(model, train_data) # 预测测试集的结果 test_pred <- predict(model, test_data) # 计算训练集的准确率 train_accuracy <- sum(train_pred == train_labels) / length(train_labels) cat("训练集准确率:", train_accuracy, "\n") # 计算测试集的准确率 test_accuracy <- sum(test_pred == test_labels) / length(test_labels) cat("测试集准确率:", test_accuracy, "\n") # 计算训练集的混淆矩阵 train_confusion <- table(train_pred, train_labels) cat("训练集混淆矩阵:\n", train_confusion, "\n") # 计算测试集的混淆矩阵 test_confusion <- table(test_pred, test_labels) cat("测试集混淆矩阵:\n", test_confusion, "\n") # 计算训练集的AUC值(如果是二分类问题) library(pROC) train_auc <- roc(train_labels, train_pred)$auc cat("训练集AUC值:", train_auc, "\n") # 计算测试集的AUC值(如果是二分类问题) test_auc <- roc(test_labels, test_pred)$auc cat("测试集AUC值:", test_auc, "\n") ``` 在上面的代码中,我们首先假设您已经拟合了一个随机森林模型 `model`。然后,使用模型预测训练集和测试集的结果,并计算准确率、混淆矩阵和AUC值等评估指标。 请注意,您需要将代码中的 `train_data`、`train_labels`、`test_data` 和 `test_labels` 替换为实际的训练集和测试集数据。另外,如果您的问题是二分类问题,您可以使用`pROC`包来计算AUC值。如果是多分类问题,您可以考虑使用其他合适的指标进行评估。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值