Repository /Examples/MajorityClassifier_rseslib.jar:org.tunedit.examples.rseslib.MajorityClassifier


Back

No file description

Source code

/*
 *  Copyright (C) 2009 by TunedIT
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/.
 */
package org.tunedit.examples.rseslib;

import java.util.Properties;
import rseslib.processing.classification.Classifier;
import rseslib.structure.data.DoubleData;
import rseslib.structure.table.DoubleDataTable;
import rseslib.system.*;
import rseslib.system.progress.Progress;

/**
 * Classifier assigning always the same decision.
 * This is the most frequent decision in the training set.
 */
public class MajorityClassifier extends ConfigurationWithStatistics implements Classifier
{
    /** Decision to be returned. */
	double m_nDecision;

	/**
    /**
     * Constructor selects the majority decision.
     *
     * @param prop                Parameters of this classifier. If null,
     *                            parameters are loaded from the configuration directory.
     * @param trainTable          Table used to train classifier.
     * @param prog                Progress object for reporting training process.
	 * @throws PropertyConfigurationException If the classifier properties are wrong.
     * @throws InterruptedException When a user interrupts training.
	 */
    public MajorityClassifier(Properties prop, DoubleDataTable trainTable, Progress prog) throws PropertyConfigurationException, InterruptedException
    {
        super(prop);
        prog.set("Training the majority classifier", 1);
        int[] decDistr = trainTable.getDecisionDistribution();
        int bestDecision = 0;
        for (int dec = 1; dec < decDistr.length; dec++)
            if (decDistr[dec] > decDistr[bestDecision]) bestDecision = dec;
        m_nDecision = trainTable.attributes().nominalDecisionAttribute().globalValueCode(bestDecision);
        prog.step();
    }

    /**
     * Returns the majority decision.
     *
     * @param dObj  Test object.
     * @return      Majority decision.
     */
    public double classify(DoubleData dObj)
    {
    	return m_nDecision;
    }

    /**
     * Calculates statistics.
     */
    public void calculateStatistics()
    {
    }

    /**
     * Resets statistics.
     */
    public void resetStatistics()
    {
    }
}
Copyright © 2008-2011 by TunedIT
Design by luksite