-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrainClassifier.m
More file actions
37 lines (30 loc) · 811 Bytes
/
trainClassifier.m
File metadata and controls
37 lines (30 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [classifier, ds] = trainClassifier(g, classifier)
% accepts struct g with fields
% name - genre
% files - struct of files with feature data
% ceps (long x 13)
% features (1 x 13
ds = prtDataSetClass;
nGenre = length(g);
classNames = cell(1,nGenre);
features = [];
labels = [];
for ii=1:nGenre
nFiles = length(g(ii).files);
classNames{ii} = {ii-1,g(ii).name};
for jj=1:nFiles
newFeat = g(ii).files(jj).features;
if ~any(isnan(newFeat) | isinf(newFeat))
features = [features; newFeat];
labels = [labels; ii-1];
end
end
end
ds = ds.setClassNames(classNames);
ds.data = features;
ds.targets = labels;
% zmuv = prtPreProcZmuv;
% zmuv = zmuv.train(ds);
% ds = zmuv.run(ds);
classifier = classifier.train(ds);
end