jsat.classifiers.trees
Class DecisionStump
- java.lang.Object
-
- jsat.classifiers.trees.DecisionStump
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized, Regressor
public class DecisionStump extends java.lang.Object implements Classifier, Regressor, Parameterized
This class is a 1-rule. It creates one rule that is used to classify all inputs, making it a decision tree with only one node. It can be used as a weak learner for ensemble learners, or as the nodes in a true decision tree.
Categorical values are handled similarly under all circumstances.
During classification, numeric attributes are separated based on most likely probability into their classes.
During regression, numeric attributes are done with only binary splits, finding the split that minimizes the total squared error sum.
The Decision Stump supports missing values in training and prediction.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DecisionStump()Creates a new decision stump
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.DecisionStumpclone()ImpurityScore.ImpurityMeasuregetGainMethod()intgetMinResultSplitSize()Returns the minimum result split size that may be considered for use as the attribute to split on.intgetNumberOfPaths()Returns the number of paths that this decision stump leads to.intgetSplittingAttribute()Returns the attribute that this stump has decided to use to compute results.doubleregress(DataPoint data)CategoricalResultsresult(int i)Returns the categorical result of the i'th path.voidsetGainMethod(ImpurityScore.ImpurityMeasure gainMethod)voidsetMinResultSplitSize(int minResultSplitSize)When a split is made, it may be that outliers cause the split to segregate a minority of points from the majority.voidsetPredicting(CategoricalData predicting)Sets the DecisionStump's predicting information.voidsetRemoveContinuousAttributes(boolean removeContinuousAttributes)Unlike categorical values, when a continuous attribute is selected to split on, not all values of the attribute become the same.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet, boolean parallel)java.util.List<java.util.List<DataPointPair<java.lang.Integer>>>trainC(java.util.List<DataPointPair<java.lang.Integer>> dataPoints, java.util.Set<java.lang.Integer> options)This is a helper function that does the work of training this stump.java.util.List<java.util.List<DataPointPair<java.lang.Integer>>>trainC(java.util.List<DataPointPair<java.lang.Integer>> dataPoints, java.util.Set<java.lang.Integer> options, boolean parallel)java.util.List<java.util.List<DataPointPair<java.lang.Double>>>trainR(java.util.List<DataPointPair<java.lang.Double>> dataPoints, java.util.Set<java.lang.Integer> options)java.util.List<java.util.List<DataPointPair<java.lang.Double>>>trainR(java.util.List<DataPointPair<java.lang.Double>> dataPoints, java.util.Set<java.lang.Integer> options, boolean parallel)intwhichPath(DataPoint data)Determines which split path this data point would follow from this decision stump.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Method Detail
-
setRemoveContinuousAttributes
public void setRemoveContinuousAttributes(boolean removeContinuousAttributes)
Unlike categorical values, when a continuous attribute is selected to split on, not all values of the attribute become the same. It can be useful to split on the same attribute multiple times. If set true, continuous attributes will be removed from the options list. Else, they will be left in the options list.- Parameters:
removeContinuousAttributes- whether or not to remove continuous attributes on a call totrainC(java.util.List, java.util.Set)
-
setGainMethod
public void setGainMethod(ImpurityScore.ImpurityMeasure gainMethod)
-
getGainMethod
public ImpurityScore.ImpurityMeasure getGainMethod()
-
setMinResultSplitSize
public void setMinResultSplitSize(int minResultSplitSize)
When a split is made, it may be that outliers cause the split to segregate a minority of points from the majority. The min result split size parameter specifies the minimum allowable number of points to end up in one of the splits for it to be admisible for consideration.- Parameters:
minResultSplitSize- the minimum result split size to use
-
getMinResultSplitSize
public int getMinResultSplitSize()
Returns the minimum result split size that may be considered for use as the attribute to split on.- Returns:
- the minimum result split size in use
-
getSplittingAttribute
public int getSplittingAttribute()
Returns the attribute that this stump has decided to use to compute results. Numeric features start from 0, and categorical features start from the number of numeric features.- Returns:
- the attribute that this stump has decided to use to compute results.
-
setPredicting
public void setPredicting(CategoricalData predicting)
Sets the DecisionStump's predicting information. This will be set automatically by callingClassifier.train(jsat.classifiers.ClassificationDataSet)or#train(jsat.classifiers.ClassificationDataSet, java.util.concurrent.ExecutorService), but it must be called before usingtrainC(java.util.List, java.util.Set).- Parameters:
predicting- the information about the attribute that will be predicted by this classifier
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
whichPath
public int whichPath(DataPoint data)
Determines which split path this data point would follow from this decision stump. Works for both classification and regression.- Parameters:
data- the data point in question- Returns:
- the integer indicating which path to take. -1 returned if stump is not trained
-
getNumberOfPaths
public int getNumberOfPaths()
Returns the number of paths that this decision stump leads to. The stump may not ever direct a data point on some of the paths. A result of 1 path means that all data points will be given the same decision, and is generated when the entropy of a set is 0.0.
-1 is returned for an untrained stump- Returns:
- the number of paths this decision stump has stored
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
result
public CategoricalResults result(int i)
Returns the categorical result of the i'th path.- Parameters:
i- the path to get the result for- Returns:
- the result that would be returned if a data point went down the given path
- Throws:
java.lang.IndexOutOfBoundsException- if an invalid path is givenjava.lang.NullPointerException- if the stump has not been trained for classification
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
trainC
public java.util.List<java.util.List<DataPointPair<java.lang.Integer>>> trainC(java.util.List<DataPointPair<java.lang.Integer>> dataPoints, java.util.Set<java.lang.Integer> options)
This is a helper function that does the work of training this stump. It may be called directly by other classes that are creating decision trees to avoid redundant repackaging of lists.- Parameters:
dataPoints- the lists of datapoint to train on, paired with the true category of each training pointoptions- the set of attributes that this classifier may choose from. The attribute it does choose will be removed from the set.- Returns:
- the a list of lists, containing all the datapoints that would have followed each path. Useful for training a decision tree
-
trainC
public java.util.List<java.util.List<DataPointPair<java.lang.Integer>>> trainC(java.util.List<DataPointPair<java.lang.Integer>> dataPoints, java.util.Set<java.lang.Integer> options, boolean parallel)
-
trainR
public java.util.List<java.util.List<DataPointPair<java.lang.Double>>> trainR(java.util.List<DataPointPair<java.lang.Double>> dataPoints, java.util.Set<java.lang.Integer> options)
-
trainR
public java.util.List<java.util.List<DataPointPair<java.lang.Double>>> trainR(java.util.List<DataPointPair<java.lang.Double>> dataPoints, java.util.Set<java.lang.Integer> options, boolean parallel)
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
clone
public DecisionStump clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG