我面临一个(可能很简单)问题,必须使用PCA降低特征向量的维度。所有这些的要点是创建一个分类器来预测由音素组成的句子。我用人们发音的几个小时的句子来训练我的模型(句子只有10个),每个句子都有一个由一组音素组成的标签(见下文)。
到目前为止,我所做的是:
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具有相同的形状?
我还尝试了一个新方法:在for循环中调用gmm_classifier.fit(…),在那里我获得了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
非常感谢
关于您的最后一条评论/问题:gmm_classifier.fit(pca)#以这种方式工作,但我不确定它是否真的对模型进行了正确的训练无论何时调用此函数,分类器都会忘记以前的信息,只根据最后的数据进行训练。试着在循环中添加壮举,然后进行调整。