How do I Print this Silhouette Score?

1.1k views Asked by At

I want to print silhouette score as shown below, but i keep getting this error: name 'silhoutte_score' is not defined. Can someone assist please?

from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score

n = [Arsenal, Aston_Villa, Bournemouth, Brighton, Burnley, Chelsea, Crystal_Palace, Everton, Leicester, Liverpool, Man_City, Man_Utd, Newcastle_United, Norwich, Sheffield_United, Southampton, Tottenham, Watford, West_Ham, Wolves]

for i in n:
    kmeans = KMeans(n_clusters=2, random_state=0)
    kmeans = kmeans.fit(i)
    labels = kmeans.predict(i)
    print(silhoutte_score(i,labels))
1

There are 1 answers

0
Siddharth Pilli On

it seems to be the case you have misspelled silhouette_score.

This is your code with silhouette_score spelled correctly:

from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score

n = [Arsenal, Aston_Villa, Bournemouth, Brighton, Burnley, Chelsea, Crystal_Palace, Everton, Leicester, Liverpool, Man_City, Man_Utd, Newcastle_United, Norwich, Sheffield_United, Southampton, Tottenham, Watford, West_Ham, Wolves]

for i in n:
    kmeans = KMeans(n_clusters=2, random_state=0)
    kmeans = kmeans.fit(i)
    labels = kmeans.predict(i)
    print(silhouette_score(i,labels))