1

I am using minisom package for doing som clustering.

After train_batch() how can i use trained model to assign cluster number to data points?

shantanu pathak
  • 2,018
  • 19
  • 26

2 Answers2

0

I can provide you the code for the SUSI package which also includes an unsupervised SOM for clustering and visualization. You can install it with pip3 install susi. Here is a code example (you find more in the examples of the repository):

import susi

# TODO get your data X here
X = ...

# train your SOM
som = susi.SOMClustering()
som.fit(X)

# get clusters
clusters = som.get_clusters(X)

# get u-matrix
u_matrix = som.get_u_matrix()
felice
  • 1,185
  • 1
  • 13
  • 27
0

I labeled my clusters as this: SOM Cluster is cluster=(0,0) So i did cluster[0]*10 + cluster[1] and got my labels

Edit - Code Example

I've used this function that i found here: https://www.kaggle.com/code/izzettunc/introduction-to-time-series-clustering/notebook

They select the cluster from SOM as cluster = (x,y)

You can see cluster_number = xsom_y+y+1 I got the same result by doing cluster_number = x10 + y

def plot_som_series_dba_center(som_x, som_y, win_map):
    fig, axs = plt.subplots(som_x,som_y,figsize=(25,25))
    fig.suptitle('Clusters')
    for x in range(som_x):
        for y in range(som_y):
            cluster = (x,y)
            if cluster in win_map.keys():
                for series in win_map[cluster]:
                    axs[cluster].plot(series,c="gray",alpha=0.5) 
                axs[cluster].plot(dtw_barycenter_averaging(np.vstack(win_map[cluster])),c="red") # I changed this part
            cluster_number = x*som_y+y+1
            axs[cluster].set_title(f"Cluster {cluster_number}")

    plt.show()
Hakun
  • 357
  • 3
  • 10