【问题标题】:R: Error in plot.window(...) : need finite 'ylim' valuesR:plot.window(...) 中的错误:需要有限的 'ylim' 值
【发布时间】:2021-07-05 15:24:20
【问题描述】:

我正在使用 R。我正在尝试在此处遵循以前的 stackoverflow 帖子中的代码:Kullback-Leibler distance between 2 samples

特别是,我试图确定两个数据集之间的“距离”:

#load library
library(FNN)
library(dplyr)

#create two data sets
df = iris
data1 = sample_n(df, 20)
data2 = sample_n(df, 20)

#plot KL divergence
plot(KLx.dist(data1,data2))

但是,这会产生以下错误:

Error in plot.window(...) : need finite 'ylim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf

有谁知道为什么会产生这个错误?

谢谢

【问题讨论】:

  • 可能是因为 Species 列是非数字的?
  • 谢谢!这解决了问题!你想发布这个答案吗?或者你想让我这样做(以便未来的读者可以弄清楚)。请让我知道 - 再次感谢!

标签: r


【解决方案1】:

根据KLx.dist 文档,此功能需要数据矩阵作为输入。在iris 数据集中,我们需要删除Species 列,它是一个factor 变量。在采样前删除Species 列将解决问题:

data(iris)

library(FNN)
library(dplyr)

#create two data sets
df = iris[,1:4]
data1 = sample_n(df, 20)
data2 = sample_n(df, 20)

#plot KL divergence
plot(KLx.dist(data1,data2))

【讨论】:

  • 感谢您的帮助!这完美!
  • 只是一个问题:你以前在工作中使用过KL散度吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-27
  • 2014-11-10
  • 1970-01-01
相关资源
最近更新 更多