gpt4 book ai didi

Setting k for KDTree search: chatgpt seems wrong(为KDTree搜索设置k:聊天似乎有误)

转载 作者:bug小助手 更新时间:2023-10-24 23:59:16 30 4
gpt4 key购买 nike



I have dataset consisting of 30 samples and 5 features.
I want kdtree search across all 30 samples and 5 features .
What should be the value for "k" parameter ?

我有一个由30个样本和5个特征组成的数据集。我希望kdtree搜索所有30个样本和5个功能。“k”参数的值应该是多少?


from sklearn.neighbors import KDTree

# Assuming your data is in a variable called 'data'
tree = KDTree(data)

# Query point
query_point = [1.0, 2.0, 3.0, 4.0, 5.0]

# Find the 5 nearest neighbors
distances, indices = tree.query([query_point], k=5)

# 'indices' will contain the indices of the 5 nearest neighbors
# 'distances' will contain the distances to these neighbors

The chatgpt says that it should be 5.
But I do not think so.
Do someone know about it?

喋喋不休的人说应该是5。但我不这么认为。有人知道这件事吗?


更多回答

The choice of k (in query) is up to you and your problem, there isn't really a "should be".

K(在查询中)的选择取决于您和您的问题,没有真正的“应该是”。

@BenReiniger my question was: what k should be for "search across all 30 samples". I guess the answer is 30 then ?

@BenReiniger我的问题是:“在所有30个样本中搜索”的k应该是多少。我想答案是30岁吧?

No, "search across all 30 samples" doesn't imply anything about k. k is the number of results, the number of nearest neighbors, returned. Maybe if would help to tell us what you're trying to do.

不,“在所有30个样本中搜索”并不意味着任何关于k的内容。k是返回的结果数,即最近的邻居数。也许如果能告诉我们你想做什么。

If you meant you want the distance to all 30 points, then k=30 is what you want, but then there's no reason to use KDTree...

如果你的意思是你想要所有30个点的距离,那么k=30就是你想要的,但是没有理由使用KDTree...

优秀答案推荐

The value for the "k" parameter in a KDTree search determines how many nearest neighbors you want to find for a given query point. In your code example, you are looking for the 5 nearest neighbors to the query_point.

KDTree搜索中“k”参数的值确定要为给定查询点查找多少最近邻居。在您的代码示例中,您将查找距离Query_point最近的5个邻居。


So, if you want to find the 5 nearest neighbors, setting k=5 is the correct choice in this case. The code you provided will return the indices of the 5 nearest neighbors and their corresponding distances from the query_point.

因此,如果您想要查找5个最近的邻居,在这种情况下设置k=5是正确的选择。您提供的代码将返回5个最近邻居的索引以及它们到Query_point的相应距离。


更多回答

I want kdtree search across all 30 samples and 5 features . What should be the value for "k" parameter ?

我希望kdtree搜索所有30个样本和5个功能。“k”参数的值应该是多少?

@mark "I want kdtree search across all 30 samples and 5 features" doesn't inform the choice of k (in query) at all. How many neighbors (from among the 30) do you want returned?

@mark“我想要对所有30个样本和5个特性进行kdtree搜索”根本不会通知k(在查询中)的选择。你想(从30个邻居中)选出几个?

The sklearn documentation clearly says that k is "The number of nearest neighbors to return". This answer is correct. Set k=5.

Sknowledge文档中明确表示,k是“要返回的最近邻居的数量”。这个答案是正确的。设置k=5。

@BenReiniger So, k deals across samples only and it does not matter with #features ?

@BenReiniger所以,k只处理样本,而与#功能无关?

@JesseSealand My question was to search across all 30 samples. So, I think k should be 30 not 5. Is not it ?

@JesseSealand我的问题是搜索所有30个样本。所以,我认为k应该是30而不是5,不是吗?

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com