I am trying to use SOM to cluster my data, firstly I want to get the best K. but I need a line or something to detect the best K on the plot. I tried to use KElbowVisualizer() but it always diplay an error:
YellowbrickTypeError: The supplied model is not a clustering estimator; try a classifier or regression score visualizer instead!
and here is my code:
from sklearn_som.som import SOM
som = SOM(m = 1, n = i, dim = data.shape[1])
visualizer = KElbowVisualizer(som, k = (1,11))
visualizer.fit(data)
visualizer.show()
I also used the ordinary Plot() from matplotlib, but I cannot see the Best k, my code:
inertia = []
for i in range (1,31):
som = SOM(m = 1, n = i, dim = data.shape[1])
som.fit_predict(data)
inertia.append(som.inertia_)
plt.plot(range(1,31), inertia)
plt.title('elbow method for SOM')
plt.xlabel('number of clusters')
plt.ylabel('WCSS')
plt.show()
that's the plot I got from Plot()
So, please how can I do that either in the plot or by using a code?