Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
The Waikato Environment for Knowledge Analysis (WEKA), a machine
learning workbench. This version represents the developer version, the
"bleeding edge" of development, you could say. New functionality gets added
to this version.
/*
* 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 .
*/
/*
* AdaBoostM1.java
* Copyright (C) 1999-2014 University of Waikato, Hamilton, New Zealand
*
*/
package weka.classifiers.meta;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Random;
import java.util.Vector;
import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.RandomizableIteratedSingleClassifierEnhancer;
import weka.classifiers.Sourcable;
import weka.classifiers.IterativeClassifier;
import weka.core.Capabilities;
import weka.core.Capabilities.Capability;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.Randomizable;
import weka.core.RevisionUtils;
import weka.core.TechnicalInformation;
import weka.core.TechnicalInformation.Field;
import weka.core.TechnicalInformation.Type;
import weka.core.TechnicalInformationHandler;
import weka.core.Utils;
import weka.core.WeightedInstancesHandler;
/**
* Class for boosting a nominal class classifier using
* the Adaboost M1 method. Only nominal class problems can be tackled. Often
* dramatically improves performance, but sometimes overfits.
*
* For more information, see
*
* Yoav Freund, Robert E. Schapire: Experiments with a new boosting algorithm.
* In: Thirteenth International Conference on Machine Learning, San Francisco,
* 148-156, 1996.
*
*
*
* BibTeX:
*
*
* @inproceedings{Freund1996,
* address = {San Francisco},
* author = {Yoav Freund and Robert E. Schapire},
* booktitle = {Thirteenth International Conference on Machine Learning},
* pages = {148-156},
* publisher = {Morgan Kaufmann},
* title = {Experiments with a new boosting algorithm},
* year = {1996}
* }
*
*
*
*
* Valid options are:
*
*
*
* -P <num>
* Percentage of weight mass to base training on.
* (default 100, reduce to around 90 speed up)
*
*
*
* -Q
* Use resampling for boosting.
*
*
*
* -S <num>
* Random number seed.
* (default 1)
*
*
*
* -I <num>
* Number of iterations.
* (default 10)
*
*
*
* -D
* If set, classifier is run in debug mode and
* may output additional info to the console
*
*
*
* -W
* Full name of base classifier.
* (default: weka.classifiers.trees.DecisionStump)
*
*
*
* Options specific to classifier weka.classifiers.trees.DecisionStump:
*
*
*
* -D
* If set, classifier is run in debug mode and
* may output additional info to the console
*
*
*
*
* Options after -- are passed to the designated classifier.
*
*
* @author Eibe Frank ([email protected])
* @author Len Trigg ([email protected])
* @version $Revision: 10969 $
*/
public class AdaBoostM1 extends RandomizableIteratedSingleClassifierEnhancer
implements WeightedInstancesHandler, Sourcable, TechnicalInformationHandler, IterativeClassifier {
/** for serialization */
static final long serialVersionUID = -1178107808933117974L;
/** Max num iterations tried to find classifier with non-zero error. */
private static int MAX_NUM_RESAMPLING_ITERATIONS = 10;
/** Array for storing the weights for the votes. */
protected double[] m_Betas;
/** The number of successfully generated base classifiers. */
protected int m_NumIterationsPerformed;
/** Weight Threshold. The percentage of weight mass used in training */
protected int m_WeightThreshold = 100;
/** Use boosting with reweighting? */
protected boolean m_UseResampling;
/** The number of classes */
protected int m_NumClasses;
/** a ZeroR model in case no model can be built from the data */
protected Classifier m_ZeroR;
/** The (weighted) training data */
protected Instances m_TrainingData;
/** Random number generator to be used for resampling */
protected Random m_RandomInstance;
/**
* Constructor.
*/
public AdaBoostM1() {
m_Classifier = new weka.classifiers.trees.DecisionStump();
}
/**
* Returns a string describing classifier
*
* @return a description suitable for displaying in the explorer/experimenter
* gui
*/
public String globalInfo() {
return "Class for boosting a nominal class classifier using the Adaboost "
+ "M1 method. Only nominal class problems can be tackled. Often "
+ "dramatically improves performance, but sometimes overfits.\n\n"
+ "For more information, see\n\n" + getTechnicalInformation().toString();
}
/**
* Returns an instance of a TechnicalInformation object, containing detailed
* information about the technical background of this class, e.g., paper
* reference or book this class is based on.
*
* @return the technical information about this class
*/
@Override
public TechnicalInformation getTechnicalInformation() {
TechnicalInformation result;
result = new TechnicalInformation(Type.INPROCEEDINGS);
result.setValue(Field.AUTHOR, "Yoav Freund and Robert E. Schapire");
result.setValue(Field.TITLE, "Experiments with a new boosting algorithm");
result.setValue(Field.BOOKTITLE,
"Thirteenth International Conference on Machine Learning");
result.setValue(Field.YEAR, "1996");
result.setValue(Field.PAGES, "148-156");
result.setValue(Field.PUBLISHER, "Morgan Kaufmann");
result.setValue(Field.ADDRESS, "San Francisco");
return result;
}
/**
* String describing default classifier.
*
* @return the default classifier classname
*/
@Override
protected String defaultClassifierString() {
return "weka.classifiers.trees.DecisionStump";
}
/**
* Select only instances with weights that contribute to the specified
* quantile of the weight distribution
*
* @param data the input instances
* @param quantile the specified quantile eg 0.9 to select 90% of the weight
* mass
* @return the selected instances
*/
protected Instances selectWeightQuantile(Instances data, double quantile) {
int numInstances = data.numInstances();
Instances trainData = new Instances(data, numInstances);
double[] weights = new double[numInstances];
double sumOfWeights = 0;
for (int i = 0; i < numInstances; i++) {
weights[i] = data.instance(i).weight();
sumOfWeights += weights[i];
}
double weightMassToSelect = sumOfWeights * quantile;
int[] sortedIndices = Utils.sort(weights);
// Select the instances
sumOfWeights = 0;
for (int i = numInstances - 1; i >= 0; i--) {
Instance instance = (Instance) data.instance(sortedIndices[i]).copy();
trainData.add(instance);
sumOfWeights += weights[sortedIndices[i]];
if ((sumOfWeights > weightMassToSelect) && (i > 0)
&& (weights[sortedIndices[i]] != weights[sortedIndices[i - 1]])) {
break;
}
}
if (m_Debug) {
System.err.println("Selected " + trainData.numInstances() + " out of "
+ numInstances);
}
return trainData;
}
/**
* Returns an enumeration describing the available options.
*
* @return an enumeration of all the available options.
*/
@Override
public Enumeration