source: trunk/CrossPare/src/de/ugoe/cs/cpdp/training/RandomClass.java @ 37

Last change on this file since 37 was 34, checked in by atrautsch, 10 years ago

RandomClass? hinzu

File size: 1.3 KB
Line 
1package de.ugoe.cs.cpdp.training;
2
3import java.util.Random;
4import java.util.logging.Level;
5
6import de.ugoe.cs.util.console.Console;
7import weka.classifiers.AbstractClassifier;
8import weka.classifiers.Classifier;
9import weka.core.Instance;
10import weka.core.Instances;
11
12/**
13 * Assigns a random class label to the instance it is evaluated on.
14 *
15 * The range of class labels are hardcoded in fixedClassValues.
16 * This can later be extended to take values from the XML configuration.
17 */
18public class RandomClass extends AbstractClassifier implements ITrainingStrategy, IWekaCompatibleTrainer {
19
20        private static final long serialVersionUID = 1L;
21
22        private double[] fixedClassValues = {0.0d, 1.0d};
23       
24        @Override
25        public void setParameter(String parameters) {
26                // do nothing, maybe take percentages for distribution later
27        }
28
29        @Override
30        public void buildClassifier(Instances arg0) throws Exception {
31                // do nothing
32        }
33
34        @Override
35        public Classifier getClassifier() {
36                return this;
37        }
38
39        @Override
40        public void apply(Instances traindata) {
41                // nothing to do
42        }
43
44        @Override
45        public String getName() {
46                return "RandomClass";
47        }
48       
49        @Override
50        public double classifyInstance(Instance instance) {
51                Random rand = new Random();
52            int randomNum = rand.nextInt(this.fixedClassValues.length);
53                return this.fixedClassValues[randomNum];
54        }
55}
Note: See TracBrowser for help on using the repository browser.