在 spark 中使用 LSH 对数据帧中的每个点运行最近邻查询 [英] Using LSH in spark to run nearest neighbors query on every point in dataframe
本文介绍了在 spark 中使用 LSH 对数据帧中的每个点运行最近邻查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于数据帧中的每个特征向量,我需要 k 个最近的邻居.我正在使用来自 pyspark 的 BucketedRandomProjectionLSHModel.
I need k nearest neighbors for each feature vector in the dataframe. I'm using BucketedRandomProjectionLSHModel from pyspark.
创建模型的代码
brp = BucketedRandomProjectionLSH(inputCol="features", outputCol="hashes",seed=12345, bucketLength=n)
model = brp.fit(data_df)
df_lsh = model.transform(data_df)
现在,我如何为 data_df 中的每个点运行近似最近邻查询.
Now, How do I run approx nearest neighbor query for each point in data_df.
我曾尝试广播模型,但出现 pickle 错误.此外,定义一个 udf 来访问模型会给出错误 Method __getstate__([]) does not exist
I have tried broadcasting the model but got pickle error.
Also, defining a udf to access the model gives error Method __getstate__([]) does not exist
推荐答案
使用应该使用.approxSimilarityJoin
model.df_lsh(df_lsh, df_lsh)
这篇关于在 spark 中使用 LSH 对数据帧中的每个点运行最近邻查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文