简体   繁体   English

在密度图中找到边界

[英]Finding a boundary in a density plot

I am very new to machine learning so I am open to suggestions as well. 我是机器学习的新手,所以我也愿意接受建议。 I read something called minimax risk today and I was wondering if this is possible in my case. 我今天读了一些名为minimax的风险,我想知道这是否可能。

I have two datasets and am interested in finding a line (or a boundary to be more precise) such that the area under the left curve to the right of the vertical line is equal to the area under the right curve to the left of the vertical line. 我有两个数据集,我有兴趣找到一条线(或更精确的边界),使得垂直线右边的左曲线下方的区域等于垂直线左边的右曲线下方的区域线。 Is there a way this can be done in R ie, find out the exact location to draw the vertical line? 有没有办法可以在R中完成,即找出绘制垂直线的确切位置?

I put up some sample data here that can be used to plot the following graph: https://gist.github.com/Legend/2f299c3b9ba94b9328b2 我在这里提供了一些样本数据,可以用来绘制下图: https//gist.github.com/Legend/2f299c3b9ba94b9328b2

在此输入图像描述

Suppose you are using the density function to get the estimated kernel density for each response, then follow this link to get the estimated kernel CDF, then your question would become to find a value t , such that: 1 - cdf1(t) = cdf2(t) , which can be solved by regular root find function: 假设您使用density函数来获取每个响应的估计内核密度,然后按照此链接获取估计的内核CDF,那么您的问题将变为找到值t ,例如: 1 - cdf1(t) = cdf2(t) ,可以通过常规的根查找功能解决:

x1 <- subset(data, Type == 'Curve 1')$Value
x2 <- subset(data, Type == 'Curve 2')$Value

pdf1 <- density(x1)
f1 <- approxfun(pdf1$x, pdf1$y, yleft = 0, yright = 0)
cdf1 <- function(z){
  integrate(f1, -Inf, z)$value
}

pdf2 <- density(x2)
f2 <- approxfun(pdf2$x, pdf2$y, yleft = 0, yright = 0)
cdf2 <- function(z){
  integrate(f2, -Inf, z)$value
}

Target <- function(t){
  1 - cdf1(t) - cdf2(t)
}

uniroot(Target, range(c(x1, x2)))$root

R > uniroot(Target, range(c(x1, x2)))$root
[1] 0.06501821

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

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