I am trying to find silhouette_score for K-means cluster Algorithm. Actually I am using 4 other algorithms and I have to find silhouette_score of all four algorithms. I am trying to find for k-mean cluster first and use the same code for all others as well.
import pandas as pd
import numpy as np
from sklearn.datasets import load_wine
df = load_wine()
from sklearn.preprocessing import MinMaxScaler
X_scaled_data = MinMaxScaler().fit_transform(df.data)
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3).fit(X_scaled_data)
from sklearn.metrics import silhouette_score
silhouette_avg = silhouette_score(X_scaled_data, kmeans.labels_)
print("For n_clusters =", 3, "The average silhouette_score is :", silhouette_avg)
Here is the Error:
