首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >第三次观测点R上的黄土曲线拟合

第三次观测点R上的黄土曲线拟合
EN

Stack Overflow用户
提问于 2020-03-31 07:35:08
回答 1查看 218关注 0票数 0

我用LOESS平滑器在散点图上跟踪this tutorial,但我希望能够将二阶导数应用于LOESS平滑线,以检查它在哪里达到最大值,这样我就可以分辨出有多少簇是最优的,就好像它是k均值的肘部一样。

代码语言:javascript
复制
perplexi <- structure(list(Perplexity = c(NA, NA, 660, 596, 552, 480, 464, 
                      415, 399, 370, 349, 340, 327, 314, 288), Clusters = c(1, 2, 3, 
                      4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)), class = "data.frame", row.names = c(NA, 
                      -15L))

library(plotly)

p <- plot_ly(perplexi[3:15,],
             x = ~Clusters,
             color = I("black")) %>% 
  add_markers(y = ~Perplexity) %>% 
  add_lines(y = ~fitted(loess(Perplexity ~ Clusters)),
                         line = list(color = 'lightblue'),
                         name = "Loess Smoother",
                         showlegend = F) %>% 
  layout(xaxis = list(title = 'Clusters'),
         yaxis = list(title = 'Perplexity')) %>% 
  add_trace(y = ~Perplexity,
            name = 'Perplexity',
            mode = 'markers',
            showlegend = F)

p

d1 <- diff(perplex); k <- which.max(abs(diff(d1) / diff(perplex[-1])))

谁能指出下一步要做什么?我希望k代表平滑的线,而不是实际的数字,这样我就知道要执行多少个主题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-31 09:24:33

一种方法是将黄土拟合在plotly之外,然后取导数。

代码语言:javascript
复制
loess.result <-loess.smooth(perplexi$Clusters, y=perplexi$Perplexity, evaluation = 20)
slopes <- diff(loess.result$x)/diff(loess.result$y)

plot_ly(perplexi[3:15,],
             x = ~Clusters,
             color = I("black")) %>% 
  add_markers(y = ~Perplexity) %>% 
  add_lines(y = ~fitted(loess(Perplexity ~ Clusters)),
                         line = list(color = 'lightblue'),
                         name = "Loess Smoother") %>% 
  layout(xaxis = list(title = 'Clusters'),
         yaxis = list(title = 'Perplexity')) %>% 
  add_trace(y = ~Perplexity,
            name = 'Perplexity',
            mode = 'markers',
            showlegend = F) %>%
  add_trace(x = loess.result$x[-1], y = slopes * -10000, mode = "line", name = "Loess First Derivative")

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60941213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档