Hi Jaime, >From *Elegant SciPy*:
""" The *fcluster* function takes a linkage matrix, as returned by linkage, and a threshold, and returns cluster identities. It's difficult to know a-priori what the threshold should be, but we can obtain the appropriate threshold for a fixed number of clusters by checking the distances in the linkage matrix. from scipy.cluster.hierarchy import fcluster n_clusters = 3 threshold_distance = (Z[-n_clusters, 2] + Z[-n_clusters+1, 2]) / 2 clusters = fcluster(Z, threshold_distance, 'distance') """ As an aside, I imagine this question is better placed in the SciPy mailing list than scikit-learn (which has its own hierarchical clustering API). Juan. On Fri, Nov 4, 2016 at 2:16 AM, Jaime Lopez Carvajal <[email protected]> wrote: > Hi there, > > I am trying to do image classification using hierarchical clustering. > So, I have my data, and apply this steps: > > from scipy.cluster.hierarchy import dendrogram, linkage > > data1 = np.array(data) > Z = linkage(data, 'ward') > dendrogram(Z, truncate_mode='lastp', p=12, show_leaf_counts=False, > leaf_rotation=90., leaf_font_size=12.,show_contracted=True) > plt.show() > > So, I can see the dendrogram with 12 clusters as I want, but I dont know > how to use this to classify the image. > Also, I understand that funtion cluster.hierarchy.cut_tree(Z, n_clusters), > that cut the tree at that number of clusters, but again I dont know how to > procedd from there. I would like to have something like: cluster = > predict(Z, instance) > > Any advice or direction would be really appreciate, > > Thanks in advance, Jaime > > > -- > > *Jaime Lopez Carvajal* > > _______________________________________________ > scikit-learn mailing list > [email protected] > https://mail.python.org/mailman/listinfo/scikit-learn > >
_______________________________________________ scikit-learn mailing list [email protected] https://mail.python.org/mailman/listinfo/scikit-learn
