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

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