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

Last change on this file since 39 was 31, checked in by atrautsch, 10 years ago

fixed class trainer

File size: 2.0 KB
Line 
1package de.ugoe.cs.cpdp.training;
2
3import weka.classifiers.AbstractClassifier;
4import weka.classifiers.Classifier;
5import weka.core.Capabilities;
6import weka.core.Instance;
7import weka.core.Instances;
8import weka.core.Utils;
9import weka.core.Capabilities.Capability;
10
11/**
12 * Simple classifier that always predicts the same class
13 *
14 * @author Steffen Herbold
15 */
16public class FixClass extends AbstractClassifier implements ITrainingStrategy, IWekaCompatibleTrainer {
17
18        private static final long serialVersionUID = 1L;
19
20        private double fixedClassValue = 0.0d;
21
22        /**
23         * Returns default capabilities of the classifier.
24         *
25         * @return the capabilities of this classifier
26         */
27        @Override
28        public Capabilities getCapabilities() {
29                Capabilities result = super.getCapabilities();
30                result.disableAll();
31
32                // attributes
33                result.enable(Capability.NOMINAL_ATTRIBUTES);
34                result.enable(Capability.NUMERIC_ATTRIBUTES);
35                result.enable(Capability.DATE_ATTRIBUTES);
36                result.enable(Capability.STRING_ATTRIBUTES);
37                result.enable(Capability.RELATIONAL_ATTRIBUTES);
38                result.enable(Capability.MISSING_VALUES);
39
40                // class
41                result.enable(Capability.NOMINAL_CLASS);
42                result.enable(Capability.NUMERIC_CLASS);
43                result.enable(Capability.MISSING_CLASS_VALUES);
44
45                // instances
46                result.setMinimumNumberInstances(0);
47
48                return result;
49        }
50
51        @Override
52        public void setOptions(String[] options) throws Exception {
53                fixedClassValue = Double.parseDouble(Utils.getOption('C', options));
54        }
55
56        @Override
57        public double classifyInstance(Instance instance) {
58                return fixedClassValue;
59        }
60
61        @Override
62        public void buildClassifier(Instances traindata) throws Exception {
63                // do nothing
64        }
65
66        @Override
67        public void setParameter(String parameters) {
68                try {
69                        this.setOptions(parameters.split(" "));
70                } catch (Exception e) {
71                        e.printStackTrace();
72                }               
73        }
74
75        @Override
76        public void apply(Instances traindata) {
77                // do nothing!
78        }
79
80        @Override
81        public String getName() {
82                return "FixClass";
83        }
84
85        @Override
86        public Classifier getClassifier() {
87                return this;
88        }
89
90}
Note: See TracBrowser for help on using the repository browser.