1 | package de.ugoe.cs.cpdp.training; |
---|
2 | |
---|
3 | import java.util.Random; |
---|
4 | import java.util.logging.Level; |
---|
5 | |
---|
6 | import de.ugoe.cs.util.console.Console; |
---|
7 | import weka.classifiers.AbstractClassifier; |
---|
8 | import weka.classifiers.Classifier; |
---|
9 | import weka.core.Instance; |
---|
10 | import 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 | */ |
---|
18 | public 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 | } |
---|