2016-12-28 85 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

感謝隊友,非常感謝:) –