微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

游侠预测R中的尺寸错误

如何解决游侠预测R中的尺寸错误

发布评估游侠。两者都无法对数据进行子集化(想要rf.trnprob的第一列)

rangermodel= ranger(outcome~.,data=traindata,num.trees=200,probability=TRUE)
rf.trnprob= predict(rangerModel,traindata,type='prob')


trainscore <- subset(traindata,select=c("outcome"))
trainscore$score<-rf.trnprob[,1]  

错误

尺寸错误

table(pred = rf.trbprob,true=traindata$outcome)

错误

所有参数的长度必须相同

解决方法

似乎错误地调用了class Solution { public static void main(String[] args) { /* * 5235 and 4068 is OK * 5235 and 5339 is OK * 5235 and 2553 is OK * 5235 and 5236 is NOT OK * 5325 and 5235 is NOT OK (permutation) */ // threshold is the maximum number of digits that can be the same // while the pin1,pin2 are distant enough; in this case 2 int threshold = 2; int pinLength = 4; System.out.println(areDistant(5235,4068,threshold,pinLength)); System.out.println(areDistant(5235,5339,2553,5236,pinLength)); System.out.println(areDistant(5325,5235,pinLength)); } public static boolean areDistant(int pin1,int pin2,int threshold,int pinLength) { if (isPermutation(pin1,pin2)) return false; int sameDigits = 0; int ithDigit1,ithDigit2; for (int i=0; i<pinLength; i++) { ithDigit1 = (int) (pin1 / Math.pow(10,i)) % 10; ithDigit2 = (int) (pin2 / Math.pow(10,i)) % 10; // System.out.println(ithDigit1); // System.out.println(ithDigit2); if ( ithDigit1 == ithDigit2) sameDigits += 1; } return sameDigits <= threshold; } private static boolean isPermutation(int pin1,int pin2) { return false; // fill the code here } } 函数,它应该是predict而不是response。使用示例数据集:

type

概率存储在此处,每个类的一列:

library(ranger)
traindata =iris
traindata$Species = factor(as.numeric(traindata$Species=="versicolor"))
rangerModel = ranger(Species~.,data=traindata,probability=TRUE)
rf.trnprob= predict(rangerModel,traindata,response='prob')

但是似乎您想做一个混淆矩阵,因此您可以通过以下方式获得预测:

head(rf.trnprob$predictions)
             0           1
[1,] 1.0000000 0.000000000
[2,] 0.9971786 0.002821429
[3,] 1.0000000 0.000000000
[4,] 1.0000000 0.000000000
[5,] 1.0000000 0.000000000
[6,] 1.0000000 0.000000000

然后:

pred = levels(traindata$Species)[max.col(rf.trnprob$predictions)]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?