I am new to Python. I want to perform K-means clustering on samples generated by two multivariate normal distributions. I generated the samples and performed the K-means clustering but I get an error when I want to plot the clusters. There should be some dimensional problem that I am missing. please see my code below:
mean1 = [-1, -1.5]
cov1 = [[1, .2], [.2, 1]]
x1, y1 = np.random.default_rng().multivariate_normal(mean1, cov1, 100).T
mean2 = [1, 1.5]
cov2 = [[2, .1], [.1,2]]
x2, y2 = np.random.default_rng().multivariate_normal(mean2, cov2, 100).T
X = np.mat([x1,x2]).reshape(-1).transpose()
Y= np.mat([y1,y2]).reshape(-1).transpose()
kmeans = KMeans(n_clusters=2)
kmeans.fit(X)
y_kmeans = np.array(kmeans.predict(X))
plt.scatter(X[:, 0], X[:, 1], c=y_kmeans, s=50, cmap='viridis')

