jsat.classifiers.boosting
Class Stacking
- java.lang.Object
-
- jsat.classifiers.boosting.Stacking
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Regressor
public class Stacking extends java.lang.Object implements Classifier, Regressor
This provides an implementation of the Stacking ensemble method. Stacking learns several base classifiers and a top level classifier learns to predict the target based on the outputs of all the ensambled models. Historically a linear model (such asLinearBatch) is used, which translates to learning a weighted vote of the classifier outputs. However any classifier may be used so long as it supports the desired target type.
Note, that Stacking tends to work best when the base classifiers produce reasonable probability estimates.
Stacking supportsweighted data instancesif the aggregating model does.
See: Wolpert, D. H. (1992). Stacked generalization. Neural Networks, 5, 241–259.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static intDEFAULT_FOLDS
-
Constructor Summary
Constructors Constructor and Description Stacking(Classifier aggregatingClassifier, Classifier... baseClassifiers)Creates a new Stacking classifier that uses 3 folds of cross validationStacking(Classifier aggregatingClassifier, java.util.List<Classifier> baseClassifiers)Creates a new Stacking classifier that uses 3 folds of cross validationStacking(int folds, Classifier aggregatingClassifier, Classifier... baseClassifiers)Creates a new Stacking classifierStacking(int folds, Classifier aggregatingClassifier, java.util.List<Classifier> baseClassifiers)Creates a new Stacking classifierStacking(int folds, Regressor aggregatingRegressor, java.util.List<Regressor> baseRegressors)Creates a new Stacking regressorStacking(int folds, Regressor aggregatingRegressor, Regressor... baseRegressors)Creates a new Stacking regressorStacking(Regressor aggregatingRegressor, java.util.List<Regressor> baseRegressors)Creates a new Stacking regressor that uses 3 folds of cross validationStacking(Regressor aggregatingRegressor, Regressor... baseRegressors)Creates a new Stacking regressor that uses 3 folds of cross validationStacking(Stacking toCopy)Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.Stackingclone()intgetFolds()doubleregress(DataPoint data)voidsetFolds(int folds)Sets the number of folds of cross validation to use when creating the new set of weights that will be feed into the aggregating model.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)-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
-
-
-
Field Detail
-
DEFAULT_FOLDS
public static final int DEFAULT_FOLDS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Stacking
public Stacking(int folds, Classifier aggregatingClassifier, java.util.List<Classifier> baseClassifiers)Creates a new Stacking classifier- Parameters:
folds- the number of cross validation folds for learning the base modelaggregatingClassifier- the classifier used to merge the results of all the input classifiersbaseClassifiers- the list of base classifiers to ensemble
-
Stacking
public Stacking(int folds, Classifier aggregatingClassifier, Classifier... baseClassifiers)Creates a new Stacking classifier- Parameters:
folds- the number of cross validation folds for learning the base modelaggregatingClassifier- the classifier used to merge the results of all the input classifiersbaseClassifiers- the array of base classifiers to ensemble
-
Stacking
public Stacking(Classifier aggregatingClassifier, java.util.List<Classifier> baseClassifiers)
Creates a new Stacking classifier that uses 3 folds of cross validation- Parameters:
aggregatingClassifier- the classifier used to merge the results of all the input classifiersbaseClassifiers- the list of base classifiers to ensemble
-
Stacking
public Stacking(Classifier aggregatingClassifier, Classifier... baseClassifiers)
Creates a new Stacking classifier that uses 3 folds of cross validation- Parameters:
aggregatingClassifier- the classifier used to merge the results of all the input classifiersbaseClassifiers- the array of base classifiers to ensemble
-
Stacking
public Stacking(int folds, Regressor aggregatingRegressor, java.util.List<Regressor> baseRegressors)Creates a new Stacking regressor- Parameters:
folds- the number of cross validation folds for learning the base modelaggregatingRegressor- the regressor used to merge the results of all the input classifiersbaseRegressors- the list of base regressors to ensemble
-
Stacking
public Stacking(int folds, Regressor aggregatingRegressor, Regressor... baseRegressors)Creates a new Stacking regressor- Parameters:
folds- the number of cross validation folds for learning the base modelaggregatingRegressor- the regressor used to merge the results of all the input classifiersbaseRegressors- the array of base regressors to ensemble
-
Stacking
public Stacking(Regressor aggregatingRegressor, java.util.List<Regressor> baseRegressors)
Creates a new Stacking regressor that uses 3 folds of cross validation- Parameters:
aggregatingRegressor- the regressor used to merge the results of all the input classifiersbaseRegressors- the list of base regressors to ensemble
-
Stacking
public Stacking(Regressor aggregatingRegressor, Regressor... baseRegressors)
Creates a new Stacking regressor that uses 3 folds of cross validation- Parameters:
aggregatingRegressor- the regressor used to merge the results of all the input classifiersbaseRegressors- the array of base regressors to ensemble
-
Stacking
public Stacking(Stacking toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setFolds
public void setFolds(int folds)
Sets the number of folds of cross validation to use when creating the new set of weights that will be feed into the aggregating model.
Note that the number of folds may be 1, and will run significantly faster since models do not need to be re-trained. However it will be more prone to overfitting.- Parameters:
folds- the number of cross validation folds to use
-
getFolds
public int getFolds()
- Returns:
- the number of CV folds used for training
-
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.
-
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
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
clone
public Stacking clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceRegressor- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG