出了点问题;缺少所有 ROC 指标值:
Something is wrong; all the ROC metric values are missing:
我正在使用 caret 包在 R 中训练模型:
ctrl <- trainControl(method = "repeatedcv", repeats = 3, summaryFunction = twoClassSummary)
logitBoostFit <- train(LoanStatus~., credit, method = "LogitBoost", family=binomial, preProcess=c("center", "scale", "pca"),
trControl = ctrl)
我收到以下警告:
Warning message:
In train.default(x, y, weights = w, ...): The metric "Accuracy" was not in the result set. ROC will be used instead.Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : There were missing values in resampled performance measures.
Something is wrong; all the ROC metric values are missing:
ROC Sens Spec
Min. : NA Min. :0.03496 Min. :0.9747
1st Qu.: NA 1st Qu.:0.03919 1st Qu.:0.9758
Median : NA Median :0.04343 Median :0.9770
Mean :NaN Mean :0.04349 Mean :0.9779
3rd Qu.: NA 3rd Qu.:0.04776 3rd Qu.:0.9795
Max. : NA Max. :0.05210 Max. :0.9821
NA's :3
Error in train.default(x, y, weights = w, ...): Stopping
我安装了 pROC 包:
install.packages("pROC", repos="http://cran.rstudio.com/")
library(pROC)
Type 'citation("pROC")' for a citation.
Attaching package: ‘pROC’
The following objects are masked from ‘package:stats’:
cov, smooth, var
这是数据:
str(credit)
'data.frame': 8580 obs. of 45 variables:
$ ListingCategory : int 1 7 3 1 1 7 1 1 1 1 ...
$ IncomeRange : int 3 4 6 4 4 3 3 4 3 3 ...
$ StatedMonthlyIncome : num 2583 4326 10500 4167 5667 ...
$ IncomeVerifiable : logi TRUE TRUE TRUE FALSE TRUE TRUE ...
$ DTIwProsperLoan : num 1.8e-01 2.0e-01 1.7e-01 1.0e+06 1.8e-01 4.4e-01 2.2e-01 2.0e-01 2.0e-01 3.1e-01 ...
$ EmploymentStatusDescription: Factor w/ 7 levels "Employed","Full-time",..: 1 4 1 7 1 1 1 1 1 1 ...
$ Occupation : Factor w/ 65 levels "","Accountant/CPA",..: 37 37 20 14 43 58 48 37 37 37 ...
$ MonthsEmployed : int 4 44 159 67 26 16 209 147 24 9 ...
$ BorrowerState : Factor w/ 48 levels "AK","AL","AR",..: 22 32 5 5 14 28 4 10 10 34 ...
$ BorrowerCity : Factor w/ 3089 levels "AARONSBURG","ABERDEEN",..: 1737 3059 2488 654 482 719 895 1699 2747 1903 ...
$ BorrowerMetropolitanArea : Factor w/ 1 level "(Not Implemented)": 1 1 1 1 1 1 1 1 1 1 ...
$ LenderIndicator : int 0 0 0 1 0 0 0 0 1 0 ...
$ GroupIndicator : logi FALSE FALSE FALSE TRUE FALSE FALSE ...
$ GroupName : Factor w/ 83 levels "","00 Used Car Loans",..: 1 1 1 47 1 1 1 1 1 1 ...
$ ChannelCode : int 90000 90000 90000 80000 40000 40000 90000 90000 80000 90000 ...
$ AmountParticipation : int 0 0 0 0 0 0 0 0 0 0 ...
$ MonthlyDebt : int 247 785 1631 817 644 1524 427 817 654 749 ...
$ CurrentDelinquencies : int 0 0 0 0 0 0 0 1 0 1 ...
$ DelinquenciesLast7Years : int 0 10 0 0 0 0 0 0 0 0 ...
$ PublicRecordsLast10Years : int 0 1 0 0 0 0 1 0 1 0 ...
$ PublicRecordsLast12Months : int 0 0 0 0 0 0 0 0 0 0 ...
$ FirstRecordedCreditLine : Factor w/ 4719 levels "1/1/00 0:00",..: 3032 2673 1197 2541 4698 4345 3150 925 4452 2358 ...
$ CreditLinesLast7Years : int 53 30 36 26 7 22 15 20 34 32 ...
$ InquiriesLast6Months : int 2 8 5 0 0 0 0 3 0 0 ...
$ AmountDelinquent : int 0 0 0 0 0 0 0 63 0 15 ...
$ CurrentCreditLines : int 10 10 18 10 4 11 6 10 7 8 ...
$ OpenCreditLines : int 9 10 15 8 3 8 5 7 7 8 ...
$ BankcardUtilization : num 0.26 0.69 0.94 0.69 0.81 0.38 0.55 0.24 0.03 0 ...
$ TotalOpenRevolvingAccounts : int 9 7 12 10 3 5 4 5 4 6 ...
$ InstallmentBalance : int 48648 14827 0 0 0 30916 0 21619 41340 15447 ...
$ RealEstateBalance : int 0 0 577745 0 0 0 191296 0 0 126039 ...
$ RevolvingBalance : int 5265 9967 94966 50511 37871 22463 19550 2436 1223 3236 ...
$ RealEstatePayment : int 0 0 4159 0 0 0 1303 0 0 1279 ...
$ RevolvingAvailablePercent : int 78 52 36 45 18 61 44 74 96 76 ...
$ TotalInquiries : int 8 11 15 2 0 0 1 7 1 1 ...
$ TotalTradeItems : int 53 30 36 26 7 22 15 20 34 32 ...
$ SatisfactoryAccounts : int 52 23 36 26 7 19 15 18 34 29 ...
$ NowDelinquentDerog : int 0 0 0 0 0 0 0 1 0 1 ...
$ WasDelinquentDerog : int 1 7 0 0 0 3 0 1 0 2 ...
$ OldestTradeOpenDate : int 5092001 5011977 12011984 4272000 9081993 9122000 6161987 11181999 9191990 4132000 ...
$ DelinquenciesOver30Days : int 0 6 0 0 0 13 0 2 0 2 ...
$ DelinquenciesOver60Days : int 0 4 0 0 0 0 0 0 0 1 ...
$ DelinquenciesOver90Days : int 0 10 0 0 0 0 0 0 0 0 ...
$ IsHomeowner : logi FALSE FALSE TRUE FALSE FALSE FALSE ...
$ LoanStatus : Factor w/ 2 levels "0","1": 2 1 1 2 2 2 2 2 2 1 .`..
总结(学分)
上市类别收入范围规定每月收入收入可核实
分钟: 0.000 分钟。 :1.000 分钟。 : 0 模式:逻辑
第一题:1.000 第一题:3.000 第一题:3167 FALSE:784
中位数:2.000 中位数:4.000 中位数:4750 真:7796
平均值:4.997 平均值:4.089 平均值:5755 NA:0
第三题:7.000 第三题:5.000 第三题:7083
最大限度。 :20.000 最大。 :7.000 马克斯。 :250000
DTIwProsperLoan EmploymentStatusDescription MonthsEmployed
分钟: 0.0 就业人数:7182 最少:-23.00
第一学期:0.1 全日制:416 第一学期:26.00
中位数:0.2 未就业:122 中位数:68.00
平均值:91609.4 其他:475 平均值:97.44
第三期:0.3 兼职:7 第三期:139.00
最大限度。 :1000000.0 退休 : 32 最大。 :755.00
自雇人士:346 NA:5
BorrowerState LenderIndicator GroupIndicator ChannelCode
加利福尼亚州:1056 分钟。 :0.00000 模式:逻辑最小值。 :40000
FL : 608 第一曲:0.00000 FALSE:8325 第一曲:80000
纽约:574 中位数:0.00000 真实:255 中位数:80000
TX:532 平均值:0.09196 NA:0 平均值:77196
IL : 443 第三次:0.00000 第三次:90000
GA:343 最大。 :1.00000 最大。 :90000
(其他):5024
每月债务当前拖欠率过去 7 年拖欠率
分钟:0.0 分钟。 : 0.0000 分钟。 : 0.000
第一题:364.0 第一题:0.0000 第一题:0.000
中位数:708.0 中位数:0.0000 中位数:0.000
平均值:885.5 平均值:0.4119 平均值:4.009
第三题:1205.2 第三题:0.0000 第三题:3.000
最大限度。 :30213.0 最大。 :21.0000 最大。 :99.000
PublicRecordsLast10Years PublicRecordsLast12Months CreditLinesLast7Years
分钟: 0.0000 分钟。 :0.00000 分钟。 : 2.0
第一题:0.0000 第一题:0.00000 第一题:16.0
中位数:0.0000 中位数:0.00000 中位数:24.0
平均值:0.2809 平均值:0.01364 平均值:26.1
第三题:0.0000 第三题:0.00000 第三题:34.0
最大限度。 :11.0000 最大。 :4.00000 最大。 :115.0
InquiriesLast6Months AmountDelinquent CurrentCreditLines OpenCreditLines
分钟: 0.0000 分钟。 : 0 分钟: 0.000 分钟。 : 0.000
第一题:0.0000 第一题:0 第一题:5.000 第一题:5.000
中位数:1.0000 中位数:0 中位数:9.000 中位数:8.000
平均值:0.9994 平均值:1195 平均值:9.345 平均值:8.306
第三题:1.0000 第三题:0 第三题:12.000 第三题:11.000
最大限度。 :15.0000 最大。 :179158 最大。 :54.000 马克斯。 :42.000
BankcardUtilization TotalOpenRevolvingAccounts InstallmentBalance
分钟:0.0000 分钟: 0.000 分钟。 : 0
第一题:0.2500 第一题:3.000 第一题:3338
中位数:0.5400 中位数:6.000 中位数:14453
平均值:0.5182 平均值:6.441 平均值:24900
第三曲:0.7900 第三曲:9.000 第三曲:32238
最大限度。 :2.2300 最大。 :44.000 最大。 :739371
NA 的 :328
RealEstateBalance RevolvingBalance RealEstatePayment RevolvingAvailablePercent
分钟: 0 分钟: 0 分钟:0.0 分钟。 : 0.00
第一题:0 第一题:2799 第一题:0.0 第一题:29.00
中位数:26154 中位数:8784 中位数:346.5 中位数:52.00
平均值:109306 平均值:19555 平均值:830.5 平均值:51.46
第三题:176542 第三题:21110 第三题:1382.2 第三题:75.00
最大限度。 :1938421 最大。 :695648 最大。 :13651.0 最大。 :100.00
TotalInquiries TotalTradeItems SatisfactoryAccounts NowDelinquentDerog
分钟:0.00 分钟。 :2.0 分钟。 :1.00 分钟。 : 0.0000
第一题:2.00 第一题:16.0 第一题:14.00 第一题:0.0000
中位数:3.00 中位数:24.0 中位数:21.00 中位数:0.0000
平均值:3.91 平均值:26.1 平均值:23.34 平均值:0.4119
第三题:5.00 第三题:34.0 第三题:30.25 第三题:0.0000
最大限度。 :36.00 最大。 :115.0 最大。 :113.00 马克斯。 :21.0000
WasDelinquentDerog OldestTradeOpenDate 拖欠超过 30 天
分钟: 0.000 分钟。 :1011957 分钟。 : 0.000
第一题:0.000 第一题:4101996 第一题:0.000
中位数:1.000 中位数:7191993 中位数:1.000
平均值:2.343 平均值:6934230 平均值:4.332
第三题:3.000 第三题:10011990 第三题:5.000
最大限度。 :32.000 马克斯。 :12312004 最大。 :99.000
拖欠超过 60 天拖欠超过 90 天是房主贷款状态
分钟: 0.000 分钟。 : 0.000 模式: 逻辑 0:1518
第一题:0.000 第一题:0.000 FALSE:4264 1:7062
中位数:0.000 中位数:0.000 真:4316
平均值:1.908 平均值:4.009 NA:0
第三题:2.000 第三题:3.000
最大限度。 :73.000 马克斯。 :99.000
我没有找到任何缺失值:
try(na.fail(credit))
dput(head(credit,4))
structure(list(ListingCategory = c(1L, 7L, 3L, 1L), IncomeRange = c(3L,
4L, 6L, 4L), StatedMonthlyIncome = c(2583.3333, 4326, 10500,
4166.6667), IncomeVerifiable = c(TRUE, TRUE, TRUE, FALSE), DTIwProsperLoan = c(0.18,
0.2, 0.17, 1e+06), EmploymentStatusDescription = structure(c(1L,
4L, 1L, 7L), .Label = c("Employed", "Full-time", "Not employed",
"Other", "Part-time", "Retired", "Self-employed"), class = "factor"),
MonthsEmployed = c(4L, 44L, 159L, 67L), BorrowerState = structure(c(22L,
32L, 5L, 5L), .Label = c("AK", "AL", "AR", "AZ", "CA", "CO",
"CT", "DC", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "KS",
"KY", "LA", "MA", "MD", "MI", "MN", "MO", "MS", "MT", "NC",
"NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA",
"RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI",
"WV", "WY"), class = "factor"), LenderIndicator = c(0L, 0L,
0L, 1L), GroupIndicator = c(FALSE, FALSE, FALSE, TRUE), ChannelCode = c(90000L,
90000L, 90000L, 80000L), MonthlyDebt = c(247L, 785L, 1631L,
817L), CurrentDelinquencies = c(0L, 0L, 0L, 0L), DelinquenciesLast7Years = c(0L,
10L, 0L, 0L), PublicRecordsLast10Years = c(0L, 1L, 0L, 0L
), PublicRecordsLast12Months = c(0L, 0L, 0L, 0L), CreditLinesLast7Years = c(53L,
30L, 36L, 26L), InquiriesLast6Months = c(2L, 8L, 5L, 0L),
AmountDelinquent = c(0L, 0L, 0L, 0L), CurrentCreditLines = c(10L,
10L, 18L, 10L), OpenCreditLines = c(9L, 10L, 15L, 8L), BankcardUtilization = c(0.26,
0.69, 0.94, 0.69), TotalOpenRevolvingAccounts = c(9L, 7L,
12L, 10L), InstallmentBalance = c(48648L, 14827L, 0L, 0L),
RealEstateBalance = c(0L, 0L, 577745L, 0L), RevolvingBalance = c(5265L,
9967L, 94966L, 50511L), RealEstatePayment = c(0L, 0L, 4159L,
0L), RevolvingAvailablePercent = c(78L, 52L, 36L, 45L), TotalInquiries = c(8L,
11L, 15L, 2L), TotalTradeItems = c(53L, 30L, 36L, 26L), SatisfactoryAccounts = c(52L,
23L, 36L, 26L), NowDelinquentDerog = c(0L, 0L, 0L, 0L), WasDelinquentDerog = c(1L,
7L, 0L, 0L), OldestTradeOpenDate = c(5092001L, 5011977L,
12011984L, 4272000L), DelinquenciesOver30Days = c(0L, 6L,
0L, 0L), DelinquenciesOver60Days = c(0L, 4L, 0L, 0L), DelinquenciesOver90Days = c(0L,
10L, 0L, 0L), IsHomeowner = c(FALSE, FALSE, TRUE, FALSE),
LoanStatus = structure(c(2L, 1L, 1L, 2L), .Label = c("0",
"1"), class = "factor")), .Names = c("ListingCategory", "IncomeRange",
"StatedMonthlyIncome", "IncomeVerifiable", "DTIwProsperLoan",
"EmploymentStatusDescription", "MonthsEmployed", "BorrowerState",
"LenderIndicator", "GroupIndicator", "ChannelCode", "MonthlyDebt",
"CurrentDelinquencies", "DelinquenciesLast7Years", "PublicRecordsLast10Years",
"PublicRecordsLast12Months", "CreditLinesLast7Years", "InquiriesLast6Months",
"AmountDelinquent", "CurrentCreditLines", "OpenCreditLines",
"BankcardUtilization", "TotalOpenRevolvingAccounts", "InstallmentBalance",
"RealEstateBalance", "RevolvingBalance", "RealEstatePayment",
"RevolvingAvailablePercent", "TotalInquiries", "TotalTradeItems",
"SatisfactoryAccounts", "NowDelinquentDerog", "WasDelinquentDerog",
"OldestTradeOpenDate", "DelinquenciesOver30Days", "DelinquenciesOver60Days",
"DelinquenciesOver90Days", "IsHomeowner", "LoanStatus"), row.names = c(NA,
4L), class = "data.frame")
有什么问题吗?
Warning message:
In train.default(x, y, weights = w, ...): The metric "Accuracy" was not in the result set. ROC will be used instead.
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3540.667624
iter 20 value 3329.692768
iter 30 value 3279.191024
iter 40 value 3264.926986
iter 50 value 3259.276647
iter 60 value 3259.056261
final value 3259.032668
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3540.774666
iter 20 value 3330.016829
iter 30 value 3279.545595
iter 40 value 3265.384385
iter 50 value 3259.499032
iter 60 value 3259.353010
final value 3259.342601
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3540.667731
iter 20 value 3329.693092
iter 30 value 3279.191379
iter 40 value 3264.927427
iter 50 value 3259.276899
iter 60 value 3259.056561
final value 3259.032978
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3528.401458
iter 20 value 3314.932958
iter 30 value 3264.117072
iter 40 value 3253.780051
iter 50 value 3253.368959
iter 60 value 3253.359047
final value 3253.358819
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3528.508505
iter 20 value 3315.134599
iter 30 value 3265.021404
iter 40 value 3255.739021
iter 50 value 3253.817833
iter 60 value 3253.697180
final value 3253.671003
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3528.401565
iter 20 value 3314.933160
iter 30 value 3264.117768
iter 40 value 3253.780539
iter 50 value 3253.369030
iter 60 value 3253.359358
final value 3253.359133
converged
# weights: 71 (70 variable)
initial value 5145.231521
iter 10 value 4680.326236
iter 20 value 4672.506024
iter 30 value 3662.998233
iter 40 value 3310.207744
iter 50 value 3252.983656
iter 60 value 3250.400275
iter 70 value 3250.339216
final value 3250.332646
converged
... # 权重:72(71 变量)
初始值 5144.538374
iter 10 值 4661.569290
iter 20 值 4652.246624
iter 30 值 3715.472355
iter 40 值 3484.096833
iter 50 值 3254.247424
iter 60 值 3248.931841
iter 70 值 3248.154679
iter 80 值 3248.129089
iter 80 值 3248.129085
终值 3248.128574
会聚
# 权重:72(71 个变量)
初始值 5144.538374
iter 10 值 4663.660886
iter 20 值 4654.255466
iter 30 值 3542.473235
iter 40 值 3315.027437
iter 50 值 3250.340679
iter 60 值 3248.693378
iter 70 值 3248.455840
iter 80 值 3248.443345
iter 80 值 3248.443325
iter 80 值 3248.443325
最终价值 3248.443325
会聚
# 权重:72(71 个变量)
初始值 5144.538374
iter 10 值 4661.571382
iter 20 值 4652.248711
iter 30 值 4397.069608
iter 40 值 3532.067046
iter 50 值 3283.179445
iter 60 值 3249.518694
iter 70 值 3248.163057
iter 80 值 3248.129552
终值 3248.128889
会聚
警告信息:
在 nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : 重新采样的性能度量中存在缺失值。
出了点问题;缺少所有 ROC 指标值:
ROC Sens 规范
分钟: 不适用:0.01805分钟。 :0.9946
第一题:NA 第一题:0.01805 第一题:0.9946
中位数:NA 中位数:0.01805 中位数:0.9946
平均值:NaN 平均值:0.01805 平均值:0.9946
第三题:NA 第三题:0.01805 第三题:0.9946
最大限度。 : 不适用:0.01805 最大。 :0.9946
NA 的 :3
train.default(x, y, weights = w, ...) 中的错误:停止
summaryFunction = twoClassSummary 出现触发警告。
它也发生在这里:
ctrl <- trainControl(method = "cv", summaryFunction = twoClassSummary)
multinomSummaryFit <- train(LoanStatus~., credit, method = "multinom", family=binomial,
trControl = ctrl)
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : There were missing values in resampled performance measures.
Something is wrong; all the ROC metric values are missing:
ROC Sens Spec
Min. : NA Min. :0.01919 Min. :0.9941
1st Qu.: NA 1st Qu.:0.01988 1st Qu.:0.9942
Median : NA Median :0.02056 Median :0.9943
Mean :NaN Mean :0.02011 Mean :0.9943
3rd Qu.: NA 3rd Qu.:0.02056 3rd Qu.:0.9943
Max. : NA Max. :0.02057 Max. :0.9944
NA's :3
Error in train.default(x, y, weights = w, ...): Stopping
尝试将 class 变量值从“0”、“1”更改为例如"A" , "B" 然后试试。
查看summary(credit)
的输出,可以看出至少有两个变量有NA
个值;
变量 MonthsEmployed
有 5 NA
个值:
MonthsEmployed
Min. :-23.00
1st Qu.: 26.00
Median : 68.00
Mean : 97.44
3rd Qu.:139.00
Max. :755.00
NA's :5
并且变量 InstallmentBalance
有 328 NA
个值。
InstallmentBalance
Min. : 0
1st Qu.: 3338
Median : 14453
Mean : 24900
3rd Qu.: 32238
Max. :739371
NA's :328
尝试删除具有缺失值的行(或临时删除这两个变量)并再次 运行 该函数以查看是否可以解决您的问题。
另外,使用twoClassSummary
时,需要在train
函数中添加metric = "ROC"
,在trainControl()
中添加classProbs = TRUE
ctrl <- trainControl(method = "repeatedcv",
repeats = 3,
classProbs = TRUE,
summaryFunction = twoClassSummary) .
所以,你的电话应该是
multinomSummaryFit <- train(LoanStatus~.,
data = credit,
method = "multinom",
family=binomial,
metric = "ROC",
trControl = ctrl)
关于数据集的另一个重要问题是,您需要仔细检查变量的值并确保每个值都有意义。例如,MonthsEmployed
变量具有负值。从逻辑上讲,雇员的受雇月数是正数。这些负值是错误的还是有其他含义! (例如,值 -23 表示此人已 23 个月未受雇)。
回答关于 confusionMatrix
的问题:
假设您的训练模型名为 multinomSummaryFit
。为了在测试数据集上评估你的模型,你需要在没有 LoanStatus
的情况下对测试数据集调用 predict
方法(使用你训练模型的相同变量),然后将你的模型预测与LoanStatus
中的实际值。例如,
#let's say your test datafrme is called test
mymodel_pred <- predict(multinomSummaryFit, test[, names(test) != "LoanStatus"])
然后使用 confusionMatrix
:
confusionMatrix(data = mymodel_pred,
reference = test$LoanStatus,
positive = "Default")
如果测试数据集没有 LoanStatus
列,那么您只需使用:
mymodel_pred <- predict(multinomSummaryFit, test)
但在这种情况下,如果您不知道实际响应,则无法在测试数据集上评估模型。
请记住,如果您从训练数据集中删除了任何变量,则需要在调用 predict
之前也从测试数据集中删除它们
使用分层抽样拆分数据进行训练和测试:
trainingRows <- createDataPartition(credit$LoanStatus, p = .70, list= FALSE)
train <- credit[trainingRows, ]
test <- credit[-trainingRows, ]
我在一些数据上遇到了类似的问题,我使用选项 "summaryFunction = twoClassSummary" 来获得一些输出性能指标,而一些数据特征的 sd() 等于 1。
我通过排除 "twoClassSummary" 并在接下来的步骤中计算我需要的性能指标(例如 ROC、CM)解决了这个问题。
我正在使用 caret 包在 R 中训练模型:
ctrl <- trainControl(method = "repeatedcv", repeats = 3, summaryFunction = twoClassSummary)
logitBoostFit <- train(LoanStatus~., credit, method = "LogitBoost", family=binomial, preProcess=c("center", "scale", "pca"),
trControl = ctrl)
我收到以下警告:
Warning message:
In train.default(x, y, weights = w, ...): The metric "Accuracy" was not in the result set. ROC will be used instead.Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : There were missing values in resampled performance measures.
Something is wrong; all the ROC metric values are missing:
ROC Sens Spec
Min. : NA Min. :0.03496 Min. :0.9747
1st Qu.: NA 1st Qu.:0.03919 1st Qu.:0.9758
Median : NA Median :0.04343 Median :0.9770
Mean :NaN Mean :0.04349 Mean :0.9779
3rd Qu.: NA 3rd Qu.:0.04776 3rd Qu.:0.9795
Max. : NA Max. :0.05210 Max. :0.9821
NA's :3
Error in train.default(x, y, weights = w, ...): Stopping
我安装了 pROC 包:
install.packages("pROC", repos="http://cran.rstudio.com/")
library(pROC)
Type 'citation("pROC")' for a citation.
Attaching package: ‘pROC’
The following objects are masked from ‘package:stats’:
cov, smooth, var
这是数据:
str(credit)
'data.frame': 8580 obs. of 45 variables:
$ ListingCategory : int 1 7 3 1 1 7 1 1 1 1 ...
$ IncomeRange : int 3 4 6 4 4 3 3 4 3 3 ...
$ StatedMonthlyIncome : num 2583 4326 10500 4167 5667 ...
$ IncomeVerifiable : logi TRUE TRUE TRUE FALSE TRUE TRUE ...
$ DTIwProsperLoan : num 1.8e-01 2.0e-01 1.7e-01 1.0e+06 1.8e-01 4.4e-01 2.2e-01 2.0e-01 2.0e-01 3.1e-01 ...
$ EmploymentStatusDescription: Factor w/ 7 levels "Employed","Full-time",..: 1 4 1 7 1 1 1 1 1 1 ...
$ Occupation : Factor w/ 65 levels "","Accountant/CPA",..: 37 37 20 14 43 58 48 37 37 37 ...
$ MonthsEmployed : int 4 44 159 67 26 16 209 147 24 9 ...
$ BorrowerState : Factor w/ 48 levels "AK","AL","AR",..: 22 32 5 5 14 28 4 10 10 34 ...
$ BorrowerCity : Factor w/ 3089 levels "AARONSBURG","ABERDEEN",..: 1737 3059 2488 654 482 719 895 1699 2747 1903 ...
$ BorrowerMetropolitanArea : Factor w/ 1 level "(Not Implemented)": 1 1 1 1 1 1 1 1 1 1 ...
$ LenderIndicator : int 0 0 0 1 0 0 0 0 1 0 ...
$ GroupIndicator : logi FALSE FALSE FALSE TRUE FALSE FALSE ...
$ GroupName : Factor w/ 83 levels "","00 Used Car Loans",..: 1 1 1 47 1 1 1 1 1 1 ...
$ ChannelCode : int 90000 90000 90000 80000 40000 40000 90000 90000 80000 90000 ...
$ AmountParticipation : int 0 0 0 0 0 0 0 0 0 0 ...
$ MonthlyDebt : int 247 785 1631 817 644 1524 427 817 654 749 ...
$ CurrentDelinquencies : int 0 0 0 0 0 0 0 1 0 1 ...
$ DelinquenciesLast7Years : int 0 10 0 0 0 0 0 0 0 0 ...
$ PublicRecordsLast10Years : int 0 1 0 0 0 0 1 0 1 0 ...
$ PublicRecordsLast12Months : int 0 0 0 0 0 0 0 0 0 0 ...
$ FirstRecordedCreditLine : Factor w/ 4719 levels "1/1/00 0:00",..: 3032 2673 1197 2541 4698 4345 3150 925 4452 2358 ...
$ CreditLinesLast7Years : int 53 30 36 26 7 22 15 20 34 32 ...
$ InquiriesLast6Months : int 2 8 5 0 0 0 0 3 0 0 ...
$ AmountDelinquent : int 0 0 0 0 0 0 0 63 0 15 ...
$ CurrentCreditLines : int 10 10 18 10 4 11 6 10 7 8 ...
$ OpenCreditLines : int 9 10 15 8 3 8 5 7 7 8 ...
$ BankcardUtilization : num 0.26 0.69 0.94 0.69 0.81 0.38 0.55 0.24 0.03 0 ...
$ TotalOpenRevolvingAccounts : int 9 7 12 10 3 5 4 5 4 6 ...
$ InstallmentBalance : int 48648 14827 0 0 0 30916 0 21619 41340 15447 ...
$ RealEstateBalance : int 0 0 577745 0 0 0 191296 0 0 126039 ...
$ RevolvingBalance : int 5265 9967 94966 50511 37871 22463 19550 2436 1223 3236 ...
$ RealEstatePayment : int 0 0 4159 0 0 0 1303 0 0 1279 ...
$ RevolvingAvailablePercent : int 78 52 36 45 18 61 44 74 96 76 ...
$ TotalInquiries : int 8 11 15 2 0 0 1 7 1 1 ...
$ TotalTradeItems : int 53 30 36 26 7 22 15 20 34 32 ...
$ SatisfactoryAccounts : int 52 23 36 26 7 19 15 18 34 29 ...
$ NowDelinquentDerog : int 0 0 0 0 0 0 0 1 0 1 ...
$ WasDelinquentDerog : int 1 7 0 0 0 3 0 1 0 2 ...
$ OldestTradeOpenDate : int 5092001 5011977 12011984 4272000 9081993 9122000 6161987 11181999 9191990 4132000 ...
$ DelinquenciesOver30Days : int 0 6 0 0 0 13 0 2 0 2 ...
$ DelinquenciesOver60Days : int 0 4 0 0 0 0 0 0 0 1 ...
$ DelinquenciesOver90Days : int 0 10 0 0 0 0 0 0 0 0 ...
$ IsHomeowner : logi FALSE FALSE TRUE FALSE FALSE FALSE ...
$ LoanStatus : Factor w/ 2 levels "0","1": 2 1 1 2 2 2 2 2 2 1 .`..
总结(学分)
上市类别收入范围规定每月收入收入可核实
分钟: 0.000 分钟。 :1.000 分钟。 : 0 模式:逻辑
第一题:1.000 第一题:3.000 第一题:3167 FALSE:784
中位数:2.000 中位数:4.000 中位数:4750 真:7796
平均值:4.997 平均值:4.089 平均值:5755 NA:0
第三题:7.000 第三题:5.000 第三题:7083
最大限度。 :20.000 最大。 :7.000 马克斯。 :250000
DTIwProsperLoan EmploymentStatusDescription MonthsEmployed
分钟: 0.0 就业人数:7182 最少:-23.00
第一学期:0.1 全日制:416 第一学期:26.00
中位数:0.2 未就业:122 中位数:68.00
平均值:91609.4 其他:475 平均值:97.44
第三期:0.3 兼职:7 第三期:139.00
最大限度。 :1000000.0 退休 : 32 最大。 :755.00
自雇人士:346 NA:5
BorrowerState LenderIndicator GroupIndicator ChannelCode
加利福尼亚州:1056 分钟。 :0.00000 模式:逻辑最小值。 :40000
FL : 608 第一曲:0.00000 FALSE:8325 第一曲:80000
纽约:574 中位数:0.00000 真实:255 中位数:80000
TX:532 平均值:0.09196 NA:0 平均值:77196
IL : 443 第三次:0.00000 第三次:90000
GA:343 最大。 :1.00000 最大。 :90000
(其他):5024
每月债务当前拖欠率过去 7 年拖欠率
分钟:0.0 分钟。 : 0.0000 分钟。 : 0.000
第一题:364.0 第一题:0.0000 第一题:0.000
中位数:708.0 中位数:0.0000 中位数:0.000
平均值:885.5 平均值:0.4119 平均值:4.009
第三题:1205.2 第三题:0.0000 第三题:3.000
最大限度。 :30213.0 最大。 :21.0000 最大。 :99.000
PublicRecordsLast10Years PublicRecordsLast12Months CreditLinesLast7Years
分钟: 0.0000 分钟。 :0.00000 分钟。 : 2.0
第一题:0.0000 第一题:0.00000 第一题:16.0
中位数:0.0000 中位数:0.00000 中位数:24.0
平均值:0.2809 平均值:0.01364 平均值:26.1
第三题:0.0000 第三题:0.00000 第三题:34.0
最大限度。 :11.0000 最大。 :4.00000 最大。 :115.0
InquiriesLast6Months AmountDelinquent CurrentCreditLines OpenCreditLines
分钟: 0.0000 分钟。 : 0 分钟: 0.000 分钟。 : 0.000
第一题:0.0000 第一题:0 第一题:5.000 第一题:5.000
中位数:1.0000 中位数:0 中位数:9.000 中位数:8.000
平均值:0.9994 平均值:1195 平均值:9.345 平均值:8.306
第三题:1.0000 第三题:0 第三题:12.000 第三题:11.000
最大限度。 :15.0000 最大。 :179158 最大。 :54.000 马克斯。 :42.000
BankcardUtilization TotalOpenRevolvingAccounts InstallmentBalance
分钟:0.0000 分钟: 0.000 分钟。 : 0
第一题:0.2500 第一题:3.000 第一题:3338
中位数:0.5400 中位数:6.000 中位数:14453
平均值:0.5182 平均值:6.441 平均值:24900
第三曲:0.7900 第三曲:9.000 第三曲:32238
最大限度。 :2.2300 最大。 :44.000 最大。 :739371
NA 的 :328
RealEstateBalance RevolvingBalance RealEstatePayment RevolvingAvailablePercent
分钟: 0 分钟: 0 分钟:0.0 分钟。 : 0.00
第一题:0 第一题:2799 第一题:0.0 第一题:29.00
中位数:26154 中位数:8784 中位数:346.5 中位数:52.00
平均值:109306 平均值:19555 平均值:830.5 平均值:51.46
第三题:176542 第三题:21110 第三题:1382.2 第三题:75.00
最大限度。 :1938421 最大。 :695648 最大。 :13651.0 最大。 :100.00
TotalInquiries TotalTradeItems SatisfactoryAccounts NowDelinquentDerog
分钟:0.00 分钟。 :2.0 分钟。 :1.00 分钟。 : 0.0000
第一题:2.00 第一题:16.0 第一题:14.00 第一题:0.0000
中位数:3.00 中位数:24.0 中位数:21.00 中位数:0.0000
平均值:3.91 平均值:26.1 平均值:23.34 平均值:0.4119
第三题:5.00 第三题:34.0 第三题:30.25 第三题:0.0000
最大限度。 :36.00 最大。 :115.0 最大。 :113.00 马克斯。 :21.0000
WasDelinquentDerog OldestTradeOpenDate 拖欠超过 30 天
分钟: 0.000 分钟。 :1011957 分钟。 : 0.000
第一题:0.000 第一题:4101996 第一题:0.000
中位数:1.000 中位数:7191993 中位数:1.000
平均值:2.343 平均值:6934230 平均值:4.332
第三题:3.000 第三题:10011990 第三题:5.000
最大限度。 :32.000 马克斯。 :12312004 最大。 :99.000
拖欠超过 60 天拖欠超过 90 天是房主贷款状态
分钟: 0.000 分钟。 : 0.000 模式: 逻辑 0:1518
第一题:0.000 第一题:0.000 FALSE:4264 1:7062
中位数:0.000 中位数:0.000 真:4316
平均值:1.908 平均值:4.009 NA:0
第三题:2.000 第三题:3.000
最大限度。 :73.000 马克斯。 :99.000
我没有找到任何缺失值:
try(na.fail(credit))
dput(head(credit,4))
structure(list(ListingCategory = c(1L, 7L, 3L, 1L), IncomeRange = c(3L,
4L, 6L, 4L), StatedMonthlyIncome = c(2583.3333, 4326, 10500,
4166.6667), IncomeVerifiable = c(TRUE, TRUE, TRUE, FALSE), DTIwProsperLoan = c(0.18,
0.2, 0.17, 1e+06), EmploymentStatusDescription = structure(c(1L,
4L, 1L, 7L), .Label = c("Employed", "Full-time", "Not employed",
"Other", "Part-time", "Retired", "Self-employed"), class = "factor"),
MonthsEmployed = c(4L, 44L, 159L, 67L), BorrowerState = structure(c(22L,
32L, 5L, 5L), .Label = c("AK", "AL", "AR", "AZ", "CA", "CO",
"CT", "DC", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "KS",
"KY", "LA", "MA", "MD", "MI", "MN", "MO", "MS", "MT", "NC",
"NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA",
"RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI",
"WV", "WY"), class = "factor"), LenderIndicator = c(0L, 0L,
0L, 1L), GroupIndicator = c(FALSE, FALSE, FALSE, TRUE), ChannelCode = c(90000L,
90000L, 90000L, 80000L), MonthlyDebt = c(247L, 785L, 1631L,
817L), CurrentDelinquencies = c(0L, 0L, 0L, 0L), DelinquenciesLast7Years = c(0L,
10L, 0L, 0L), PublicRecordsLast10Years = c(0L, 1L, 0L, 0L
), PublicRecordsLast12Months = c(0L, 0L, 0L, 0L), CreditLinesLast7Years = c(53L,
30L, 36L, 26L), InquiriesLast6Months = c(2L, 8L, 5L, 0L),
AmountDelinquent = c(0L, 0L, 0L, 0L), CurrentCreditLines = c(10L,
10L, 18L, 10L), OpenCreditLines = c(9L, 10L, 15L, 8L), BankcardUtilization = c(0.26,
0.69, 0.94, 0.69), TotalOpenRevolvingAccounts = c(9L, 7L,
12L, 10L), InstallmentBalance = c(48648L, 14827L, 0L, 0L),
RealEstateBalance = c(0L, 0L, 577745L, 0L), RevolvingBalance = c(5265L,
9967L, 94966L, 50511L), RealEstatePayment = c(0L, 0L, 4159L,
0L), RevolvingAvailablePercent = c(78L, 52L, 36L, 45L), TotalInquiries = c(8L,
11L, 15L, 2L), TotalTradeItems = c(53L, 30L, 36L, 26L), SatisfactoryAccounts = c(52L,
23L, 36L, 26L), NowDelinquentDerog = c(0L, 0L, 0L, 0L), WasDelinquentDerog = c(1L,
7L, 0L, 0L), OldestTradeOpenDate = c(5092001L, 5011977L,
12011984L, 4272000L), DelinquenciesOver30Days = c(0L, 6L,
0L, 0L), DelinquenciesOver60Days = c(0L, 4L, 0L, 0L), DelinquenciesOver90Days = c(0L,
10L, 0L, 0L), IsHomeowner = c(FALSE, FALSE, TRUE, FALSE),
LoanStatus = structure(c(2L, 1L, 1L, 2L), .Label = c("0",
"1"), class = "factor")), .Names = c("ListingCategory", "IncomeRange",
"StatedMonthlyIncome", "IncomeVerifiable", "DTIwProsperLoan",
"EmploymentStatusDescription", "MonthsEmployed", "BorrowerState",
"LenderIndicator", "GroupIndicator", "ChannelCode", "MonthlyDebt",
"CurrentDelinquencies", "DelinquenciesLast7Years", "PublicRecordsLast10Years",
"PublicRecordsLast12Months", "CreditLinesLast7Years", "InquiriesLast6Months",
"AmountDelinquent", "CurrentCreditLines", "OpenCreditLines",
"BankcardUtilization", "TotalOpenRevolvingAccounts", "InstallmentBalance",
"RealEstateBalance", "RevolvingBalance", "RealEstatePayment",
"RevolvingAvailablePercent", "TotalInquiries", "TotalTradeItems",
"SatisfactoryAccounts", "NowDelinquentDerog", "WasDelinquentDerog",
"OldestTradeOpenDate", "DelinquenciesOver30Days", "DelinquenciesOver60Days",
"DelinquenciesOver90Days", "IsHomeowner", "LoanStatus"), row.names = c(NA,
4L), class = "data.frame")
有什么问题吗?
Warning message:
In train.default(x, y, weights = w, ...): The metric "Accuracy" was not in the result set. ROC will be used instead.
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3540.667624
iter 20 value 3329.692768
iter 30 value 3279.191024
iter 40 value 3264.926986
iter 50 value 3259.276647
iter 60 value 3259.056261
final value 3259.032668
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3540.774666
iter 20 value 3330.016829
iter 30 value 3279.545595
iter 40 value 3265.384385
iter 50 value 3259.499032
iter 60 value 3259.353010
final value 3259.342601
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3540.667731
iter 20 value 3329.693092
iter 30 value 3279.191379
iter 40 value 3264.927427
iter 50 value 3259.276899
iter 60 value 3259.056561
final value 3259.032978
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3528.401458
iter 20 value 3314.932958
iter 30 value 3264.117072
iter 40 value 3253.780051
iter 50 value 3253.368959
iter 60 value 3253.359047
final value 3253.358819
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3528.508505
iter 20 value 3315.134599
iter 30 value 3265.021404
iter 40 value 3255.739021
iter 50 value 3253.817833
iter 60 value 3253.697180
final value 3253.671003
converged
# weights: 72 (71 variable)
initial value 5144.538374
iter 10 value 3528.401565
iter 20 value 3314.933160
iter 30 value 3264.117768
iter 40 value 3253.780539
iter 50 value 3253.369030
iter 60 value 3253.359358
final value 3253.359133
converged
# weights: 71 (70 variable)
initial value 5145.231521
iter 10 value 4680.326236
iter 20 value 4672.506024
iter 30 value 3662.998233
iter 40 value 3310.207744
iter 50 value 3252.983656
iter 60 value 3250.400275
iter 70 value 3250.339216
final value 3250.332646
converged
... # 权重:72(71 变量)
初始值 5144.538374
iter 10 值 4661.569290
iter 20 值 4652.246624
iter 30 值 3715.472355
iter 40 值 3484.096833
iter 50 值 3254.247424
iter 60 值 3248.931841
iter 70 值 3248.154679
iter 80 值 3248.129089
iter 80 值 3248.129085
终值 3248.128574
会聚
# 权重:72(71 个变量)
初始值 5144.538374
iter 10 值 4663.660886
iter 20 值 4654.255466
iter 30 值 3542.473235
iter 40 值 3315.027437
iter 50 值 3250.340679
iter 60 值 3248.693378
iter 70 值 3248.455840
iter 80 值 3248.443345
iter 80 值 3248.443325
iter 80 值 3248.443325
最终价值 3248.443325
会聚
# 权重:72(71 个变量)
初始值 5144.538374
iter 10 值 4661.571382
iter 20 值 4652.248711
iter 30 值 4397.069608
iter 40 值 3532.067046
iter 50 值 3283.179445
iter 60 值 3249.518694
iter 70 值 3248.163057
iter 80 值 3248.129552
终值 3248.128889
会聚
警告信息:
在 nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : 重新采样的性能度量中存在缺失值。
出了点问题;缺少所有 ROC 指标值:
ROC Sens 规范
分钟: 不适用:0.01805分钟。 :0.9946
第一题:NA 第一题:0.01805 第一题:0.9946
中位数:NA 中位数:0.01805 中位数:0.9946
平均值:NaN 平均值:0.01805 平均值:0.9946
第三题:NA 第三题:0.01805 第三题:0.9946
最大限度。 : 不适用:0.01805 最大。 :0.9946
NA 的 :3
train.default(x, y, weights = w, ...) 中的错误:停止
summaryFunction = twoClassSummary 出现触发警告。 它也发生在这里:
ctrl <- trainControl(method = "cv", summaryFunction = twoClassSummary)
multinomSummaryFit <- train(LoanStatus~., credit, method = "multinom", family=binomial,
trControl = ctrl)
Warning message:
In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : There were missing values in resampled performance measures.
Something is wrong; all the ROC metric values are missing:
ROC Sens Spec
Min. : NA Min. :0.01919 Min. :0.9941
1st Qu.: NA 1st Qu.:0.01988 1st Qu.:0.9942
Median : NA Median :0.02056 Median :0.9943
Mean :NaN Mean :0.02011 Mean :0.9943
3rd Qu.: NA 3rd Qu.:0.02056 3rd Qu.:0.9943
Max. : NA Max. :0.02057 Max. :0.9944
NA's :3
Error in train.default(x, y, weights = w, ...): Stopping
尝试将 class 变量值从“0”、“1”更改为例如"A" , "B" 然后试试。
查看summary(credit)
的输出,可以看出至少有两个变量有NA
个值;
变量 MonthsEmployed
有 5 NA
个值:
MonthsEmployed
Min. :-23.00
1st Qu.: 26.00
Median : 68.00
Mean : 97.44
3rd Qu.:139.00
Max. :755.00
NA's :5
并且变量 InstallmentBalance
有 328 NA
个值。
InstallmentBalance
Min. : 0
1st Qu.: 3338
Median : 14453
Mean : 24900
3rd Qu.: 32238
Max. :739371
NA's :328
尝试删除具有缺失值的行(或临时删除这两个变量)并再次 运行 该函数以查看是否可以解决您的问题。
另外,使用twoClassSummary
train
函数中添加metric = "ROC"
,在trainControl()
中添加classProbs = TRUE
ctrl <- trainControl(method = "repeatedcv",
repeats = 3,
classProbs = TRUE,
summaryFunction = twoClassSummary) .
所以,你的电话应该是
multinomSummaryFit <- train(LoanStatus~.,
data = credit,
method = "multinom",
family=binomial,
metric = "ROC",
trControl = ctrl)
关于数据集的另一个重要问题是,您需要仔细检查变量的值并确保每个值都有意义。例如,MonthsEmployed
变量具有负值。从逻辑上讲,雇员的受雇月数是正数。这些负值是错误的还是有其他含义! (例如,值 -23 表示此人已 23 个月未受雇)。
回答关于 confusionMatrix
的问题:
假设您的训练模型名为 multinomSummaryFit
。为了在测试数据集上评估你的模型,你需要在没有 LoanStatus
的情况下对测试数据集调用 predict
方法(使用你训练模型的相同变量),然后将你的模型预测与LoanStatus
中的实际值。例如,
#let's say your test datafrme is called test
mymodel_pred <- predict(multinomSummaryFit, test[, names(test) != "LoanStatus"])
然后使用 confusionMatrix
:
confusionMatrix(data = mymodel_pred,
reference = test$LoanStatus,
positive = "Default")
如果测试数据集没有 LoanStatus
列,那么您只需使用:
mymodel_pred <- predict(multinomSummaryFit, test)
但在这种情况下,如果您不知道实际响应,则无法在测试数据集上评估模型。
请记住,如果您从训练数据集中删除了任何变量,则需要在调用 predict
使用分层抽样拆分数据进行训练和测试:
trainingRows <- createDataPartition(credit$LoanStatus, p = .70, list= FALSE)
train <- credit[trainingRows, ]
test <- credit[-trainingRows, ]
我在一些数据上遇到了类似的问题,我使用选项 "summaryFunction = twoClassSummary" 来获得一些输出性能指标,而一些数据特征的 sd() 等于 1。
我通过排除 "twoClassSummary" 并在接下来的步骤中计算我需要的性能指标(例如 ROC、CM)解决了这个问题。