我使用了10个交叉验证,我试图绘制ROC,但我需要预测的平均值,因为我有10倍。
N R
[1,] 0.6994095 0.3005905414
[2,] 0.9874324 0.0125676441
[3,] 0.9117558 0.0882442408
[4,] 0.8081003 0.1918996998
[5,] 0.9437582 0.0562418220
[6,] 0.8711155 0.1288844516
[7,] 0.9167169 0.0832830858
[8,] 0.9966530 0.0033469534
[9,] 0.9643046 0.0356954021
[10,] 0.9994098 0.0005901851
[11,] 0.7107562 0.2892437714
[12,] 0.8031399 0.1968601047
[13,] 0.5862284 0.4137715762
[14,] 0.8754098 0.1245901676
[15,] 0.7266179 0.2733820504
[16,] 0.8171662 0.1828337523
[17,] 0.8747295 0.1252705449
[18,] 0.7039327 0.2960673460
[19,] 0.8622489 0.1377510708
[20,] 0.8061929 0.1938071442
N R
[1,] 0.91467687 0.08532313
[2,] 0.94999319 0.05000681
[3,] 0.85994831 0.14005169
[4,] 0.92427004 0.07572996
[5,] 0.92279287 0.07720713
[6,] 0.15469616 0.84530384
[7,] 0.08503478 0.91496522
[8,] 0.90096648 0.09903352
[9,] 0.78253348 0.21746652
[10,] 0.83780906 0.16219094
[11,] 0.02735678 0.97264322
[12,] 0.75501512 0.24498488
[13,] 0.14337626 0.85662374
[14,] 0.67239166 0.32760834
[15,] 0.79444085 0.20555915
[16,] 0.82959876 0.17040124
[17,] 0.62381221 0.37618779
[18,] 0.93198652 0.06801348
[19,] 0.80549723 0.19450277
N R
[1,] 0.6474697 3.525303e-01
[2,] 0.9999089 9.113255e-05
[3,] 0.9641722 3.582776e-02
[4,] 0.7305543 2.694457e-01
[5,] 0.6486594 3.513406e-01
[6,] 0.7024364 2.975636e-01
[7,] 0.9235632 7.643683e-02
[8,] 0.8051925 1.948075e-01
[9,] 0.9945675 5.432450e-03
[10,] 0.7742103 2.257897e-01
[11,] 0.7069689 2.930311e-01
[12,] 0.9724157 2.758426e-02
[13,] 0.7592248 2.407752e-01
[14,] 0.7832677 2.167323e-01
[15,] 0.8788655 1.211345e-01
[16,] 0.8095320 1.904680e-01
[17,] 0.7962395 2.037605e-01
[18,] 0.8026804 1.973196e-01
[19,] 0.9230530 7.694699e-02
[20,] 0.8657116 1.342884e-01
N R
[1,] 0.9195472 0.08045275
[2,] 0.6775318 0.32246818
[3,] 0.6507470 0.34925302
[4,] 0.8885743 0.11142566
[5,] 0.7350531 0.26494692
[6,] 0.8004245 0.19957554
[7,] 0.5541833 0.44581670
[8,] 0.4774113 0.52258866
[9,] 0.8397112 0.16028884
[10,] 0.7737221 0.22627789
[11,] 0.6968631 0.30313689
[12,] 0.6234547 0.37654533
[13,] 0.8837244 0.11627555
[14,] 0.7675875 0.23241249
[15,] 0.9442500 0.05575000
[16,] 0.6844704 0.31552959
[17,] 0.7430570 0.25694296
[18,] 0.6992994 0.30070062
[19,] 0.6573980 0.34260198
N R
[1,] 0.773917644 0.22608236
[2,] 0.859971281 0.14002872
[3,] 0.480901800 0.51909820
[4,] 0.863198048 0.13680195
[5,] 0.883855903 0.11614410
[6,] 0.573908341 0.42609166
[7,] 0.897306073 0.10269393
[8,] 0.870504201 0.12949580
[9,] 0.794074784 0.20592522
[10,] 0.908536236 0.09146376
[11,] 0.001425088 0.99857491
[12,] 0.871647353 0.12835265
[13,] 0.156116706 0.84388329
[14,] 0.734450321 0.26554968
[15,] 0.576451465 0.42354853
[16,] 0.463655607 0.53634439
[17,] 0.950560375 0.04943963
[18,] 0.747841536 0.25215846
[19,] 0.941368131 0.05863187
[20,] 0.144217858 0.85578214
N R
[1,] 0.981461477 0.01853852
[2,] 0.956505434 0.04349457
[3,] 0.268210734 0.73178927
[4,] 0.733341695 0.26665830
[5,] 0.433069679 0.56693032
[6,] 0.237313097 0.76268690
[7,] 0.610106940 0.38989306
[8,] 0.868319458 0.13168054
[9,] 0.963723775 0.03627623
[10,] 0.951685816 0.04831418
[11,] 0.007348949 0.99265105
[12,] 0.744557243 0.25544276
[13,] 0.383166677 0.61683332
[14,] 0.614589691 0.38541031
[15,] 0.265940109 0.73405989
[16,] 0.760060264 0.23993974
[17,] 0.775920639 0.22407936
[18,] 0.700276994 0.29972301
[19,] 0.879906317 0.12009368
N R
[1,] 0.41169942 0.588300585
[2,] 0.88863545 0.111364548
[3,] 0.85190855 0.148091445
[4,] 0.86718613 0.132813871
[5,] 0.89864928 0.101350716
[6,] 0.06688256 0.933117438
[7,] 0.93223502 0.067764981
[8,] 0.99141598 0.008584024
[9,] 0.88233479 0.117665208
[10,] 0.33516056 0.664839445
[11,] 0.69588065 0.304119347
[12,] 0.82156356 0.178436441
[13,] 0.74519215 0.254807845
[14,] 0.97662100 0.023379005
[15,] 0.88235832 0.117641677
[16,] 0.96929855 0.030701449
[17,] 0.31255910 0.687440896
[18,] 0.88288702 0.117112982
[19,] 0.80102871 0.198971289
N R
[1,] 0.9999485 5.151445e-05
[2,] 0.8935091 1.064909e-01
[3,] 0.8862276 1.137724e-01
[4,] 0.8211438 1.788562e-01
[5,] 0.9311932 6.880675e-02
[6,] 0.8675625 1.324375e-01
[7,] 0.8856136 1.143864e-01
[8,] 0.8135479 1.864521e-01
[9,] 0.9050920 9.490801e-02
[10,] 0.2020622 7.979378e-01
[11,] 0.9886441 1.135591e-02
[12,] 0.8716919 1.283081e-01
[13,] 0.7141835 2.858165e-01
[14,] 0.6755985 3.244015e-01
[15,] 0.2744007 7.255993e-01
[16,] 0.8592688 1.407312e-01
[17,] 0.9179941 8.200594e-02
[18,] 0.7902478 2.097522e-01
[19,] 0.5800900 4.199100e-01
N R
[1,] 0.8805678 0.11943219
[2,] 0.8517081 0.14829192
[3,] 0.9830331 0.01696693
[4,] 0.8223849 0.17761507
[5,] 0.9638743 0.03612568
[6,] 0.8545500 0.14545004
[7,] 0.6056922 0.39430778
[8,] 0.9077465 0.09225346
[9,] 0.9138271 0.08617288
[10,] 0.7173141 0.28268590
[11,] 0.8547256 0.14527435
[12,] 0.9870370 0.01296299
[13,] 0.7568859 0.24311411
[14,] 0.7389089 0.26109106
[15,] 0.4960564 0.50394361
[16,] 0.2751176 0.72488239
[17,] 0.7197224 0.28027763
[18,] 0.8987683 0.10123174
[19,] 0.7769943 0.22300568
[20,] 0.8007028 0.19929716
N R
[1,] 0.79091397 0.20908603
[2,] 0.60712842 0.39287158
[3,] 0.79979195 0.20020805
[4,] 0.55740147 0.44259853
[5,] 0.83137224 0.16862776
[6,] 0.36536631 0.63463369
[7,] 0.75064646 0.24935354
[8,] 0.81430815 0.18569185
[9,] 0.68985973 0.31014027
[10,] 0.73377876 0.26622124
[11,] 0.07613196 0.92386804
[12,] 0.95714924 0.04285076
[13,] 0.98379127 0.01620873
[14,] 0.84372946 0.15627054
[15,] 0.75142544 0.24857456
[16,] 0.35243540 0.64756460
[17,] 0.20153258 0.79846742
[18,] 0.59625005 0.40374995
[19,] 0.85515909 0.14484091
所以我有10个来自预测的矩阵,我需要每个行和列的平均值为一个矩阵。 我使用了(colMean)函数但是它给了我所有列的平均值,所以最终矩阵将是10行,它应该是20行。
N R
0.8432539 0.1567461
N R
0.6797998 0.3202002
N R
0.8244347 0.1755653
N R
0.7377374 0.2622626
N R
0.6746954 0.3253046
N R
0.6387108 0.3612892
N R
0.7480788 0.2519212
N R
0.7830537 0.2169463
N R
0.7902809 0.2097191
N R
0.6609564 0.3390436
如何获得10个矩阵中每行的平均值?
答案 0 :(得分:2)
有一个rowMeans
函数可以处理矩阵。
m = matrix(1:6,nrow=2)
l = list(m,m)
lapply(l,rowMeans)
你可以unlist
输出得到一个向量,如果你想要一个矩阵,你可以将向量转换成矩阵。像这样:
matrix(unlist(lapply(l,rowMeans)),nrow=nrow(m))
答案 1 :(得分:0)
您可以将数组保存在数组中并应用rowMeans循环
A = array(data = NA, dim = c(20,2,10));dimnames(A)[[2]] = c("N","R")
for(i in 1:10){A[,,] <- cbind(N = runif(20), R = runif(20))}
res = matrix(data = NA, nrow = 20, ncol = 10)
for(i in 1:10){res[,i] <- rowMeans(A[,,i])}
res