source: trunk/CrossPare/src/de/ugoe/cs/cpdp/wekaclassifier/FixClass.java @ 46

Last change on this file since 46 was 41, checked in by sherbold, 9 years ago
  • formatted code and added copyrights
  • Property svn:mime-type set to text/plain
File size: 2.5 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.wekaclassifier;
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    public FixClass() {
36        // TODO Auto-generated constructor stub
37    }
38
39    /**
40     * Returns default capabilities of the classifier.
41     *
42     * @return the capabilities of this classifier
43     */
44    @Override
45    public Capabilities getCapabilities() {
46        Capabilities result = super.getCapabilities();
47        result.disableAll();
48
49        // attributes
50        result.enable(Capability.NOMINAL_ATTRIBUTES);
51        result.enable(Capability.NUMERIC_ATTRIBUTES);
52        result.enable(Capability.DATE_ATTRIBUTES);
53        result.enable(Capability.STRING_ATTRIBUTES);
54        result.enable(Capability.RELATIONAL_ATTRIBUTES);
55        result.enable(Capability.MISSING_VALUES);
56
57        // class
58        result.enable(Capability.NOMINAL_CLASS);
59        result.enable(Capability.NUMERIC_CLASS);
60        result.enable(Capability.MISSING_CLASS_VALUES);
61
62        // instances
63        result.setMinimumNumberInstances(0);
64
65        return result;
66    }
67
68    @Override
69    public void setOptions(String[] options) throws Exception {
70        fixedClassValue = Double.parseDouble(Utils.getOption('C', options));
71    }
72
73    @Override
74    public double classifyInstance(Instance instance) {
75        return fixedClassValue;
76    }
77
78    @Override
79    public void buildClassifier(Instances traindata) throws Exception {
80        // do nothing
81    }
82}
Note: See TracBrowser for help on using the repository browser.