So I used the below code and I want to know how to color code the scatter plot per KMeans cluster. I’m new to coding, so please bear with me:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
data = pd.read_csv(“Banknote authentication dataset.csv”)
var = data[‘V1’]
skew = data[‘V2’]
varskew = np.column_stack((var,skew))
kem_res = KMeans(n_clusters=2).fit(varskew)
clusters = km_res.cluster_centers_
plt.scatter(varskew[:,0],varskew[:,1],s=10,alpha=0.5)
plt.scatter(clusters[:,0],clusters[:,1],s=50)
plt.show()
So, I got the dataset and the clusters plotted, but I want to color code the dataset per the cluster they belong to.
PS: I’m using Python3 on iPad using Juno application.
This is the dataset being used
Scatter Plot as per above code:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…