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 is the stable version. Apart from bugfixes, this version
does not receive any other updates.
/*
* 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 .
*/
/*
* InputMappedClassifier.java
* Copyright (C) 2010-2012 University of Waikato, Hamilton, New Zealand
*
*/
package weka.classifiers.misc;
import java.io.Serializable;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
import weka.classifiers.Classifier;
import weka.classifiers.SingleClassifierEnhancer;
import weka.core.AdditionalMeasureProducer;
import weka.core.Attribute;
import weka.core.Capabilities;
import weka.core.Capabilities.Capability;
import weka.core.DenseInstance;
import weka.core.Drawable;
import weka.core.Environment;
import weka.core.EnvironmentHandler;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.OptionHandler;
import weka.core.RevisionUtils;
import weka.core.SerializationHelper;
import weka.core.Utils;
import weka.core.WeightedInstancesHandler;
/**
* Wrapper classifier that addresses incompatible
* training and test data by building a mapping between the training data that a
* classifier has been built with and the incoming test instances' structure.
* Model attributes that are not found in the incoming instances receive missing
* values, so do incoming nominal attribute values that the classifier has not
* seen before. A new classifier can be trained or an existing one loaded from a
* file.
*
*
*
* Valid options are:
*
*
*
* -I
* Ignore case when matching attribute names and nominal values.
*
*
*
* -M
* Suppress the output of the mapping report.
*
*
*
* -trim
* Trim white space from either end of names before matching.
*
*
*
* -L <path to model to load>
* Path to a model to load. If set, this model
* will be used for prediction and any base classifier
* specification will be ignored. Environment variables
* may be used in the path (e.g. ${HOME}/myModel.model)
*
*
*
* -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.rules.ZeroR)
*
*
*
* Options specific to classifier weka.classifiers.rules.ZeroR:
*
*
*
* -D
* If set, classifier is run in debug mode and
* may output additional info to the console
*
*
*
*
* @author Mark Hall (mhall{[at]}pentaho{[dot]}com)
* @version $Revision: 10153 $
*
*/
public class InputMappedClassifier extends SingleClassifierEnhancer implements
Serializable, OptionHandler, Drawable, WeightedInstancesHandler,
AdditionalMeasureProducer, EnvironmentHandler {
/** For serialization */
private static final long serialVersionUID = 4901630631723287761L;
/** The path to the serialized model to use (if any) */
protected String m_modelPath = "";
/** The header of the last known set of incoming test instances */
protected transient Instances m_inputHeader;
/** The instances structure used to train the classifier with */
protected Instances m_modelHeader;
/** Handle any environment variables used in the model path */
protected transient Environment m_env;
/** Map from model attributes to incoming attributes */
protected transient int[] m_attributeMap;
protected transient int[] m_attributeStatus;
/**
* For each model attribute, map from incoming nominal values to model nominal
* values
*/
protected transient int[][] m_nominalValueMap;
/** Trim white space from both ends of attribute names and nominal values? */
protected boolean m_trim = true;
/** Ignore case when matching attribute names and nominal values? */
protected boolean m_ignoreCase = true;
/** Dont output mapping report if set to true */
protected boolean m_suppressMappingReport = false;
/**
* If true, then a call to buildClassifier() will not overwrite any test
* structure that has been recorded with the current training structure. This
* is useful for getting a correct mapping report output in toString() after
* buildClassifier has been called and before any test instance has been seen.
* Test structure and mapping will get reset if a test instance is received
* whose structure does not match the recorded test structure.
*/
protected boolean m_initialTestStructureKnown = false;
/** Holds values for instances constructed for prediction */
protected double[] m_vals;
/**
* Returns a string describing this classifier
*
* @return a description of the classifier suitable for displaying in the
* explorer/experimenter gui
*/
public String globalInfo() {
return "Wrapper classifier that addresses incompatible training and test "
+ "data by building a mapping between the training data that "
+ "a classifier has been built with and the incoming test instances' "
+ "structure. Model attributes that are not found in the incoming "
+ "instances receive missing values, so do incoming nominal attribute "
+ "values that the classifier has not seen before. A new classifier "
+ "can be trained or an existing one loaded from a file.";
}
/**
* Set the environment variables to use
*
* @param env the environment variables to use
*/
@Override
public void setEnvironment(Environment env) {
m_env = env;
}
/**
* Returns the tip text for this property
*
* @return tip text for this property suitable for displaying in the
* explorer/experimenter gui
*/
public String ignoreCaseForNamesTipText() {
return "Ignore case when matching attribute names and nomina values.";
}
/**
* Set whether to ignore case when matching attribute names and nominal
* values.
*
* @param ignore true if case is to be ignored
*/
public void setIgnoreCaseForNames(boolean ignore) {
m_ignoreCase = ignore;
}
/**
* Get whether to ignore case when matching attribute names and nominal
* values.
*
* @return true if case is to be ignored.
*/
public boolean getIgnoreCaseForNames() {
return m_ignoreCase;
}
/**
* Returns the tip text for this property
*
* @return tip text for this property suitable for displaying in the
* explorer/experimenter gui
*/
public String trimTipText() {
return "Trim white space from each end of attribute names and "
+ "nominal values before matching.";
}
/**
* Set whether to trim white space from each end of names before matching.
*
* @param trim true to trim white space.
*/
public void setTrim(boolean trim) {
m_trim = trim;
}
/**
* Get whether to trim white space from each end of names before matching.
*
* @return true if white space is to be trimmed.
*/
public boolean getTrim() {
return m_trim;
}
/**
* Returns the tip text for this property
*
* @return tip text for this property suitable for displaying in the
* explorer/experimenter gui
*/
public String suppressMappingReportTipText() {
return "Don't output a report of model-to-input mappings.";
}
/**
* Set whether to suppress output the report of model to input mappings.
*
* @param suppress true to suppress this output.
*/
public void setSuppressMappingReport(boolean suppress) {
m_suppressMappingReport = suppress;
}
/**
* Get whether to suppress output the report of model to input mappings.
*
* @return true if this output is to be suppressed.
*/
public boolean getSuppressMappingReport() {
return m_suppressMappingReport;
}
/**
* Returns the tip text for this property
*
* @return tip text for this property suitable for displaying in the
* explorer/experimenter gui
*/
public String modelPathTipText() {
return "Set the path from which to load a model. "
+ "Loading occurs when the first test instance "
+ "is received. Environment variables can be used in the "
+ "supplied path.";
}
/**
* Set the path from which to load a model. Loading occurs when the first test
* instance is received or getModelHeader() is called programatically.
* Environment variables can be used in the supplied path - e.g.
* ${HOME}/myModel.model.
*
* @param modelPath the path to the model to load.
* @throws Exception if a problem occurs during loading.
*/
public void setModelPath(String modelPath) throws Exception {
if (m_env == null) {
m_env = Environment.getSystemWide();
}
m_modelPath = modelPath;
// loadModel(modelPath);
}
/**
* Get the path used for loading a model.
*
* @return the path used for loading a model.
*/
public String getModelPath() {
return m_modelPath;
}
/**
* Returns default capabilities of the classifier.
*
* @return the capabilities of this classifier
*/
@Override
public Capabilities getCapabilities() {
Capabilities result = super.getCapabilities();
result.disable(Capability.RELATIONAL_ATTRIBUTES);
return result;
}
/**
* Returns an enumeration describing the available options.
*
* Valid options are:
*
*
*
* -I
* Ignore case when matching attribute names and nominal values.
*
*
*
* -M
* Suppress the output of the mapping report.
*
*
*
* -trim
* Trim white space from either end of names before matching.
*
*
*
* -L <path to model to load>
* Path to a model to load. If set, this model
* will be used for prediction and any base classifier
* specification will be ignored. Environment variables
* may be used in the path (e.g. ${HOME}/myModel.model)
*
*
*
* -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.rules.ZeroR)
*
*
*
* Options specific to classifier weka.classifiers.rules.ZeroR:
*
*
*
* -D
* If set, classifier is run in debug mode and
* may output additional info to the console
*
*
*
*
* @return an enumeration of all the available options.
*/
@Override
public Enumeration