2016-12-28 75 views
0

我有绘制的散点图多维的EPlotting散点图特点

我想绘制音频的值在散点图上清晰的视觉效果功能(不是我有我的训练5个的音频文件设置的问题 - 我将用它来训练KNN/SVM等增加我的数据集之后)

标记的training_labels是 [0, 0, 1, 2, 1]

虽然training_feature值

[ 
    [103.359375, [11, 36, 60, 85, 110, 134, 159, 183, 208, 232, 257, 286, 310, 335]], 
    [89.10290948275862, [11, 41, 69, 98, 127, 155, 184, 213, 241, 270, 299, 327, 356]], 
    [151.99908088235293, [7, 24, 41, 57, 73, 90, 107, 123, 140, 157, 173, 189, 206, 223, 239, 256, 272, 290, 307, 325, 343, 360, 377]], 
    [143.5546875, [39, 57, 77, 95, 114, 132, 150, 168, 186, 204, 222, 239, 256, 272, 288, 305, 322, 340]], 
    [83.35433467741936, [8, 38, 70, 101, 137, 168, 199, 230, 266, 298, 334, 365]] 
] 

进行分类的每个对象有2个特点叫tempobeat per minute

我怎么能在散点图中绘制的?

我尝试以下,但它失败,因为x和y

featureA = [x[0] for x in training_features] 
featureB = [x[1] for x in training_features] 

plt.scatter(featureA[:2], featureB[:2]) 
plt.scatter(featureA[2:], featureB[2:], color='r') 
plt.xlabel('Beat Frame') 
plt.ylabel('Tempo') 

的大小之间的差异这给我一个错误ValueError: setting an array element with a sequence.。请帮助:)

编辑:还有一两件事,我怎么能绘制多个功能即(> 2),我想使用频谱质心,过零率,MFCC等,然后画出结果

+0

你必须每x值超过10的y值。你需要告诉我们你想对什么进行阴谋。 – ImportanceOfBeingErnest

+0

我不知道tbh,我只是为了检查它们如何在scatterplot中可视化@ImportanceOfBeingErnest –

回答

1

由于ImportanceOfBeingEarnest说,问题是数组的大小。

对于散射,您需要一个包含点(x和y)坐标的数组。 但是featureB是一个有许多值的数组。

>>> print(featureB[:2]) 
[[11, 36, 60, 85, 110, 134, 159, 183, 208, 232, 257, 286, 310, 335], 
[11, 41, 69, 98, 127, 155, 184, 213, 241, 270, 299, 327, 356]] 

然后,你需要变换training_feature到这样的事情:

points = [] 
for x in training_feature: 
    for y in x[1]: 
     points.append([x[0], y]) 
points = np.array(points) 

points.shape # (80, 2) 

现在,如果我们可以用plt.scatter!

plt.scatter(points[:, 0], points[:, 1]) 

scatter_example

我不明白,你想情节,但我希望它为你工作!...

+0

感谢队友,非常感谢:) –