【发布时间】:2020-01-08 17:25:20
【问题描述】:
我有一个包含不同情绪类别(标签)的数据集。您可以从下面代码中定义的“标签”变量中查看哪些类别。这些类别中的每一个在此数据集中都有不同数量的可用数据,我试图通过直方图箱来表示数据集的分布。
import matplotlib.pyplot as plt
import numpy as np
#labels inside emo variable, however they are labeled with numbers from 0 to 6 in sequence according to labels variable
labels = ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise','neutral']
labels_np = np.array(labels)
#df_training is holding the train_set.csv, where I am selecting a single column which is 'emotion'
emo = df_training["emotion"].hist()
plt.plot(labels_np,emo)
df_training['emotion']:
这是我得到的错误:
**ValueError:** x and y must have same first dimension, but have shapes (7,) and (1,)
这是所需的输出:
【问题讨论】:
-
除非您向他们提供Minimal, Complete, and Verifiable example,否则人们很难帮助您
-
至于代码部分,我已经给出了我所拥有的一切,我将尝试解释变量可能是什么,至于我想要实现的目标我想我已经描述了所有需要的东西,包括图片。
-
你需要给
df_training -
希望它现在更清楚,我已经在代码中评论了
-
如您所见,通常如果我不在情节中包含 labels_np ,我会将这些垃圾箱标记为从 0 开始(生气)到 6 (中性),并且我正在尝试使用上面的方法将它们命名为图片!
标签: python pandas matplotlib histogram