I am using kmeans to cluster some data with 2 features. Not sure I understand why kmeans is producing the clusters I see:
Why would kmeans not cluster these points in a way that matches what we would expect visually looking at the data? Why are seemingly random points in the middle of visual clusters being put into a second cluster like that?
The code I am running:
cols = ['col1', 'col2'] features = map(lambda x: df[x], cols) input = np.matrix(list(zip(*features))) scaler = StandardScaler() scaler.fit(input) input_scaled = scaler.transform(input) algo = KMeans(n_clusters=2) algo.fit(input_scaled) df['cluster'] = pd.Series(algo.labels_) sns.lmplot(x=cols,y=cols,data=df, fit_reg=False, hue='cluster')