Python 3.x 类型错误:不可损坏的类型:';numpy.ndarray和#x27;(k表示聚类)

Python 3.x 类型错误:不可损坏的类型:';numpy.ndarray和#x27;(k表示聚类),python-3.x,numpy,cluster-analysis,k-means,Python 3.x,Numpy,Cluster Analysis,K Means,我的数据集是一个140*140的相关矩阵,显示了相同140个变量之间的关系。我使用弯头方法来查找最大数量的簇。我得到的错误是 res=cache.get(项) TypeError:不可损坏的类型:“numpy.ndarray” 看起来缓存是数组数组没有get函数看起来缓存是数组数组没有get函数 # K-means clustering # Using the elbow method to find the maximum number of clusters from sklearn.

我的数据集是一个140*140的相关矩阵,显示了相同140个变量之间的关系。我使用弯头方法来查找最大数量的簇。我得到的错误是

res=cache.get(项)

TypeError:不可损坏的类型:“numpy.ndarray”
看起来缓存是数组数组没有get函数看起来缓存是数组数组没有get函数
 # K-means clustering
 # Using the elbow method to find the maximum number of clusters

from sklearn.cluster import KMeans
        wcss = []

for i in range(1,11):

    kmeans = KMeans(n_clusters = i, init = 'k-means++', random_state = 40)
    kmeans.fit(X)
    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()
#Applying K-means to my Data set


kmeans = KMeans(n_clusters = 4, init = 'k-means++', random_state = 40)
y_kmeans = kmeans.fit_predict(X)

# Visualizing the clusters

plt.scatter(X[y_kmeans == 0,0], X[y_kmeans == 0,1], s = 10, c = 'red', label = 'Cluster 1')

plt.scatter(X[y_kmeans == 1,0], X[y_kmeans == 1,1], s = 10, c = 'blue', label = 'Cluster 2')

plt.scatter(X[y_kmeans == 2,0], X[y_kmeans == 2,1], s = 10, c = 'green', label = 'Cluster 3')

plt.scatter(X[y_kmeans == 3,0], X[y_kmeans == 3,1], s = 10, c = 'green', label = 'Cluster 4')


plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 30, c ='yellow', label = 'Centroids')



 plt.title('K-Means Clustering of Inbreds')


    plt.xlabel('X')

    plt.ylabel('Y')

    plt.legend()

    plt.show()