我面临一个(可能是简单的)问题,我必须使用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
非常感谢
答案 0 :(得分:0)
关于你的上一条评论/问题: gmm_classifier.fit(pca)#以这种方式工作,但我不确定它是否真的模型正确训练 无论何时调用此方法,分类器都会忘记以前的信息,并且只能通过最后的数据进行训练。尝试在环中添加专长然后适合。