1
我面临一个(可能很简单)的问题,我必须使用PCA来减少我的特征向量的维数。所有这一切的主要点是创建一个预测由音素组成的句子的分类器。我用几小时的句子训练我的模型(句子只有10个),每个句子都有一个由一组音素组成的标签(见下文)。PCA应用于MFCC饲养GMM分类器(sklearn库)
我迄今所做如下:
import mdp
from sklearn import mixture
from features import mdcc
def extract_mfcc():
X_train = []
directory = test_audio_folder
# Iterate through each .wav file and extract the mfcc
for audio_file in glob.glob(directory):
(rate, sig) = wav.read(audio_file)
mfcc_feat = mfcc(sig, rate)
X_train.append(mfcc_feat)
return np.array(X_train)
def extract_labels():
Y_train = []
# here I have all the labels - each label is a sentence composed by a set of phonemes
with open(labels_files) as f:
for line in f: # Ex: line = AH0 P IY1 S AH0 V K EY1 K
Y_train.append(line)
return np.array(Y_train)
def main():
__X_train = extract_mfcc()
Y_train = extract_labels()
# Now, according to every paper I read, I need to reduce the dimensionality of my mfcc vector before to feed my gaussian mixture model
X_test = []
for feat in __X_train:
pca = mdp.pca(feat)
X_test.append(pca)
n_classes = 10 # I'm trying to predict only 10 sentences (each sentence is composed by the phonemes described above)
gmm_classifier = mixture.GMM(n_components=n_classes, covariance_type='full')
gmm_classifier.fit(X_train) # error here!reason: each "pca" that I appended before in X_train has a different shape (same number of columns though)
我怎么能降维和,在同一时间,为每个PCA我提取相同的形状?
我还尝试了新事物:调用gmm_classifier.fit(...)中的for循环,我得到PCA矢量(见下面的代码)。函数fit()有效,但我不确定我是否正确地训练GMM。
n_classes = 10
gmm_classifier = mixture.GMM(n_components=n_classes, covariance_type='full')
X_test = []
for feat in __X_train:
pca = mdp.pca(feat)
gmm_classifier.fit(pca) # in this way it works, but I'm not sure if it actually model is trained correctly
非常感谢
您不应该先将您的整个数据进行PCA处理,然后使用新的减少的数据来训练您的GMM分类器吗? –