source: trunk/CrossPare/src/de/ugoe/cs/cpdp/training/WekaTraining.java @ 9

Last change on this file since 9 was 2, checked in by sherbold, 10 years ago
  • initial commit
  • Property svn:mime-type set to text/plain
File size: 934 bytes
Line 
1package de.ugoe.cs.cpdp.training;
2
3import java.io.PrintStream;
4
5import org.apache.commons.io.output.NullOutputStream;
6
7import weka.classifiers.Classifier;
8import weka.core.Instances;
9
10public abstract class WekaTraining implements ITrainingStrategy, WekaCompatibleTrainer {
11       
12        private final Classifier classifier = setupClassifier();
13
14        protected abstract Classifier setupClassifier();
15       
16        @Override
17        public Classifier getClassifier() {
18                return classifier;
19        }
20       
21        @Override
22        public void apply(Instances traindata) {
23                PrintStream errStr      = System.err;
24                System.setErr(new PrintStream(new NullOutputStream()));
25                try {
26                        classifier.buildClassifier(traindata);
27                } catch (Exception e) {
28                        throw new RuntimeException(e);
29                } finally {
30                        System.setErr(errStr);
31                }
32        }
33       
34        @Override
35        public void setParameter(String parameters) {
36                // TODO should allow passing of weka parameters to the classifier
37        }
38}
Note: See TracBrowser for help on using the repository browser.