绘制语音频谱图的TSNE散点图

时间:2019-05-10 11:29:23

标签: python tensorflow keras scatter-plot speech

我有属于4类的语音波形频谱图。我想绘制TSNE散点图,以可视化语音文件在四个类之间的分布。 tsne我该怎么办?

1 个答案:

答案 0 :(得分:2)

假设您的频谱图数据为形状(n_points, n_dims)和相关标签的数组。

在这里我将产生地雷:

import matplotlib.pyplot as plt
import numpy as np
from sklearn.manifold import TSNE

n_points = 50
n_classes = 4
n_dims = 150

# Generate data
labels = np.random.randint(n_classes, size=n_points)
X = np.random.normal(size=(n_points, n_dims))
X = (X.transpose() + labels).transpose()

然后,您只需将TSNE应用于数据即可使其二维化并绘制。

# Do TSNE
X_embedded = TSNE(n_components=2).fit_transform(X)

# Plot
names = ['class_1', 'class_2', 'class_3', 'class_4']
for i in range(n_classes):
    X_label = X_embedded[np.where(labels == i)]
    plt.scatter(X_label[:, 0], X_label[:, 1], label=names[i])
plt.legend()

TSNE plot of the clusters