K-Means output the similar to each other cluster I am trying to run K-Means on my data set of house price prediction problem.
After running it, the output of the model seems wrong because the graphs look the same as each other.
This is my code:
from sklearn.cluster import KMeans

n_clusters = 4
kmeans = KMeans(n_clusters=n_clusters, random_state=0, verbose=0, n_jobs=int(0.8*n_cores)).fit(X_train)
c_train = kmeans.predict(X_train)
c_pred = kmeans.predict(X_val)

You guys can try with my Colab. Just create a copy of my notebook and then you can run my code.
The data set is cleaned and only contains numerical values.
Below is the example of the graph.
Do you guys know what is wrong about this? Thanks.
Update:
This is how I visualize the plot:
import matplotlib.pyplot as plt

n_clusters = 8

color = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']
for i in range(0, n_clusters):
  plt.scatter(
      X_train[c_train == i, 0], X_train[c_train == i, 1],
      s=50, c=color[i],
      marker='s', edgecolor='black',
      label='cluster '+str(i)
  )
  plt.legend(scatterpoints=1)
  plt.grid()
  plt.show()

plt.scatter(
      kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1],
      s=250,
      c='red', edgecolor='black',
      label='centroids'
)


Update 2:
Thanks to @StupidWolf answer, I can see the pattern of my dataset.
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

pca = PCA(n_components=2)
sc = StandardScaler()
X_scaled = sc.fit_transform(X_train)
PCs = pca.fit_transform(X_scaled)

n_clusters = 4
kmeans = KMeans(n_clusters=n_clusters).fit(X_scaled)
c_train = kmeans.predict(X_scaled)

sns.scatterplot(x=PCs[:, 0], y=PCs[:, 1], hue=c_train)


 A: Since you did not provide the data, most likely the variables you are plotting are columns from the dataset that are not useful in the clustering or are too small in magnitude. I will use an example below:
import numpy as np
import pandas as pd
from sklearn import datasets

np.random.seed(111)
iris = datasets.load_iris()

df=pd.DataFrame(iris.data,columns=iris.feature_names)
d1 = pd.DataFrame({'x1':np.random.uniform(0,1,150),'x2':np.random.uniform(0,1,150)})
df = pd.concat([d1,df],axis=1)

The first two columns don't have useful information and are lower in magnitude compared to the iris data. So if you run kmeans and only plot the first two columns, you see no pattern:
from sklearn.cluster import KMeans
import seaborn as sns

X_train = df.sample(100)
X_val = df.drop(X_train.index).to_numpy()

X_train = X_train.to_numpy()

n_clusters = 4
kmeans = KMeans(n_clusters=n_clusters).fit(X_train)
c_train = kmeans.predict(X_train)
sns.scatterplot(x=X_train[:,0],y=X_train[:,1],hue=c_train)


The better way is to scale your data, do kmeans and plot on a PCA:
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

pca = PCA(n_components=2)
sc = StandardScaler()
X_scaled = sc.fit_transform(X_train)
PCs = pca.fit_transform(X_scaled)

n_clusters = 3
kmeans = KMeans(n_clusters=n_clusters).fit(X_scaled)
c_train = kmeans.predict(X_scaled)

sns.scatterplot(x=PCs[:,0],y=PCs[:,1],hue=c_train)


So you can do likewise for your data, scale all columns, perform kmeans and plot on PCA
A: K-means is not the right tool to use if you are looking to predict the price of houses based on some datasets. K-means is rather a clustering method to be used to solve unsupervised classification problems.
Regression algorithms are the best tool that helps you make predictions of house prices by learning from existing statistical data.
You can use K-means here but in the prediction task. You can for example use it to cluster the houses you have in your datasets into a number of clusters based on their prices.
