1 | // Copyright 2015 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.cpdp.training; |
---|
16 | |
---|
17 | import weka.classifiers.AbstractClassifier; |
---|
18 | import weka.core.Capabilities; |
---|
19 | import weka.core.Instance; |
---|
20 | import weka.core.Instances; |
---|
21 | import weka.core.Utils; |
---|
22 | import weka.core.Capabilities.Capability; |
---|
23 | |
---|
24 | /** |
---|
25 | * Simple classifier that always predicts the same class |
---|
26 | * |
---|
27 | * @author Steffen Herbold |
---|
28 | */ |
---|
29 | public class FixClass extends AbstractClassifier { |
---|
30 | |
---|
31 | /** |
---|
32 | * default serial ID |
---|
33 | */ |
---|
34 | private static final long serialVersionUID = 1L; |
---|
35 | |
---|
36 | /** |
---|
37 | * default prediction: non-defective |
---|
38 | */ |
---|
39 | private double fixedClassValue = 0.0d; |
---|
40 | |
---|
41 | /** |
---|
42 | * Returns default capabilities of the classifier. |
---|
43 | * |
---|
44 | * @return the capabilities of this classifier |
---|
45 | */ |
---|
46 | @Override |
---|
47 | public Capabilities getCapabilities() { |
---|
48 | Capabilities result = super.getCapabilities(); |
---|
49 | result.disableAll(); |
---|
50 | |
---|
51 | // attributes |
---|
52 | result.enable(Capability.NOMINAL_ATTRIBUTES); |
---|
53 | result.enable(Capability.NUMERIC_ATTRIBUTES); |
---|
54 | result.enable(Capability.DATE_ATTRIBUTES); |
---|
55 | result.enable(Capability.STRING_ATTRIBUTES); |
---|
56 | result.enable(Capability.RELATIONAL_ATTRIBUTES); |
---|
57 | result.enable(Capability.MISSING_VALUES); |
---|
58 | |
---|
59 | // class |
---|
60 | result.enable(Capability.NOMINAL_CLASS); |
---|
61 | result.enable(Capability.NUMERIC_CLASS); |
---|
62 | result.enable(Capability.MISSING_CLASS_VALUES); |
---|
63 | |
---|
64 | // instances |
---|
65 | result.setMinimumNumberInstances(0); |
---|
66 | |
---|
67 | return result; |
---|
68 | } |
---|
69 | |
---|
70 | /* |
---|
71 | * (non-Javadoc) |
---|
72 | * |
---|
73 | * @see weka.classifiers.AbstractClassifier#setOptions(java.lang.String[]) |
---|
74 | */ |
---|
75 | @Override |
---|
76 | public void setOptions(String[] options) throws Exception { |
---|
77 | fixedClassValue = Double.parseDouble(Utils.getOption('C', options)); |
---|
78 | } |
---|
79 | |
---|
80 | /* |
---|
81 | * (non-Javadoc) |
---|
82 | * |
---|
83 | * @see weka.classifiers.AbstractClassifier#classifyInstance(weka.core.Instance) |
---|
84 | */ |
---|
85 | @Override |
---|
86 | public double classifyInstance(Instance instance) { |
---|
87 | return fixedClassValue; |
---|
88 | } |
---|
89 | |
---|
90 | /* |
---|
91 | * (non-Javadoc) |
---|
92 | * |
---|
93 | * @see weka.classifiers.Classifier#buildClassifier(weka.core.Instances) |
---|
94 | */ |
---|
95 | @Override |
---|
96 | public void buildClassifier(Instances traindata) throws Exception { |
---|
97 | // do nothing |
---|
98 | } |
---|
99 | } |
---|