I am trying to create a model that will predict the dominant color in the image using K-means clustering. I have the data all set up, but I am unsure how I can proceed after fitting the model. Thanks
from sklearn.cluster import KMeans
import h5py
train_data = h5py.File('x_train.h5','r')
test_data = h5py.File('x_test.h5','r')
x_train = train_data['train'][:]
x_test = test_data['test'][:]
print(x_train.shape) # (429-number of images, 416-height,416-width, 3-channels)
x_train = x_train/255.0
x_test = x_test/255.0
X_train = x_train.reshape(len(x_train),-1)
X_test = x_test.reshape(len(x_test),-1)
kmeans = KMeans(n_clusters = 5)
# Fitting the model to training set
kmeans.fit(X_train)
#------edit------
pred = kmeans.predict(X_test[0])
labels=pred.labels_
labels=list(labels)
centroid=pred.cluster_centers_
percent=[]
for i in range(len(centroid)):
x=labels.count(i)
x=x/(len(labels))
percent.append(x)
get_label_index = percent.index(max(percent))
get_rgb_of_dominant_color = centroid[get_label_index][:]
print(get_rgb_of_dominant_color)