question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Agglomerative Clustering Dendrogram Example "distances_" attribute error

See original GitHub issue

Description

I tried to run the plot dendrogram example as shown in https://scikit-learn.org/dev/auto_examples/cluster/plot_agglomerative_dendrogram.html

Steps/Code to Reproduce

Code is available in the link in the description

Expected Results

Expected results are also documented in the

Actual Results

Traceback (most recent call last):
  File "test_agglomerative.py", line 40, in <module>
    plot_dendrogram(model, truncate_mode='level', p=3)
  File "test_agglomerative.py", line 24, in plot_dendrogram
    linkage_matrix = np.column_stack([model.children_, model.distances_,
AttributeError: 'AgglomerativeClustering' object has no attribute 'distances_'

Checking the documentation, it seems that the AgglomerativeClustering object does not have the “distances_” attribute https://scikit-learn.org/dev/modules/generated/sklearn.cluster.AgglomerativeClustering.html#sklearn.cluster.AgglomerativeClustering.

Versions

Version : 0.21.3 Build: pypi_0 Channel: pypi

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
jnothmancommented, Dec 12, 2019

Please upgrade scikit-learn to version 0.22

1reaction
libbyhcommented, Mar 15, 2020

Me either. scikit-learn-0.22.1

I was able to get it to work using a distance matrix:

Error:

cluster = AgglomerativeClustering(n_clusters = 10, affinity = "cosine", linkage = "average")  
cluster.fit(similarity)

Works:

cluster_dist = AgglomerativeClustering(distance_threshold=0, n_clusters=None)
cluster_dist.fit(distance)
Read more comments on GitHub >

github_iconTop Results From Across the Web

python - AgglomerativeClustering, no attribute called distances_
AgglomerativeClustering () says. distances_ : array-like of shape (n_nodes-1,) Distances between nodes in the corresponding place in ...
Read more >
sklearn.cluster.AgglomerativeClustering
Computes distances between clusters even if distance_threshold is not used. This can be used to make dendrogram visualization, but introduces a computational ...
Read more >
Hierarchical Clustering | Hierarchical Clustering Python
In hierarchical clustering, we have a concept called a proximity matrix. This stores the distances between each point. Let's take an example ......
Read more >
Definitive Guide to Hierarchical Clustering with Python and ...
What are the different linking methods and distance metrics applied to dendrograms and clustering algorithms; What are the agglomerative and ...
Read more >
Hierarchical Clustering in R: Dendrograms with hclust
For example if you have continuous numerical values in your dataset you can use euclidean distance, if the data is binary you may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found