gpt4 book ai didi

r - 在曲线中找到肘/膝

转载 作者:行者123 更新时间:2023-12-05 08:27:20 26 4
gpt4 key购买 nike

我有这些数据:

x <- c(6.626,6.6234,6.6206,6.6008,6.5568,6.4953,6.4441,6.2186,6.0942,5.8833,5.702,5.4361,5.0501,4.744,4.1598,3.9318,3.4479,3.3462,3.108,2.8468,2.3365,2.1574,1.899,1.5644,1.3072,1.1579,0.95783,0.82376,0.67734,0.34578,0.27116,0.058285)

y <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32)

看起来像:

plot(x,y)

enter image description here

我想找到一种方法让肘/膝点在 x=6.5

左右

我认为拟合 loess 曲线然后取二阶导数可能可行,但是:

plot(x,predict(loess(y ~ x)),type="l")

enter image description here

看起来它不会完成这项工作。

有什么想法吗?

最佳答案

我认为您想找到函数 y=f(x) 的导数在值上有巨大跳跃的点。您可以尝试以下操作,正如您所看到的,根据我们选择的阈值(对于巨大的跳跃),可能会有一个或多个这样的点:

get.elbow.points.indices <- function(x, y, threshold) {
d1 <- diff(y) / diff(x) # first derivative
d2 <- diff(d1) / diff(x[-1]) # second derivative
indices <- which(abs(d2) > threshold)
return(indices)
}

# first approximate the function, since we have only a few points
ap <- approx(x, y, n=1000, yleft=min(y), yright=max(y))
x <- ap$x
y <- ap$y

indices <- get.elbow.points.indices(x, y, 1e4) # threshold for huge jump = 1e4
x[indices]
#[1] 6.612851 # there is one such point
plot(x, y, pch=19)
points(x[indices], y[indices], pch=19, col='red')

enter image description here

 indices <- get.elbow.points.indices(x, y, 1e3) # threshold for huge jump = 1e3
x[indices]
#[1] 0.3409794 6.4353456 6.5931286 6.6128514 # there are 4 such points
plot(x, y, pch=19)
points(x[indices], y[indices], pch=19, col='red')

enter image description here

关于r - 在曲线中找到肘/膝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41518870/

26 4 0
文章推荐: firebase - 将 Firebase 快照转换到 Swift 3 对象
文章推荐: shopify - Liquid - 将数组转换为小写
文章推荐: javascript - 给定一个两位数的整数 n。返回其数字的总和。示例 对于 n = 29,输出应为 addTwoDigits(n) = 11
文章推荐: reactjs - 如何 : onClick/onChange for a