我对 HDBSCAN 中以下参数之间的差异感到困惑
如我错了请纠正我。
对于min_samples,如果设置为 7,则形成的簇需要有 7 个或更多点。因为cluster_selection_epsilon如果设置为 0.5 米,则任何相距超过 0.5 米的簇都不会合并为一个。这意味着每个簇仅包含相距 0.5 米或更小的点。
这与 有何不同min_cluster_size?
cluster-analysis machine-learning hierarchical-clustering scikit-learn hdbscan
我正在尝试安装 bertopic 并收到此错误:
pip install bertopic
Collecting bertopic
> Using cached bertopic-0.11.0-py2.py3-none-any.whl (76 kB)
> Collecting hdbscan>=0.8.28
> Using cached hdbscan-0.8.28.tar.gz (5.2 MB)
> Installing build dependencies: started
> Installing build dependencies: finished with status 'done'
> Getting requirements to build wheel: started
> Getting requirements to build wheel: finished with status 'done'
> Preparing metadata (pyproject.toml): started
> Preparing metadata (pyproject.toml): finished with status 'done'
> Requirement already satisfied: tqdm>=4.41.1 in c:\users\martin kunth\anaconda3\lib\site-packages (from bertopic) (4.62.3)
> Collecting umap-learn>=0.5.0 …Run Code Online (Sandbox Code Playgroud) 我知道以前有很多人发布过关于此的信息,但我仍然无法解决我的错误。我正在尝试导入 hdbscan 但它一直返回以下错误
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-12-bf3184c2d1a0> in <module>
2 import numpy as np
3 from pyproj import Transformer
----> 4 import hdbscan
5 from scipy.spatial.qhull import ConvexHull
6 from shapely.geometry import Point
~/Library/Python/3.7/lib/python/site-packages/hdbscan/__init__.py in <module>
----> 1 from .hdbscan_ import HDBSCAN, hdbscan
2 from .robust_single_linkage_ import RobustSingleLinkage, robust_single_linkage
3 from .validity import validity_index
4 from .prediction import (approximate_predict,
5 membership_vector,
~/Library/Python/3.7/lib/python/site-packages/hdbscan/hdbscan_.py in <module>
19 from scipy.sparse import csgraph
20
---> 21 from ._hdbscan_linkage import (single_linkage, …Run Code Online (Sandbox Code Playgroud) 我尝试使用 下载 Hdbscan pip install hdbscan,我得到了这个:
错误:hdbscan 的构建轮失败
错误:无法为使用 PEP 517 且无法直接安装的 hdbscan 构建轮子
我尝试了几种解决方案,但没有奏效。
DBSCAN 和 HDBSCAN 中哪种聚类方法被认为是最好的?其背后的原因是什么?
我的目的是使用 HDBSCAN 对来自 doc2vec 的文档向量进行聚类。我想找到存在语义和文本重复的微小集群。
为此,我使用 gensim 生成文档向量。生成的 docvec 的元素均在 [-1,1] 范围内。
为了比较两个文档,我想比较角度相似度。我通过计算向量的余弦相似度来做到这一点,效果很好。
但是,要对 HDBSCAN 文档进行聚类,需要距离矩阵,而不是相似度矩阵。从余弦相似度到余弦距离的本机转换sklearn是1-similarity。然而,据我了解,使用这个公式可以打破三角不等式,使其无法成为真正的距离度量。当搜索和查看其他人的类似任务的代码时,似乎大多数人似乎都在使用sklearn.metrics.pairwise.pairwise_distances(data, metric='cosine')它来定义余弦距离1-similarity。看起来它提供了适当的结果。
我想知道这是否正确,或者我是否应该使用角距离,计算为np.arccos(cosine similarity)/pi。我还看到人们在 l2 标准化文档向量上使用欧几里德距离;这似乎相当于余弦相似度。
请让我知道计算聚类文档向量之间的距离最合适的方法是什么:)
我正在做一些行为分析,跟踪一段时间内的行为,然后创建这些行为的 n 元模型。
sample_n_gram_list = [['scratch', 'scratch', 'scratch', 'scratch', 'scratch'],
['scratch', 'scratch', 'scratch', 'scratch', 'smell/sniff'],
['scratch', 'scratch', 'scratch', 'sit', 'stand']]
Run Code Online (Sandbox Code Playgroud)
我希望能够对这些 n 元模型进行聚类,但我需要使用自定义指标创建一个预先计算的距离矩阵。我的指标似乎工作正常,但是当我尝试使用 sklearn 函数创建距离矩阵时,出现错误:
ValueError: could not convert string to float: 'scratch'
Run Code Online (Sandbox Code Playgroud)
我查看了文档https://scikit-learn.org/stable/modules/ generated/sklearn.metrics.pairwise_distances.html,关于这个主题并不是特别清楚。
有人熟悉如何正确使用它吗?
完整代码如下:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab
import math
import hashlib
import networkx as nx
import itertools
import hdbscan
from sklearn.metrics.pairwise import pairwise_distances
def get_levenshtein_distance(path1, path2):
"""
https://en.wikipedia.org/wiki/Levenshtein_distance
:param path1:
:param path2:
:return: …Run Code Online (Sandbox Code Playgroud)