在画直方图的时候出现了这个问题。

我最开始的代码如下:

import matplotlib.pyplot as plt

plt.hist(x=train.content_type, bins=len(labels_1), color="steelblue", edgecolor='black')
plt.xlabel('事件类型')
plt.ylabel('频数')
plt.show()

这个问题是 x=train.content_type 作为参数传进去的时候,其label(1,2,3....)等也传进去了。所以只要去掉这个前面的索引就行。

aa=[]
for type in train.content_type:
    aa.append(type)
import matplotlib.pyplot as plt

plt.hist(x=aa, bins=len(labels_1), color="steelblue", edgecolor='black')
plt.xlabel('事件类型')
plt.ylabel('频数')
plt.show()

我的方法比较粗暴简单,直接用的是一个数据替代。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐