public final class M5
extends java.lang.Object
M5 algorithm main class.
Modifier and Type | Field and Description |
---|---|
static int |
MODEL_LINEAR_REGRESSION
Number to represent type of model used (Lineal regression).
|
static int |
MODEL_MODEL_TREE
Number to represent type of model used (tree model).
|
static int |
MODEL_REGRESSION_TREE
Number to represent type of model used (tree regression).
|
static Association[] |
TAGS_MODEL_TYPES
Tags for the model types.
|
Constructor and Description |
---|
M5() |
Modifier and Type | Method and Description |
---|---|
static double |
absDev(int attr,
M5Instances inst)
Returns the absolute deviation value of the instances values of an attribute
|
void |
buildClassifier(M5Instances inst)
Construct a model tree by training instances
|
double |
classifyInstance(M5Instance ins)
Classifies the given test instance.
|
static double |
correlation(double[] y1,
double[] y2,
int n)
Returns the correlation coefficient of two double vectors
|
static java.lang.StringBuffer |
deleteTrailingZerosAndDot(java.lang.StringBuffer stringBuffer)
Deletes the trailing zeros and decimal point in a stringBuffer
|
static java.lang.String |
doubleToStringF(double value,
int width,
int afterDecimalPoint)
Rounds a double and converts it into a formatted right-justified String.
|
static java.lang.String |
doubleToStringG(double value,
int width,
int precision)
Rounds a double and converts it into a formatted right-justified String.
|
java.util.Enumeration |
enumerateMeasures()
Returns an enumeration of the additional measure names
|
static boolean |
eqDouble(double a,
double b)
Tests if two double values are equal to each other
|
static void |
errorMsg(java.lang.String err)
Prints error message and exits
|
static long |
floorDouble(double value)
Returns the largest (closest to positive infinity) long integer value that is not greater than the argument.
|
static M5 |
forName(java.lang.String classifierName,
java.lang.String[] options)
Allows to construct the M5 classifier calling it by its name and options.
|
static java.lang.String |
getHeader(java.lang.String fileName)
Extracts the header of the file given.
|
static java.lang.String |
getHeaderNoData(java.lang.String fileName)
Extracts the header of the file given, when the data is not specified.
|
double |
getMeasure(java.lang.String additionalMeasureName)
Returns the value of the named measure
|
SelectedAssociation |
getModelType()
Get the value of Model.
|
java.lang.String[] |
getOptions()
Gets the current settings of the Classifier.
|
double |
getPruningFactor()
Get the value of PruningFactor.
|
boolean |
getUseUnsmoothed()
Get the value of UseUnsmoothed.
|
int |
getVerbosity()
Get the value of Verbosity.
|
static boolean |
hasEnumAttr(M5Instances inst)
Tests if enumerated attribute(s) exists in the instances
|
static boolean |
hasMissing(M5Instances inst)
Tests if missing value(s) exists in the instances
|
static java.lang.String |
headToString()
Prints the head lines of the output
|
java.util.Enumeration |
listOptions() |
static void |
main(java.lang.String[] argv)
Main method for M5' algorithm
|
double |
measureNumLeaves()
return the number of leaves in the tree
|
double |
measureNumLinearModels()
return the number of linear models
|
double |
measureNumRules()
return the number of rules
|
static long |
roundDouble(double value)
Rounds a double
|
static java.lang.String |
separatorToString()
Prints sepearating line
|
void |
setModelType(SelectedAssociation newMethod)
Set the value of Model.
|
protected static void |
setOptions(java.io.StreamTokenizer options)
Name: setOptions
Sets the option of the execution of the algorithm, reading them from an input file.
|
void |
setOptions(java.lang.String[] options)
Parses a given list of options.
|
void |
setPruningFactor(double v)
Set the value of PruningFactor.
|
void |
setUseUnsmoothed(boolean v)
Set the value of UseUnsmoothed.
|
void |
setVerbosity(int v)
Set the value of Verbosity.
|
static double |
smoothenValue(double p,
double q,
int n,
int k)
Returns the smoothed values according to the smoothing formula (np+kq)/(n+k)
|
static double |
sqrSum(int attr,
M5Instances inst)
Returns the squared sum of the instances values of an attribute
|
static double |
stdDev(int attr,
M5Instances inst)
Returns the standard deviation value of the instances values of an attribute
|
static double |
sum(int attr,
M5Instances inst)
Returns the sum of the instances values of an attribute
|
java.lang.String |
toString()
Converts the output of the training process into a string
|
static double |
variance(int attr,
M5Instances inst)
Returns the variance value of the instances values of an attribute
|
public static final int MODEL_LINEAR_REGRESSION
public static final int MODEL_REGRESSION_TREE
public static final int MODEL_MODEL_TREE
public static final Association[] TAGS_MODEL_TYPES
protected static void setOptions(java.io.StreamTokenizer options) throws java.lang.Exception
options
- the tokenizer used to tokenize the input file.java.lang.Exception
- if the configuration files can not be read correctly.public static java.lang.String getHeader(java.lang.String fileName)
fileName
- file's name give.public static java.lang.String getHeaderNoData(java.lang.String fileName)
fileName
- file's name give.public final void buildClassifier(M5Instances inst) throws java.lang.Exception
inst
- training instancesjava.lang.Exception
- if the classifier can't be builtpublic double classifyInstance(M5Instance ins) throws java.lang.Exception
ins
- the instance to be classifiedjava.lang.Exception
- if the instance can't be classifiedpublic java.util.Enumeration listOptions()
public void setOptions(java.lang.String[] options) throws java.lang.Exception
options
- the list of options as an array of stringsjava.lang.Exception
- if an option is not supportedpublic java.lang.String[] getOptions()
public final java.lang.String toString()
toString
in class java.lang.Object
public double measureNumLinearModels()
public double measureNumLeaves()
public double measureNumRules()
public java.util.Enumeration enumerateMeasures()
public double getMeasure(java.lang.String additionalMeasureName)
additionalMeasureName
- the name of the measure to query for its valuejava.lang.IllegalArgumentException
- if the named measure is not supportedpublic boolean getUseUnsmoothed()
public void setUseUnsmoothed(boolean v)
v
- Value to assign to UseUnsmoothed.public double getPruningFactor()
public void setPruningFactor(double v)
v
- Value to assign to PruningFactor.public SelectedAssociation getModelType()
public void setModelType(SelectedAssociation newMethod)
newMethod
- Value to assign to Model.public int getVerbosity()
public void setVerbosity(int v)
v
- Value to assign to Verbosity.public static M5 forName(java.lang.String classifierName, java.lang.String[] options) throws java.lang.Exception
classifierName
- name of the classifier.options
- Options used.java.lang.Exception
public static final boolean hasEnumAttr(M5Instances inst)
inst
- instancespublic static final boolean hasMissing(M5Instances inst)
inst
- instancespublic static final double sum(int attr, M5Instances inst)
attr
- an attributeinst
- instancespublic static final double sqrSum(int attr, M5Instances inst)
attr
- an attributeinst
- instancespublic static final double stdDev(int attr, M5Instances inst)
attr
- an attributeinst
- instancespublic static final double absDev(int attr, M5Instances inst)
attr
- an attributeinst
- instancespublic static final double variance(int attr, M5Instances inst)
attr
- an attributeinst
- instancespublic static final long roundDouble(double value)
value
- the double valuepublic static final long floorDouble(double value)
value
- the double valuepublic static final java.lang.String doubleToStringF(double value, int width, int afterDecimalPoint)
value
- the double valuewidth
- the width of the stringafterDecimalPoint
- the number of digits after the decimal pointpublic static final java.lang.String doubleToStringG(double value, int width, int precision)
value
- the double valuewidth
- the width of the stringprecision
- the number of valid digitspublic static final java.lang.StringBuffer deleteTrailingZerosAndDot(java.lang.StringBuffer stringBuffer)
stringBuffer
- string bufferpublic static final double smoothenValue(double p, double q, int n, int k)
p
- a double, normally is the prediction of the model at the current nodeq
- a double, normally is the prediction of the model at the up noden
- the number of instances at the up nodek
- the smoothing constance, default =15public static final double correlation(double[] y1, double[] y2, int n)
y1
- double vector 1y2
- double vector 2n
- the length of two double vectorspublic static final boolean eqDouble(double a, double b)
a
- double 1b
- double 2public static final void errorMsg(java.lang.String err)
err
- error messagepublic static final java.lang.String separatorToString()
public static final java.lang.String headToString()
public static void main(java.lang.String[] argv)
argv
- command line arguments