[86] | 1 | // Copyright 2015 Georg-August-Universität Göttingen, Germany
|
---|
[41] | 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[2] | 15 | package de.ugoe.cs.cpdp.eval;
|
---|
| 16 |
|
---|
| 17 | import java.io.PrintStream;
|
---|
| 18 | import java.util.Random;
|
---|
| 19 |
|
---|
| 20 | import org.apache.commons.io.output.NullOutputStream;
|
---|
| 21 |
|
---|
| 22 | import weka.classifiers.Classifier;
|
---|
| 23 | import weka.classifiers.Evaluation;
|
---|
| 24 | import weka.core.Instances;
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * Implements the {@link AbstractWekaEvaluation} for 10-fold cross validation.
|
---|
[41] | 28 | *
|
---|
[2] | 29 | * @author Steffen Herbold
|
---|
| 30 | */
|
---|
| 31 | public class CVWekaEvaluation extends AbstractWekaEvaluation {
|
---|
| 32 |
|
---|
[135] | 33 | /*
|
---|
[41] | 34 | * @see de.ugoe.cs.cpdp.eval.AbstractWekaEvaluation#createEvaluator(weka.core.Instances,
|
---|
| 35 | * weka.classifiers.Classifier)
|
---|
| 36 | */
|
---|
| 37 | @Override
|
---|
| 38 | protected Evaluation createEvaluator(Instances testdata, Classifier classifier) {
|
---|
| 39 | PrintStream errStr = System.err;
|
---|
| 40 | System.setErr(new PrintStream(new NullOutputStream()));
|
---|
| 41 | try {
|
---|
| 42 | final Evaluation eval = new Evaluation(testdata);
|
---|
| 43 | eval.crossValidateModel(classifier, testdata, 10, new Random(1));
|
---|
| 44 | return eval;
|
---|
| 45 | }
|
---|
| 46 | catch (Exception e) {
|
---|
| 47 | throw new RuntimeException(e);
|
---|
| 48 | }
|
---|
| 49 | finally {
|
---|
| 50 | System.setErr(errStr);
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[2] | 54 | }
|
---|