我现在正在使用Machine Learning
方法来学习K-Means
,但是使用matplotlib
进行可视化时会出现一些错误。有人可以帮忙吗?
代码在这里:
url = 'https://pokemondb.net/pokedex/all'
header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/50.0.2661.75 Safari/537.36','X-Requested-With': 'XMLHttpRequest'}
r = requests.get(url,headers=header)
df = pd.read_html(r.text,header=0)[0]
df.rename(columns={'Sp. Atk':'SpAtk','Sp. Def':'SpDef'},inplace=True)
df.to_csv('data_pokemon.csv',index=False)
raw_data = df.iloc[:,5:7]
x_array = np.array(raw_data)
k_means = KMeans(n_clusters=3,random_state=200)
k_means.fit(x_array)
df['Cluster'] = k_means.labels_.astype('int64')
plt.scatter(df['Attack'],df['Defense'],s = 20,c = df['Cluster'],marker='o',alpha='0.5')
plt.title('Clustering K-Means')
plt.xlabel('Attack')
plt.ylabel('Defense')
plt.show()
当我尝试将其可视化为分散点时,出现错误:
UFuncTypeError: ufunc 'clip' did not contain a loop with signature matching types (dtype('<U11'),dtype('<U11'),dtype('<U11')) -> dtype('<U11')
<Figure size 432x288 with 1 Axes>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。