|
Last change
on this file since 7 was
2,
checked in by sherbold, 12 years ago
|
|
|
-
Property svn:mime-type set to
text/plain
|
|
File size:
934 bytes
|
| Line | |
|---|
| 1 | package de.ugoe.cs.cpdp.training;
|
|---|
| 2 |
|
|---|
| 3 | import java.io.PrintStream;
|
|---|
| 4 |
|
|---|
| 5 | import org.apache.commons.io.output.NullOutputStream;
|
|---|
| 6 |
|
|---|
| 7 | import weka.classifiers.Classifier;
|
|---|
| 8 | import weka.core.Instances;
|
|---|
| 9 |
|
|---|
| 10 | public 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.