Add LDA option to the classifier.

This commit is contained in:
Brandon Amos 2016-04-03 15:36:53 -04:00
parent 1b3b48f588
commit 98c42a057c
1 changed files with 8 additions and 0 deletions

View File

@ -35,6 +35,8 @@ import pandas as pd
import openface import openface
from sklearn.pipeline import Pipeline
from sklearn.lda import LDA
from sklearn.preprocessing import LabelEncoder from sklearn.preprocessing import LabelEncoder
from sklearn.svm import SVC from sklearn.svm import SVC
from sklearn.mixture import GMM from sklearn.mixture import GMM
@ -100,6 +102,11 @@ def train(args):
elif args.classifier == 'GMM': elif args.classifier == 'GMM':
clf = GMM(n_components=nClasses) clf = GMM(n_components=nClasses)
if args.ldaDim > 0:
clf_final = clf
clf = Pipeline([('lda', LDA(n_components=args.ldaDim)),
('clf', clf_final)])
clf.fit(embeddings, labelsNum) clf.fit(embeddings, labelsNum)
fName = "{}/classifier.pkl".format(args.workDir) fName = "{}/classifier.pkl".format(args.workDir)
@ -147,6 +154,7 @@ if __name__ == '__main__':
subparsers = parser.add_subparsers(dest='mode', help="Mode") subparsers = parser.add_subparsers(dest='mode', help="Mode")
trainParser = subparsers.add_parser('train', trainParser = subparsers.add_parser('train',
help="Train a new classifier.") help="Train a new classifier.")
trainParser.add_argument('--ldaDim', type=int, default=-1)
trainParser.add_argument('--classifier', type=str, trainParser.add_argument('--classifier', type=str,
choices=['LinearSvm', 'GMM'], choices=['LinearSvm', 'GMM'],
help='The type of classifier to use.', help='The type of classifier to use.',