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を同じ形状にすると同時に、次元を減らすにはどうすればよいですか?
また、新しいことも試しました。PCA ベクトルを取得する for ループ内で gmm_classifier.fit(...) を呼び出します(以下のコードを参照)。関数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
どうもありがとう