我正在使用 python 对我拥有的一组数据进行聚类,但它向我显示了这个错误,我不知道应该在哪里进行更改以及在哪个文件中进行更改:
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
以下是我的代码:
from sklearn import datasets
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.cluster import KMeans
from apyori import apriori
dataset = pd.read_csv('autos1.csv',encoding= 'unicode_escape')
x = dataset.iloc[ : , 1:3]
km = KMeans(n_clusters = 2, random_state = 21)
km.fit(x)
centers = km.cluster_centers_
print(centers)
clusters = x.copy()
clusters ['cluster_id'] = km.fit_predict(x)
plt.xlabel('price')
plt.ylabel('yearOfRegistration')
plt.scatter(clusters['fuelType'], clusters['yearOfRegistration'], c='black', cmap='rainbow')
plt.xlabel('price')
plt.ylabel('yearOfRegistration')
plt.show()
plt.scatter(centers[:,0], centers[:,1], c = 'black', s = 100 , alpha = 0.9 )
plt.scatter(clusters['price'], clusters['yearOfRegistration'], c=clusters['cluster_id'], cmap='rainbow')
plt.xlabel('price')
plt.ylabel('yearOfRegistration')
plt.show()