plt.scatter中分散的点数有限制吗?

时间:2017-12-12 15:18:33

标签: python matplotlib

A sample of the dataset

我正在开发一个群集项目。当我完成聚类时,我想使用python' s plt.scatter()来显示数据。但是,我没有得到整个点。我预计的总点数约为9000.但是,我只有20左右。

我的问题是,我可以使用plt.scatter列出的点数有限吗?

# K-Means Clustering

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.preprocessing import LabelEncoder

# Importing the dataset
dataset = pd.read_csv('FYP.csv')
X = dataset.iloc[:, [10]].values
Y=dataset.iloc[:, [9]].values
done = np.vstack((Y,X)).T


#Using LabelEncoder to change categorical values to numerical ones
labelencoder_X = LabelEncoder()
X=labelencoder_X.fit_transform(X[:,0])
labelencoder_Y = LabelEncoder()
Y=labelencoder_Y.fit_transform(Y[:,0])



# Using the elbow method to find the optimal number of clusters
from sklearn.cluster import KMeans
wcss = []
for i in range(1, 11):
    kmeans = KMeans(n_clusters = i, init = 'k-means++', max_iter = 1000, n_init = 10)
    kmeans.fit(done)
    wcss.append(kmeans.inertia_)
plt.plot(range(1, 11), wcss)
plt.title('The Elbow Method')
plt.xlabel('Number of clusters')
plt.ylabel('WCSS')
plt.show()

# Fitting K-Means to the dataset
kmeans = KMeans(n_clusters = 3, init = 'k-means++', max_iter = 1000, n_init = 10)
y_kmeans = kmeans.fit_predict(done)

# Visualising the clusters
plt.scatter(done[y_kmeans == 0, 0], done[y_kmeans == 0, 1], s = 100, c = 'red', label = 'Cluster 1')
plt.scatter(done[y_kmeans == 1, 0], done[y_kmeans == 1, 1], s = 100, c = 'blue', label = 'Cluster 2')
plt.scatter(done[y_kmeans == 2, 0], done[y_kmeans == 2, 1], s = 100, c = 'green', label = 'Cluster 3')
plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 300, c = 'yellow', label = 'Centroids')
plt.title('Clusters of customers')
plt.xlabel("Category")
plt.ylabel("Subcategory")
plt.show()

0 个答案:

没有答案