[Python] Why am I getting this TypeError: AgglomerativeClustering.__init__() got an unexpected...

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    Here is my code:

    from sklearn.cluster import FeatureAgglomeration
    from sklearn.metrics import pairwise_distances

    model = AgglomerativeClustering(n_clusters = 7 , linkage = "average" , affinity = "cosine" )


    ...And here is the resulting error:

    TypeError Traceback (most recent call last)
    Cell In[17], line 4
    1 from sklearn.cluster import FeatureAgglomeration
    2 from sklearn.metrics import pairwise_distances
    ----> 4 model = AgglomerativeClustering(n_clusters = 7 , linkage = "average" , affinity = "cosine" )

    TypeError: AgglomerativeClustering.__init__() got an unexpected keyword argument 'affinity'`


    I tried updating all the necessary libraries and updating the pip but still nothing. How can I solve this problem?

    Continue reading...

Compartilhe esta Página