1 | package de.ugoe.cs.cpdp.wekaclassifier;
|
---|
2 |
|
---|
3 |
|
---|
4 | import weka.classifiers.AbstractClassifier;
|
---|
5 | import weka.core.Capabilities;
|
---|
6 | import weka.core.Instance;
|
---|
7 | import weka.core.Instances;
|
---|
8 | import weka.core.Utils;
|
---|
9 | import weka.core.Capabilities.Capability;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Simple classifier that always predicts the same class
|
---|
13 | *
|
---|
14 | * @author Steffen Herbold
|
---|
15 | */
|
---|
16 | public class FixClass extends AbstractClassifier {
|
---|
17 |
|
---|
18 | private static final long serialVersionUID = 1L;
|
---|
19 |
|
---|
20 | private double fixedClassValue = 0.0d;
|
---|
21 |
|
---|
22 | public FixClass() {
|
---|
23 | // TODO Auto-generated constructor stub
|
---|
24 | }
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Returns default capabilities of the classifier.
|
---|
28 | *
|
---|
29 | * @return the capabilities of this classifier
|
---|
30 | */
|
---|
31 | @Override
|
---|
32 | public Capabilities getCapabilities() {
|
---|
33 | Capabilities result = super.getCapabilities();
|
---|
34 | result.disableAll();
|
---|
35 |
|
---|
36 | // attributes
|
---|
37 | result.enable(Capability.NOMINAL_ATTRIBUTES);
|
---|
38 | result.enable(Capability.NUMERIC_ATTRIBUTES);
|
---|
39 | result.enable(Capability.DATE_ATTRIBUTES);
|
---|
40 | result.enable(Capability.STRING_ATTRIBUTES);
|
---|
41 | result.enable(Capability.RELATIONAL_ATTRIBUTES);
|
---|
42 | result.enable(Capability.MISSING_VALUES);
|
---|
43 |
|
---|
44 | // class
|
---|
45 | result.enable(Capability.NOMINAL_CLASS);
|
---|
46 | result.enable(Capability.NUMERIC_CLASS);
|
---|
47 | result.enable(Capability.MISSING_CLASS_VALUES);
|
---|
48 |
|
---|
49 | // instances
|
---|
50 | result.setMinimumNumberInstances(0);
|
---|
51 |
|
---|
52 | return result;
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public void setOptions(String[] options) throws Exception {
|
---|
57 | fixedClassValue = Double.parseDouble(Utils.getOption('C', options));
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public double classifyInstance(Instance instance) {
|
---|
62 | return fixedClassValue;
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public void buildClassifier(Instances traindata) throws Exception {
|
---|
67 | // do nothing
|
---|
68 | }
|
---|
69 | }
|
---|