简体   繁体   中英

TypeError: __init__() got an unexpected keyword argument 'madataset_iter'

My question is about K-means clustering algorithm , I keep getting the error TypeError: __init__() got an unexpected keyword argument 'madataset_iter' {it was sorted out after correcting the typo error} when I try to visualize the clusters after fitting my dataset into the model. Below my code:

##Fitting kmeans to the dataset with k=4
km4=KMeans(n_clusters=4,init='k-means++', max_iter=300, n_init=10, random_state=0)
y_means = km4.fit_predict(dataset)

#Visualizing the clusters for k=4
plt.scatter(dataset[y_means==0,0],dataset[y_means==0,1],s=50, c='purple',label='Cluster1')
plt.scatter(dataset[y_means==1,0],dataset[y_means==1,1],s=50, c='blue',label='Cluster2')
plt.scatter(dataset[y_means==2,0],dataset[y_means==2,1],s=50, c='green',label='Cluster3')
plt.scatter(dataset[y_means==3,0],dataset[y_means==3,1],s=50, c='cyan',label='Cluster4')
plt.scatter(km4.cluster_centers_[:,0], km4.cluster_centers_[:,1],s=200,marker='s', c='red', 
alpha=0.7, label='Centroids')
plt.title('Customer segments')
plt.xlabel('Annual income of customer')
plt.ylabel('Annual spend from customer on site')
plt.legend()
plt.show()

The new error i am getting is

'TypeError: '(array([False, False, False, False, False, False, False, False, False,'

The error message means that the KMeans constructor __init()__ does not have a madataset_iter argument. Is there a typo? Should it be metadataset_iter instead?

Otherwise you should check the KMeans function documentation or code. There is no import statement in the code example provided, so we can not look it up.

Assuming you are using the KMeans from sklearn , the constructor for this object does not accept any argument called madataset_iter . The other named argument you are using do appear in the documentation I linked to, so it remains unclear where you got that argument name from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM