简体   繁体   English

将概率边界添加到 pdp::partial 图

[英]Adding probability boundary to pdp::partial plot

I have a plot of predicted probabilities for a binary classification problem.我有一个二元分类问题的预测概率图。 I have two questions:我有两个问题:

  1. How do I draw a single probability break for p = 0.5 ?如何为p = 0.5绘制单个概率中断? Using the contour = TRUE argument adds several lines.使用contour = TRUE参数添加几行。
  2. Is it possible to add another predictor to draw a 3D plot?是否可以添加另一个预测器来绘制 3D 图?

Here is what I have now:这是我现在所拥有的:

在此处输入图片说明

Reprex:代表:


require(caret)
train.ctrl <- trainControl(method = "repeatedcv",
                          number = 10,
                          repeats = 5,
                          summaryFunction = twoClassSummary,
                          classProbs = TRUE,
                          )

set.seed(1337)
lr.fit <- train(Class ~ ., data = train.small,
                 trControl = train.ctrl,
                 method = "glm",
                 family = "binomial",
                 metric = "ROC",
                 preProcess = c("center", "scale")
                 )

require(pdp)
lr.pd <- partial(lr.fit, pred.var = c("x1", "x2"), prob = TRUE, plot = TRUE,
                chull = FALSE, 
                grid.resolution = 20,
                progress = "text",
                plot.engine = "ggplot"     
                #, levelplot = TRUE
                #, contour = TRUE
                )
lr.pd

# dataset used: 
> dput(train.small)

structure(list(x1 = c(-2.27966818800131, -0.338448010439568, 
-0.205849502281457, 0.845604758116324, 0.237243699016471, 1.24653636015188, 
0.141150345247212, -1.94634378874626, 0.844265652370458, -0.364520848772231, 
-1.23724847469945, 1.38848801851204, -1.36106463689431, -0.563757474548103, 
-1.06688494837985, 1.95249141033933, -0.19013864138727, -0.582286822918036, 
-0.121851924837777, 0.708635458099694, 0.232606893541271, -0.973242157622908, 
-0.839124499580887, -1.60414910952904, -2.48941991263215, -0.307956293709429, 
1.47833943928667, 0.878621754086077, -0.98322797566842, -1.07796826066294
), x2 = c(-2.52279563738851, -1.75938416652951, 1.39754416931398, 
-0.00212755901980971, 1.08662786676201, -0.515199741525909, 0.467733663414545, 
-0.466317884258174, -0.836744523943926, -0.718136687911924, -1.73906216686269, 
1.59934935188848, -1.27639037325246, -0.32993091478973, -2.05445383777137, 
-0.0189083922948782, -0.818464313993987, -1.15168959538223, 1.99668352214088, 
0.671670710096937, 0.680397233698906, 0.267937956913229, -1.78107607016152, 
-1.53728406964112, -1.05660014431803, -0.316921861836086, 2.65603302304451, 
0.885179019517534, -0.220384928450498, -1.94445363537753), Class = c("No", 
"Yes", "No", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", 
"Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "No", "No", "No", "Yes", 
"No", "Yes", "No", "No", "No", "No", "No", "No", "Yes")), row.names = c(24L, 
2L, 10L, 9L, 26L, 22L, 12L, 11L, 21L, 17L, 7L, 19L, 27L, 8L, 
25L, 16L, 5L, 18L, 29L, 6L, 14L, 15L, 13L, 20L, 1L, 30L, 4L, 
23L, 28L, 3L), class = "data.frame")

Here is an answer to your Question no.这是您的问题的答案。 1. 1.
You can draw a contour line at p=0.5 using the following simple code:您可以使用以下简单代码在 p=0.5 处绘制轮廓线:

lr.pd + geom_contour(color = "white", breaks=0.5, size=1)

在此处输入图片说明

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

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