jsat.classifiers.trees
Class DecisionTree
- java.lang.Object
-
- jsat.classifiers.trees.DecisionTree
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, TreeLearner, Parameterized, Regressor
- Direct Known Subclasses:
- RandomDecisionTree
public class DecisionTree extends java.lang.Object implements Classifier, Regressor, Parameterized, TreeLearner
Creates a decision tree fromDecisionStumps. How this tree performs is controlled by pruning method selected, and the methods used in the stump.
A Decision Tree supports missing values in training and prediction.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DecisionTree()Creates a Decision Tree that usesTreePruner.PruningMethod.REDUCED_ERRORpruning on a held out 10% of the data.DecisionTree(int maxDepth)Creates a Decision Tree that does not do any pruning, and is built out only to the specified depthDecisionTree(int maxDepth, int minSamples, TreePruner.PruningMethod pruningMethod, double testProportion)Creates a new decision tree classifier
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.DecisionTreeclone()static DecisionTreegetC45Tree()Returns a Decision Tree with settings initialized so that its behavior is approximately that of the C4.5 decision tree algorithm when used on classification data.ImpurityScore.ImpurityMeasuregetGainMethod()intgetMaxDepth()The maximum depth that this classifier may build trees to.intgetMinResultSplitSize()Returns the minimum result split size that may be considered for use as the attribute to split on.intgetMinSamples()The minimum number of samples needed at each step in order to continue branchingjava.util.List<Parameter>getParameters()Returns the list of parameters that can be altered for this learner.TreePruner.PruningMethodgetPruningMethod()Returns the method of pruning used after tree constructiondoublegetTestProportion()Returns the proportion of the training set that is put aside to perform pruning withTreeNodeVisitorgetTreeNodeVisitor()Obtains a node visitor for the tree learner that can be used to traverse and predict from the learned treedoubleregress(DataPoint data)voidsetGainMethod(ImpurityScore.ImpurityMeasure gainMethod)voidsetMaxDepth(int maxDepth)Sets the maximum depth that this classifier may build trees to.voidsetMinResultSplitSize(int size)When a split is made, it may be that outliers cause the split to segregate a minority of points from the majority.voidsetMinSamples(int minSamples)Sets the minimum number of samples needed at each step in order to continue branchingvoidsetPruningMethod(TreePruner.PruningMethod pruningMethod)Sets the method of pruning that will be used after tree constructionvoidsetTestProportion(double testProportion)Sets the proportion of the training set that is put aside to perform pruning with.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)voidtrain(RegressionDataSet dataSet, java.util.Set<java.lang.Integer> options)voidtrain(RegressionDataSet dataSet, java.util.Set<java.lang.Integer> options, boolean parallel)voidtrainC(ClassificationDataSet dataSet, java.util.Set<java.lang.Integer> options)-
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
-
-
-
-
Constructor Detail
-
DecisionTree
public DecisionTree()
Creates a Decision Tree that usesTreePruner.PruningMethod.REDUCED_ERRORpruning on a held out 10% of the data.
-
DecisionTree
public DecisionTree(int maxDepth)
Creates a Decision Tree that does not do any pruning, and is built out only to the specified depth- Parameters:
maxDepth-
-
DecisionTree
public DecisionTree(int maxDepth, int minSamples, TreePruner.PruningMethod pruningMethod, double testProportion)Creates a new decision tree classifier- Parameters:
maxDepth- the maximum depth of the tree to createminSamples- the minimum number of samples needed to continue branchingpruningMethod- the method of pruning to use after constructiontestProportion- the proportion of the data set to put aside to use for pruning
-
-
Method Detail
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
train
public void train(RegressionDataSet dataSet, java.util.Set<java.lang.Integer> options)
-
train
public void train(RegressionDataSet dataSet, java.util.Set<java.lang.Integer> options, boolean parallel)
-
getC45Tree
public static DecisionTree getC45Tree()
Returns a Decision Tree with settings initialized so that its behavior is approximately that of the C4.5 decision tree algorithm when used on classification data. The exact behavior not identical, and certain base cases may not behave in the exact same manner. However, it uses all of the same general algorithms.
The returned tree does not perform or support- discrete attribute grouping
- windowing
- subsidiary cutpoints (soft boundaries)
- Returns:
- a decision tree that will behave in a manner similar to C4.5
-
setGainMethod
public void setGainMethod(ImpurityScore.ImpurityMeasure gainMethod)
-
getGainMethod
public ImpurityScore.ImpurityMeasure getGainMethod()
-
setMinResultSplitSize
public void setMinResultSplitSize(int size)
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:
size- 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
-
setMaxDepth
public void setMaxDepth(int maxDepth)
Sets the maximum depth that this classifier may build trees to.- Parameters:
maxDepth- the maximum depth of the trained tree
-
getMaxDepth
public int getMaxDepth()
The maximum depth that this classifier may build trees to.- Returns:
- the maximum depth that this classifier may build trees to.
-
setMinSamples
public void setMinSamples(int minSamples)
Sets the minimum number of samples needed at each step in order to continue branching- Parameters:
minSamples- the minimum number of samples needed to branch
-
getMinSamples
public int getMinSamples()
The minimum number of samples needed at each step in order to continue branching- Returns:
- the minimum number of samples needed at each step in order to continue branching
-
setPruningMethod
public void setPruningMethod(TreePruner.PruningMethod pruningMethod)
Sets the method of pruning that will be used after tree construction- Parameters:
pruningMethod- the method of pruning that will be used after tree construction- See Also:
TreePruner.PruningMethod
-
getPruningMethod
public TreePruner.PruningMethod getPruningMethod()
Returns the method of pruning used after tree construction- Returns:
- the method of pruning used after tree construction
-
getTestProportion
public double getTestProportion()
Returns the proportion of the training set that is put aside to perform pruning with- Returns:
- the proportion of the training set that is put aside to perform pruning with
-
setTestProportion
public void setTestProportion(double testProportion)
Sets the proportion of the training set that is put aside to perform pruning with.
NOTE: The values 0 and 1 are special cases.
0 indicates that no pruning will occur regardless of the set pruning method
1 indicates that the training set will be used as the testing set. This is valid for some pruning methods.- Parameters:
testProportion- the proportion, must be in the range [0, 1]
-
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.
-
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 void trainC(ClassificationDataSet dataSet, java.util.Set<java.lang.Integer> options)
-
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 DecisionTree clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
getTreeNodeVisitor
public TreeNodeVisitor getTreeNodeVisitor()
Description copied from interface:TreeLearnerObtains a node visitor for the tree learner that can be used to traverse and predict from the learned tree- Specified by:
getTreeNodeVisitorin interfaceTreeLearner- Returns:
- the root node visitor for the learned tree
-
getParameters
public java.util.List<Parameter> getParameters()
Description copied from interface:ParameterizedReturns the list of parameters that can be altered for this learner.- Specified by:
getParametersin interfaceParameterized- Returns:
- the list of parameters that can be altered for this learner.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG