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

Last change on this file since 117 was 86, checked in by sherbold, 9 years ago
  • switched workspace encoding to UTF-8 and fixed broken characters
File size: 2.3 KB
Line 
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
15package de.ugoe.cs.cpdp.training;
16
17import weka.classifiers.AbstractClassifier;
18import weka.core.Capabilities;
19import weka.core.Instance;
20import weka.core.Instances;
21import weka.core.Utils;
22import weka.core.Capabilities.Capability;
23
24/**
25 * Simple classifier that always predicts the same class
26 *
27 * @author Steffen Herbold
28 */
29public class FixClass extends AbstractClassifier {
30
31    private static final long serialVersionUID = 1L;
32
33    private double fixedClassValue = 0.0d;
34
35    /**
36     * Returns default capabilities of the classifier.
37     *
38     * @return the capabilities of this classifier
39     */
40    @Override
41    public Capabilities getCapabilities() {
42        Capabilities result = super.getCapabilities();
43        result.disableAll();
44
45        // attributes
46        result.enable(Capability.NOMINAL_ATTRIBUTES);
47        result.enable(Capability.NUMERIC_ATTRIBUTES);
48        result.enable(Capability.DATE_ATTRIBUTES);
49        result.enable(Capability.STRING_ATTRIBUTES);
50        result.enable(Capability.RELATIONAL_ATTRIBUTES);
51        result.enable(Capability.MISSING_VALUES);
52
53        // class
54        result.enable(Capability.NOMINAL_CLASS);
55        result.enable(Capability.NUMERIC_CLASS);
56        result.enable(Capability.MISSING_CLASS_VALUES);
57
58        // instances
59        result.setMinimumNumberInstances(0);
60
61        return result;
62    }
63
64    @Override
65    public void setOptions(String[] options) throws Exception {
66        fixedClassValue = Double.parseDouble(Utils.getOption('C', options));
67    }
68
69    @Override
70    public double classifyInstance(Instance instance) {
71        return fixedClassValue;
72    }
73
74    @Override
75    public void buildClassifier(Instances traindata) throws Exception {
76        // do nothing
77    }
78}
Note: See TracBrowser for help on using the repository browser.