gpt4 book ai didi

python - 如何重现从 Hypertools.plot 识别的 Hypertools 集群

转载 作者:行者123 更新时间:2023-12-03 19:25:50 24 4
gpt4 key购买 nike

Hypertools似乎是一个很好的工具集,可以快速分析一些高维数据。

特别是可以拿一些数据,扔到hypertools.plot(...)并得到一些好看的东西。

但是,之后我无法重现这些组。

理论上,hypertools.plot(data, reduce="alg", cluster="alg2")应该大致相当于:

data = np.array(...)
reduced = hypertools.analyze(data, reduce="alg")
labels = hypertools.cluster(reduced, cluster="alg2")
hypertools.plot(reduced, hue=labels)

但是与 hypertools.plot(...) 相比,我看到逐步方法的标签大不相同。 .

有没有办法在不绘制的情况下获得相同的集群?我可以从 hypertools.plot(..) 的返回值中提取簇吗? (不是首选,因为有时我的 Python 没有意识到情节已关闭,因此从未实现返回值)?

最佳答案

看着hypertools.plot源代码,看起来问题在于混合 reducecluster在对 plot 的同一次调用中首先减少到最多三个维度,如果没有指定更小,则集群。当您采用逐步方法时,维度不会减少到三,直到您在聚类后进行绘图。使用 ndims=3 限制尺寸在 analyze逐步方法的功能产生与您想要的单线相同的结果。

所以你的问题的答案'有没有办法在不绘制的情况下得到相同的集群?将通过ndims=3analyze功能。

来自 plot.py ( super 工具 v0.6.2):

# reduce data to 3 dims for plotting, if ndims is None, return this
if (ndims and ndims < 3):
xform = reducer(xform, ndims=ndims, reduce=reduce, internal=True)
else:
xform = reducer(xform, ndims=3, reduce=reduce, internal=True)

# find cluster and reshape if n_clusters
if cluster is not None:
if hue is not None:
warnings.warn('cluster overrides hue, ignoring hue.')
if isinstance(cluster, (six.string_types, six.binary_type)):
model = cluster
params = default_params(model)
elif isinstance(cluster, dict):
model = cluster['model']
params = default_params(model, cluster['params'])
else:
raise ValueError('Invalid cluster model specified; should be'
' string or dictionary!')

if n_clusters is not None:
if cluster in ('HDBSCAN',):
warnings.warn('n_clusters is not a valid parameter for '
'HDBSCAN clustering and will be ignored.')
else:
params['n_clusters'] = n_clusters

cluster_labels = clusterer(xform, cluster={'model': model,
'params': params})
xform, labels = reshape_data(xform, cluster_labels, labels)
hue = cluster_labels


使用 的示例蘑菇样本数据集:
import hypertools
import numpy as np
%matplotlib inline

geo = hypertools.load('mushrooms')
data = geo.get_data()
reduced = hypertools.analyze(data, ndims=3, reduce="SparsePCA")
labels = hypertools.cluster(reduced, cluster="Birch")
hypertools.plot(reduced, '.', hue=labels)

enter image description here

给出与以下相同的结果:
hypertools.plot(data, '.', reduce="SparsePCA", cluster="Birch")

enter image description here

相比一步步不通过 ndims=3analyze :
enter image description here

关于python - 如何重现从 Hypertools.plot 识别的 Hypertools 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57330300/

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