简体   繁体   English

使用pdp包获取所有类的概率标度偏相关图

[英]Use pdp package to get probability scale partial dependence plots for all classes

I have been following the example here to create partial dependence plots but I would like to combine the approach used to get plots for all levels in a multiclass with the one to get predictions on the probability scale (see pages 430-431). 我一直按照这里的示例创建部分依赖图,但我想将用于获取多类中所有级别的图的方法与一种方法结合起来,以得出概率标度的预测值(请参阅第430-431页)。 This is my approach but it doesn't work because pred.fun is not allowed to have a third arguement 这是我的方法,但是不起作用,因为pred.fun不允许进行第三次辩论

library(e1071)

iris.svm <- svm(Species ~ ., data = iris, kernel = "radial", gamma = 0.75,
                cost = 0.25, probability = TRUE)

pred.prob <- function(object, newdata,i) { # see ?predict.svm
  pred <- predict(object, newdata, probability = TRUE)
  prob.class <- attr(pred, which = "probabilities")[, i]
  mean(prob.class)
}

pred.prob(iris.svm,iris,"setosa")

pd <- NULL

for (i in 1:3) {
  tmp <- partial(iris.svm, pred.var = c("Petal.Width", "Petal.Length"),
                 pred.fun = pred.prob,
                 which.class = i, grid.resolution = 101, progress = "text")
  pd <- rbind(pd, cbind(tmp, Species = levels(iris$Species)[i]))
}

Any recommendations for how to get around this requirement or a different approach? 关于如何解决此要求或其他方法的任何建议?

It looks like the package has actually been updated since the article I referred to was published. 自从我提到的文章发布以来,该软件包实际上已经得到了更新。 Now all you need to do is set the prob argument to TRUE and it will predict on the probability scale. 现在,您所需要做的就是将prob参数设置为TRUE,它将在概率范围内进行预测。

pd <- NULL    
for (i in 1:3) {
  tmp <- partial(iris.svm, pred.var = c("Petal.Width", "Petal.Length"),
                 prob = T,
                 which.class = i, grid.resolution = 101, progress = "text")
  pd <- rbind(pd, cbind(tmp, Species = levels(iris$Species)[i]))
}

I hope this helps someone else to avoid wasting an afternoon! 我希望这可以帮助其他人避免浪费一个下午!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM