我试图绘制ROC并计算AUC,但我的代码给了我无法找出的错误。我的数据集在响应变量(标记)中有3个类,分别是:Attack,Natural和NoEvents。我将数据集分为训练和测试,然后将随机森林分类器应用于数据集。请问有什么办法可以解决这个错误?
fitRand <- randomForest(marker~.,data=training, method="class")
predictions <- as.numeric(predict(fitRand, testing, type = 'response'))
plot(multiclass.roc(testing$marker, predictions))
这是我运行代码后的输出。我还尝试将代码的第二行调整为
prediction <- predict(fitRand, testing, type="prob")
但是由于错误仍然相同,结果仍然没有改变
> predictions <- as.numeric(predict(fitRand, testing, type = 'response'))
> plot(multiclass.roc(testing$marker, predictions))
Setting direction: controls < cases
Setting direction: controls < cases
Setting direction: controls < cases
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
这是数据集的dput输出
structure(list(R1.PA1.VH = c(0.901248616756968, 0.909703558645628,
0.905194256350919), R1.PM1.V = c(-0.121305257321532, -0.00568309429279342,
-0.0392508132848571), R1.PA2.VH = c(-0.453705198917175, -0.446035191298723,
-0.450074728673594), R1.PM2.V = c(-0.527827315731853, -0.137632157108689,
-0.238327660862787), R1.PA3.VH = c(-1.77870336765027, -1.77000082692442,
-1.77470973627509), R1.PM3.V = c(-0.634417962206939, -0.260622757908978,
-0.357086051950607), R1.PA4.IH = c(0.87538514789086, 0.874879348900357,
0.857513586469697), R1.PM4.I = c(0.643364755048073, 0.664045680448841,
0.718333109625854), R1.PA5.IH = c(-0.508104661575433, -0.501241885322831,
-0.508207091109096), R1.PM5.I = c(1.31275320353577, 1.2788409750031,
1.29579708926943), R1.PA6.IH = c(-1.79395928213566, -1.79712051429462,
-1.81972630841128), R1.PM6.I = c(1.12193590932576, 1.17951451257095,
1.28850258299934), R1.PA7.VH = c(0.901440664212362, 0.909782967938115,
0.905386348373739), R1.PM7.V = c(-0.300635468530866, -0.0845748753629576,
-0.142191045030625), R1.PA8.VH = c(-0.0211764695330397, -0.0211764695330397,
-0.0211764695330397), R1.PM8.V = c(-0.103089654870256, -0.103089654870256,
-0.103089654870256), R1.PA9.VH = c(-0.0235457137937955, -0.0235457137937955,
-0.0235457137937955), R1.PM9.V = c(-0.0893265067030392, -0.0893265067030392,
-0.0893265067030392), R1.PA10.IH = c(0.869793834914526, 0.871311233127761,
0.855968651727977), R1.PM10.I = c(1.11089947081114, 1.13077767881201,
1.20035140681503), R1.PA11.IH = c(1.84903656497102, 1.84054008532172,
0.0379664695214427), R1.PM11.I = c(0.0234279780175843, -0.0637239118705692,
-0.217277241673506), R1.PA12.IH = c(-1.38585135335037, -1.45166237763715,
-1.6665319006976), R1.PM12.I = c(0.0453159527659856, -0.0302759596173977,
-0.121781958818335), R1.F = c(0.106135133435126, 0.030940191325899,
0.030940191325899), R1.DF = c(-0.00514509235256255, -0.00514509235256255,
-0.00514509235256255), R1.PA.Z = c(-0.219207709937831, -0.233476767892463,
-0.261059110710058), R1.PA.ZH = c(0.0394389502182876, 0.110270153370206,
0.222509669649612), R1.S = c(-0.0583717899743145, -0.0583717899743145,
-0.0583717899743145), R2.PA1.VH = c(0.812938168551346, 0.822189686444369,
0.817590624420796), R2.PM1.V = c(-0.0715716174842044, 0.00604940722528985,
-0.0149778404310168), R2.PA2.VH = c(-0.547252708415772, -0.538738930996094,
-0.543020433793297), R2.PM2.V = c(-0.656099779469524, -0.34900852121373,
-0.432829471855525), R2.PA3.VH = c(-1.85704030354057, -1.84695353257102,
-1.8519969180558), R2.PM3.V = c(-0.786435567762694, -0.441273765833977,
-0.527223529005601), R2.PA4.IH = c(-1.32178577967063, -1.32534935971627,
-1.34338648815922), R2.PM4.I = c(0.803839038979569, 0.839822165290882,
0.904533754464616), R2.PA5.IH = c(1.36512902869124, 1.37359454310671,
1.36604421099611), R2.PM5.I = c(1.30301559246338, 1.27190871266553,
1.29308518559861), R2.PA6.IH = c(0.107234552889436, 0.104186532544877,
0.0855051241880482), R2.PM6.I = c(1.12230284004205, 1.17622350295035,
1.27413439838284), R2.PA7.VH = c(0.813075585054262, 0.82243207294593,
0.817727104545215), R2.PM7.V = c(-0.3246850562181, -0.141714529318988,
-0.18985340139939), R2.PA8.VH = c(-0.0192070795313855, -0.0192070795313855,
-0.0192070795313855), R2.PM8.V = c(-0.109128911200633, -0.109128911200633,
-0.109128911200633), R2.PA9.VH = c(-0.0167664664635024, -0.0167664664635024,
-0.0167664664635024), R2.PM9.V = c(-0.100709590417972, -0.100709590417972,
-0.100709590417972), R2.PA10.IH = c(-1.33099259332786, -1.33049912866558,
-1.34579691449664), R2.PM10.I = c(1.19383331719607, 1.21925577177352,
1.28928195590353), R2.PA11.IH = c(-0.830883181808958, -0.899539796967429,
-0.0466748883115395), R2.PM11.I = c(0.0181282105173396, -0.0710533215151392,
-0.208062046145432), R2.PA12.IH = c(1.07737578385126, 1.09944999015972,
0.0737993347785216), R2.PM12.I = c(0.0704360307118059, -0.0375120676747258,
-0.223812104852714), R2.F = c(0.023588701773691, 0.000436799488303913,
0.000436799488303913), R2.DF = c(-0.00533545688672841, -0.00533545688672841,
-0.00533545688672841), R2.PA.Z = c(-0.374995038057927, -0.404164467552751,
-0.450035405112522), R2.PA.ZH = c(-0.438993969611863, -0.425106909215613,
-0.412196061231027), R2.S = c(-0.0579487748389559, -0.0579487748389559,
-0.0579487748389559), R3.PA1.VH = c(0.813015490221589, 0.822386502214406,
0.817756776022893), R3.PM1.V = c(-0.0978497989926585, -0.0207531974377948,
-0.0400273526309679), R3.PA2.VH = c(-0.547268373518954, -0.53869610322021,
-0.542802579989106), R3.PM2.V = c(-0.689936984939945, -0.388580382117686,
-0.463919514043502), R3.PA3.VH = c(-1.85634939879425, -1.84636674568892,
-1.8513281844647), R3.PM3.V = c(-0.935677859066533, -0.586980651839238,
-0.674154964511003), R3.PA4.IH = c(-1.32123190856082, -1.32357343477016,
-1.34190587114264), R3.PM4.I = c(0.810457978470515, 0.841393827840951,
0.906359111518867), R3.PA5.IH = c(1.36471979604474, 1.37360632926632,
1.36567405521159), R3.PM5.I = c(1.32014862782678, 1.2881394707675,
1.30947890880702), R3.PA6.IH = c(0.103818013714248, 0.10150817038992,
0.0832860730734635), R3.PM6.I = c(1.12870498828374, 1.17382247223438,
1.27841300321087), R3.PA7.VH = c(0.813257607812679, 0.822626471226428,
0.817997806535294), R3.PM7.V = c(-0.377284576460134, -0.195312948700175,
-0.240805866980157), R3.PA8.VH = c(-0.0191735243202768, -0.0191735243202768,
-0.0191735243202768), R3.PM8.V = c(-0.109124064626385, -0.109124064626385,
-0.109124064626385), R3.PA9.VH = c(-0.0167540346071673, -0.0167540346071673,
-0.0167540346071673), R3.PM9.V = c(-0.100718235065081, -0.100718235065081,
-0.100718235065081), R3.PA10.IH = c(-1.33278636661911, -1.33147157541789,
-1.34679175041649), R3.PM10.I = c(1.19723722826749, 1.21600675246311,
1.28691384386879), R3.PA11.IH = c(-0.841327370979547, -0.899853463033792,
-0.0461902193607647), R3.PM11.I = c(0.0117584843247331, -0.0709580891058742,
-0.208819044823553), R3.PA12.IH = c(1.0905776066616, 1.13155892259772,
0.071286503451424), R3.PM12.I = c(0.0628578130127322, -0.0485084573249535,
-0.228815752157397), R3.F = c(0.0235978012715834, 0.000447037161910127,
0.000447037161910127), R3.DF = c(-0.00347868684292133, -0.00347868684292133,
-0.00347868684292133), R3.PA.Z = c(-0.197901687180613, -0.210548900346519,
-0.231532233196037), R3.PA.ZH = c(-0.421249514827208, -0.407998663650378,
-0.394871264572987), R3.S = c(-0.0581001971374813, -0.0581001971374813,
-0.0581001971374813), R4.PA1.VH = c(0.900966200796369, 0.909363152435685,
0.904967432814619), R4.PM1.V = c(-0.170983351445325, -0.0527309725829778,
-0.084264946567966), R4.PA2.VH = c(-0.45312759162006, -0.445457724132606,
-0.449548320173511), R4.PM2.V = c(-0.903099135851253, -0.54052443672448,
-0.625125204674263), R4.PA3.VH = c(-1.78025576046517, -1.77143259903316,
-1.77608264293892), R4.PM3.V = c(-0.743728387594984, -0.391503687946788,
-0.473689455880641), R4.PA4.IH = c(0.871589294060148, 0.871083697600872,
0.852994579290947), R4.PM4.I = c(0.677759694888594, 0.701939223135898,
0.757014815254759), R4.PA5.IH = c(-0.504990469369321, -0.497358548008076,
-0.504222155136523), R4.PM5.I = c(1.31057573487165, 1.28692720508059,
1.30627600218237), R4.PA6.IH = c(-1.79418281547186, -1.79781824126812,
-1.8186176478171), R4.PM6.I = c(1.10924829517582, 1.16937446776888,
1.26889364999188), R4.PA7.VH = c(0.900890198151885, 0.909287241101107,
0.904835117615322), R4.PM7.V = c(-0.447696085014686, -0.218486595703839,
-0.277637441167603), R4.PA8.VH = c(-0.0215398381044061, -0.0215398381044061,
-0.0215398381044061), R4.PM8.V = c(-0.102796850087267, -0.102796850087267,
-0.102796850087267), R4.PA9.VH = c(-0.0182144693916607, -0.0182144693916607,
-0.0182144693916607), R4.PM9.V = c(-0.0862806038287169, -0.0862806038287169,
-0.0862806038287169), R4.PA10.IH = c(0.866622258595165, 0.868251875541594,
0.853248160873211), R4.PM10.I = c(1.12080635570492, 1.14503890112693,
1.21167840103748), R4.PA11.IH = c(1.8450964868757, 1.87231688133858,
0.0395602393384709), R4.PM11.I = c(0.0220066940934875, -0.0661896203358343,
-0.213183477718037), R4.PA12.IH = c(-1.39890722454913, -1.4469833077612,
-0.0944323926239707), R4.PM12.I = c(0.0265509445640657, -0.0602240766457562,
-0.203402861641962), R4.F = c(0.103458664875491, 0.0293687311829247,
0.0293687311829247), R4.DF = c(-0.00401710703059435, -0.00401710703059435,
-0.00401710703059435), R4.PA.Z = c(-0.064778956788925, -0.0686188015432132,
-0.0748720466292913), R4.PA.ZH = c(0.0572086775078629, 0.136118822132398,
0.271706792291495), R4.S = c(-0.0580683175587371, -0.0580683175587371,
-0.0580683175587371), control_panel_log1 = c(-0.00753186600923715,
-0.00753186600923715, -0.00753186600923715), control_panel_log2 = c(-0.00753186600923715,
-0.00753186600923715, -0.00753186600923715), control_panel_log3 = c(-0.00434844263954693,
-0.00434844263954693, -0.00434844263954693), control_panel_log4 = c(-0.00434844263954693,
-0.00434844263954693, -0.00434844263954693), relay1_log = c(-0.0337016967341407,
-0.0337016967341407, -0.0337016967341407), relay2_log = c(-0.0322653910724096,
-0.0322653910724096, -0.0322653910724096), relay3_log = c(-0.0313721967383426,
-0.0313721967383426, -0.0313721967383426), relay4_log = c(-0.0371784274827511,
-0.0371784274827511, -0.0371784274827511), snort_log1 = c(-0.00753186600923715,
-0.00753186600923715, -0.00753186600923715), snort_log2 = c(-0.00869713196775151,
-0.00869713196775151, -0.00869713196775151), snort_log3 = c(-0.0115055505192814,
-0.0115055505192814, -0.0115055505192814), snort_log4 = c(-0.0106519692080489,
-0.0106519692080489, -0.0106519692080489), marker = structure(c(3L,
3L, 3L), .Label = c("Attack", "Natural", "NoEvents"), class = "factor")), row.names = c("2",
"6", "11"), class = "data.frame")