sklearn聚集集群:动态更新集群数量

编程入门 行业动态 更新时间:2024-10-22 09:34:00
本文介绍了sklearn聚集集群:动态更新集群数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

sklearn.cluster.AgglomerativeClustering的文档提到了这一点,

The documentation for sklearn.cluster.AgglomerativeClustering mentions that,

当更改集群数量并使用缓存时, 计算整个树可能是有利的.

when varying the number of clusters and using caching, it may be advantageous to compute the full tree.

这似乎意味着可以先计算完整的树,然后根据需要快速更新所需集群的数量,而无需重新计算树(使用缓存).

This seems to imply that it is possible to first compute the full tree, and then quickly update the number of desired clusters as necessary, without recomputing the tree (with caching).

但是,似乎没有记录此更改群集数的过程.我想这样做,但是不确定如何进行.

However this procedure for changing the number of clusters does not seem to be documented. I would like to do this but am unsure how to proceed.

更新:为明确起见,fit方法未将簇数作为输入: scikit-learn /stable/modules/generation/sklearn.cluster.AgglomerativeClustering.html#sklearn.cluster.AgglomerativeClustering.fit

Update: To clarify, the fit method does not take number of clusters as an input: scikit-learn/stable/modules/generated/sklearn.cluster.AgglomerativeClustering.html#sklearn.cluster.AgglomerativeClustering.fit

推荐答案

使用参数memory = 'mycachedir'设置缓存目录,然后如果使用compute_full_tree=True设置,则使用不同的n_clusters值重新运行fit时,它将使用缓存的树,而不是每次都重新计算.为您提供有关如何使用sklearn的gridsearch API进行此操作的示例:

You set a cacheing directory with the paramater memory = 'mycachedir' and then if you set compute_full_tree=True, when you rerun fit with different values of n_clusters, it will used the cached tree rather than recomputing each time. To give you an example of how to do this with sklearn's gridsearch API:

from sklearn.cluster import AgglomerativeClustering from sklearn.grid_search import GridSearchCV ac = AgglomerativeClustering(memory='mycachedir', compute_full_tree=True) classifier = GridSearchCV(ac, {n_clusters: range(2,6)}, scoring = 'adjusted_rand_score', n_jobs=-1, verbose=2) classifier.fit(X,y)

更多推荐

sklearn聚集集群:动态更新集群数量

本文发布于:2023-11-25 14:02:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630046.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:集群   数量   动态   sklearn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!