Class GradientBoosting
- All Implemented Interfaces:
Serializable,Cloneable
The idea behind boosting is to combine the outputs of relatively weak classifiers or predictive models to achieve iteratively better and better accuracy in either regression problems (the response variable is continuous) or classification problems (the response variable has two or more discrete values). This class implements the stochastic gradient tree boosting algorithm of Friedman, 1999. A sequence of decision trees is fit to random samples of the training data, iteratively re-weighted to minimize a specified loss function. In each iteration, pseudo-residuals are calculated based on a random sample from the original training set and the gradient of the loss function evaluated at values generated in the previous iteration. New base predictors are fit to the pseudo-residuals, and then a new prediction function is selected to minimize the loss-function, completing one iteration. The number of iterations is a parameter for the algorithm.
Gradient boosting is an ensemble method, but instead of using independent trees, gradient boosting forms a sequence of trees, iteratively and judiciously re-weighted to minimize prediction errors. In particular, the decision tree at iteration m+1 is estimated on pseudo-residuals generated using the decision tree at step m. Hence, successive trees are dependent on previous trees. The algorithm in gradient boosting iterates for a fixed number of times and stops, rather than iterating until a convergence criteria is met. The number of iterations is therefore a parameter in the model. Using a randomly selected subset of the training data in each iteration has been shown to substantially improve efficiency and robustness. Thus, the method is called stochastic gradient boosting. For further discussion, see Hastie, et. al. (2008).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe loss function type as specified by the error measure.Nested classes/interfaces inherited from class com.imsl.datamining.PredictiveModel
PredictiveModel.CloneNotSupportedException, PredictiveModel.PredictiveModelException, PredictiveModel.StateChangeException, PredictiveModel.SumOfProbabilitiesNotOneException, PredictiveModel.VariableType -
Constructor Summary
ConstructorsConstructorDescriptionGradientBoosting(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType) Constructs aGradientBoostingobject for a single response variable and multiple predictor variables.GradientBoosting(GradientBoosting gbModel) Constructs a copy of the inputGradientBoostingpredictive model.Constructs aGradientBoostingobject. -
Method Summary
Modifier and TypeMethodDescriptionclone()Clones aGradientBoostingpredictive model.voidfitModel()Performs the gradient boosting on the training data.double[][]Returns the fitted values \({f(x_i)}\) for a categorical response variable with two or more levels.double[][]Returns the predicted probabilities on the training data for a categorical response variable.double[]Returns the fitted values \({f(x_i)}\) for a continuous response variable after gradient boosting.ArrayList<double[]>Returns the gradient descent minimizing values calculated at each iteration for continuous response variables.ArrayList<double[][]>Returns the gradient descent minimizing values calculated at each iteration for categorical response variables.double[]Returns the values of the Huber parameter, \(\delta_m\), calculated at each iteration during training with the HUBER_M loss function.doubleReturns the initial value of the predictor function \(f_0\).int[]Returns the array of different values for the number of iterations.Returns the current loss function type.doubleReturns the loss function value.booleanReturns the flag indicating whether the test data is missing the response variable data.double[][]Returns the multinomial representation of the response variable.intReturns the current setting for the number of iterations to use in the gradient boosting algorithm.doubleReturns the current setting of the sample size proportion.doubleReturns the shrinkage parameter.doubleReturns the current shrinkage parameter.double[][]Returns the fitted values \({f(x_i)}\) for a categorical response variable with two or more levels on the test data.double[][]Returns the predicted probabilities on the test data for a categorical response variable.double[]Returns the fitted values \({f(x_i)}\) for a continuous response variable after gradient boosting on the test data.doubleReturns the loss function value on the test data.doubleReturns the tolerance level.Returns the list of boosted trees.double[]predict()Returns the predicted values on the training data.double[]predict(double[][] testData) Returns the predicted values on the input test data.double[]predict(double[][] testData, double[] testDataWeights) Runs the gradient boosting on the training data and returns the predicted values on the weighted test data.voidsetIterationsArray(int[] iterationsArray) Sets the array of different numbers of iterations.voidSets the loss function type for the gradient boosting algorithm.voidsetMissingTestYFlag(boolean missingTestY) Sets the flag indicating whether the test data is missing the response variable data.voidsetNumberOfIterations(int numberOfIterations) Sets the number of iterations.voidsetSampleSizeProportion(double sampleSizeProportion) Sets the sample size proportion.voidsetSaveTrees(boolean saveTrees) Sets the flag to save the boosted trees.voidsetShrinkageParameter(double shrinkageParameter) Sets the value of the shrinkage parameter.voidsetTrainingData(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType) Sets up the training data for the predictive model.Methods inherited from class com.imsl.datamining.PredictiveModel
getClassCounts, getClassErrors, getClassErrors, getClassLabels, getCostMatrix, getMaxNumberOfCategories, getMaxNumberOfIterations, getNumberOfClasses, getNumberOfColumns, getNumberOfMissing, getNumberOfPredictors, getNumberOfRows, getNumberOfUniquePredictorValues, getPredictorIndexes, getPredictorTypes, getPrintLevel, getPriorProbabilities, getRandomObject, getResponseColumnIndex, getResponseVariableAverage, getResponseVariableMostFrequentClass, getResponseVariableType, getTotalWeight, getVariableType, getWeights, getXY, isConstantSeries, isMustFitModel, isUserFixedNClasses, setClassCounts, setClassLabels, setClassProbabilities, setCostMatrix, setMaxNumberOfCategories, setMaxNumberOfIterations, setMustFitModel, setNumberOfClasses, setPredictorIndex, setPredictorTypes, setPrintLevel, setPriorProbabilities, setRandomObject, setResponseColumnIndex, setVariableType, setWeights
-
Constructor Details
-
GradientBoosting
public GradientBoosting(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType) Constructs aGradientBoostingobject for a single response variable and multiple predictor variables.- Parameters:
xy- adoublematrix containing the training dataresponseColumnIndex- anint, the column index for the response variablevarType- aPredictiveModel.VariableTypearray containing the type of each variable
-
GradientBoosting
Constructs aGradientBoostingobject.- Parameters:
pm- thePredictiveModelto serve as the base learnerNote: Currently only regression trees are supported as base learners.
-
GradientBoosting
Constructs a copy of the inputGradientBoostingpredictive model.- Parameters:
gbModel- aGradientBoostingpredictive model
-
-
Method Details
-
clone
Clones aGradientBoostingpredictive model.- Specified by:
clonein classPredictiveModel- Returns:
- a clone of the
GradientBoostingpredictive model
-
fitModel
Performs the gradient boosting on the training data.- Overrides:
fitModelin classPredictiveModel- Throws:
PredictiveModel.PredictiveModelException- is thrown when an exception occurs in the com.imsl.datamining.PredictiveModel. Superclass exceptions should be considered such as com.imsl.datamining.PredictiveModel.StateChangeException and com.imsl.datamining.PredictiveModel.SumOfProbabilitiesNotOneException.
-
predict
Returns the predicted values on the training data.- Specified by:
predictin classPredictiveModel- Returns:
- a
doublearray containing the predicted values on the training data, i.e., the fitted values - Throws:
PredictiveModel.PredictiveModelException- is thrown when an exception occurs in the com.imsl.datamining.PredictiveModel. Superclass exceptions should be considered such as com.imsl.datamining.PredictiveModel.StateChangeException and com.imsl.datamining.PredictiveModel.SumOfProbabilitiesNotOneException.
-
predict
Returns the predicted values on the input test data.- Specified by:
predictin classPredictiveModel- Parameters:
testData- adoublematrix containing test dataNote:
testDatamust have the same number of columns and the columns must be in the same arrangement asxy.- Returns:
- a
doublearray containing the predicted values - Throws:
PredictiveModel.PredictiveModelException- is thrown when an exception occurs in the com.imsl.datamining.PredictiveModel. Superclass exceptions should be considered such as com.imsl.datamining.PredictiveModel.StateChangeException and com.imsl.datamining.PredictiveModel.SumOfProbabilitiesNotOneException.
-
predict
public double[] predict(double[][] testData, double[] testDataWeights) throws PredictiveModel.PredictiveModelException Runs the gradient boosting on the training data and returns the predicted values on the weighted test data.- Specified by:
predictin classPredictiveModel- Parameters:
testData- adoublematrix containing test dataNote:
testDatamust have the same number of columns and the columns must be in the same arrangement asxy.testDataWeights- adoublearray containing weights for each row oftestData- Returns:
- a
doublearray containing the predicted values - Throws:
PredictiveModel.PredictiveModelException- is thrown when an exception occurs in the com.imsl.datamining.PredictiveModel. Superclass exceptions should be considered such as com.imsl.datamining.PredictiveModel.StateChangeException and com.imsl.datamining.PredictiveModel.SumOfProbabilitiesNotOneException.
-
getMissingTestYFlag
public boolean getMissingTestYFlag()Returns the flag indicating whether the test data is missing the response variable data.- Returns:
- a
boolean, the flag indicating whether the test data is missing the response variable values
-
setMissingTestYFlag
public void setMissingTestYFlag(boolean missingTestY) Sets the flag indicating whether the test data is missing the response variable data.- Parameters:
missingTestY- aboolean. Whentrue, the response variable in the test data is treated as missing. In that case, the test loss value isDouble.NaN. If the response variable is all missing in the test data, settingmissingTestY==falsehas no effect.Default:
missingTestY=false
-
getFittedValues
public double[] getFittedValues()Returns the fitted values \({f(x_i)}\) for a continuous response variable after gradient boosting.- Returns:
- a
doublearray containing the fitted values on the training data
-
getTestFittedValues
public double[] getTestFittedValues()Returns the fitted values \({f(x_i)}\) for a continuous response variable after gradient boosting on the test data.- Returns:
- a
doublearray containing the fitted values on the test data
-
getClassFittedValues
public double[][] getClassFittedValues()Returns the fitted values \({f(x_i)}\) for a categorical response variable with two or more levels.The underlying loss function is the binomial or multinomial deviance.
- Returns:
- a
doublematrix containing the fitted values on the training data
-
getGammaList
Returns the gradient descent minimizing values calculated at each iteration for continuous response variables.When
saveTrees=true, anArrayListof these parameters will be available after runningpredict(). Also, seegetTreeList(). The classGradientBoostingModelObjectuses these parameters to predict new data sets.- Returns:
- an
ArrayListofdoublearrays containing the minimizer for each boosting iteration
-
getGammaListMNL
Returns the gradient descent minimizing values calculated at each iteration for categorical response variables.When
saveTrees=true, anArrayListof these parameters will be available after runningpredict(). Also, seegetTreeList(). The classGradientBoostingModelObjectuses these parameters to predict new data sets.- Returns:
- an
ArrayListofdoublematrices containing the minimizer for each boosting iteration
-
getTestClassFittedValues
public double[][] getTestClassFittedValues()Returns the fitted values \({f(x_i)}\) for a categorical response variable with two or more levels on the test data.The underlying loss function is the binomial or multinomial deviance.
- Returns:
- a
doublematrix containing the fitted values on the test data
-
getMultinomialResponse
public double[][] getMultinomialResponse()Returns the multinomial representation of the response variable.\(Y^*\) is a matrix with the element at i,k, where i=0,...,
nObservations-1 and k=0,...,nClasses-1 $$ y^*_{ik} = \left\{ \begin{array}{ll} 1 & {\rm if}\;y_i = k\; \\ 0 & {\rm otherwise }\;\; \end{array} \right.$$Note: This representation is not available if the response has only 2 classes (binomial).
- Returns:
- a
doublematrix containing the response in multinomial representation
-
getClassProbabilities
public double[][] getClassProbabilities()Returns the predicted probabilities on the training data for a categorical response variable.- Overrides:
getClassProbabilitiesin classPredictiveModel- Returns:
- a
doublematrix containing the class probabilities fit on the training data. The i,k-th element of the matrix is the estimated probability that the observation at row index i belongs to the k+1-st class, where k=0,...,nClasses-1.
-
getTestClassProbabilities
public double[][] getTestClassProbabilities()Returns the predicted probabilities on the test data for a categorical response variable.- Returns:
- a
doublematrix containing the class probabilities on the test data. The i,k element is the estimated probability that the i-th pattern belongs to the k-th target class, where k=0,...,nClasses-1.
-
getLossValue
public double getLossValue()Returns the loss function value.- Returns:
- a
double, the loss function value
-
getTestLossValue
public double getTestLossValue()Returns the loss function value on the test data.- Returns:
- a
double, the loss function value
-
getTolerance
public double getTolerance()Returns the tolerance level.The tolerance value is used throughout the boosting procedure to avoid underflow.
- Returns:
- a
double, the tolerance level
-
getTreeList
Returns the list of boosted trees.The array of boosted trees will be available if
saveTrees=true, and after runningpredict(). The classGradientBoostingModelObjectuses the trees to predict new data sets.- Returns:
- an
ArrayList, the list of boosted trees
-
getNumberOfIterations
public int getNumberOfIterations()Returns the current setting for the number of iterations to use in the gradient boosting algorithm.Different values for the number of iterations can be set and used in cross validation. See
setIterationsArray(int[]).- Returns:
- an
int, the current setting for the number of iterations
-
setNumberOfIterations
public void setNumberOfIterations(int numberOfIterations) Sets the number of iterations.- Parameters:
numberOfIterations- anint, the number of iterationsDefault:
numberOfIterations= 50. ThenumberOfIterationsmust be positive.Note: This method sets
iterationsArray[0]=numberOfIterations.
-
setIterationsArray
public void setIterationsArray(int[] iterationsArray) Sets the array of different numbers of iterations.The algorithm in gradient boosting iterates for a fixed number of times and stops, rather than iterating until a convergence criteria is met. The number of iterations is therefore a parameter in the model. After setting the
iterationsArrayto two or more values, cross-validation can be used to help determine the best choice among the values. By default,iterationsArraycontains the single value{50},the default number of iterations. Or it can be set usingsetNumberOfIterations.- Parameters:
iterationsArray- anintarray containing the different numbers of iterationsDefault:
iterationsArray= {50}.
-
getHuberDeltas
public double[] getHuberDeltas()Returns the values of the Huber parameter, \(\delta_m\), calculated at each iteration during training with the HUBER_M loss function.The array is initialized to \(\{0.0\}\) and then updated during training when
LossFunctionType=HUBER_M.- Returns:
- a
doublearray containing the values
-
getInitialValue
public double getInitialValue()Returns the initial value of the predictor function \(f_0\).Before training the gradient boosting model, \(f_0 = 0 \). At the start of training, \(f_0\) is calculated using the training data and the loss function.
- Returns:
- a
double, the initial value of the predictor function
-
getIterationsArray
public int[] getIterationsArray()Returns the array of different values for the number of iterations.Different values for the number of iterations can be set and used in cross validation. See
setIterationsArray(int[]).- Returns:
- an
intarray, containing the values for the number of iterations parameter
-
getShrinkage
public double getShrinkage()Returns the shrinkage parameter. -
getLossType
Returns the current loss function type.- Returns:
- a
LossFunctionType, the current setting of the loss function type
-
setLossFunctionType
Sets the loss function type for the gradient boosting algorithm.- Parameters:
lossType- aLossFunctionType, the desired loss function typeDefault:
lossType=LossFunctionType.LEAST_SQUARES
-
getSampleSizeProportion
public double getSampleSizeProportion()Returns the current setting of the sample size proportion.- Returns:
- a
double, the sample size proportion
-
setSampleSizeProportion
public void setSampleSizeProportion(double sampleSizeProportion) Sets the sample size proportion.- Parameters:
sampleSizeProportion- adoublein the interval \(\left[0,1\right]\) specifying the desired sampling proportionDefault:
sampleSizeProportion= 0.50. IfsampleSizeProportion= 1.0, no sampling is performed.
-
setShrinkageParameter
public void setShrinkageParameter(double shrinkageParameter) Sets the value of the shrinkage parameter.- Parameters:
shrinkageParameter- adoublein the interval \(\left[0,1\right]\) specifying the shrinkage parameterDefault:
shrinkageParameter=1.0 (no shrinkage)
-
getShrinkageParameter
public double getShrinkageParameter()Returns the current shrinkage parameter.- Returns:
- a
double, the value of shrinkage parameter
-
setTrainingData
public void setTrainingData(double[][] xy, int responseColumnIndex, PredictiveModel.VariableType[] varType) Sets up the training data for the predictive model.By calling this method, the problem is either initialized or reset to use the data in the arguments.
- Overrides:
setTrainingDatain classPredictiveModel- Parameters:
xy- adoublematrix containing the training data and associated response valuesresponseColumnIndex- anintspecifying the column index inxyof the response variablevarType- aPredictiveModel.VariableTypearray of length equal toxy[0].lengthcontaining the type of each variable
-
setSaveTrees
public void setSaveTrees(boolean saveTrees) Sets the flag to save the boosted trees. Whentrue, anArrayListof the boosted trees is available after runningpredict(). SeegetTreeList(). The default issaveTrees=true.- Parameters:
saveTrees- aboolean
-