Predictor Class#
The predictor class is used for customizing how tree.predict functions. The defaults can be seen below.
Predictor #
The base Predictor class from which all other predict classes need to inhert.
forest_predict
staticmethod
#
Internal function used by the RandomForest class 'predict' method to evaluate predictions for each tree and aggregate them.
Needs to be adjusted whenever RandomForest predictions do not simply aggregate the tree predictions by averaging.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_old
|
ndarray
|
Array of feature values used during training. |
required |
Y_old
|
ndarray
|
Array of response values used during training. |
required |
X_new
|
ndarray
|
Array of new feature values at which to predict. |
required |
trees
|
list[DecisionTree]
|
List of fitted DecisionTrees fitted within the random forest. |
required |
parallel
|
ParallelModel
|
ParallelModel used for multiprocessing. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
An array with predictions for each row of X_new. |
predict #
Prediction function called by the DecisionTree when it is told to predict. Can be customised for a different output of the DecisionTree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
A 2-dimensional array for which the rows are the samples at which to predict. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
An array with predictions for each row of X. |
predict_leaf #
Computes hash table indexing in which LeafNodes the rows of X fall into.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
2-dimensional array for which the rows are the samples at which to predict. |
required |
Returns:
Type | Description |
---|---|
dict
|
A hash table with keys corresponding to LeafNode ids and values lists of indices specifying which rows land in a given LeafNode. |
PredictorClassification #
The default prediction class for the 'Classification' tree type.
predict #
For each row in X, the method first predicts the LeafNode into which the row falls and then computes the class with the highest number of occurances in that LeafNode.
If the keyword argument 'predict_proba' is set to True. This method outputs class probabilities (i.e., the frequence of each label in the same LeafNode).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
A 2-dimensional array for which the rows are the samples at which to predict. |
required |
**kwargs
|
predict_proba : bool Specifies whether to compute class probabilities or not. Defaults to False if not provided. |
{}
|
PredictorRegression #
The default prediction class for the 'Regression' tree type.
predict #
For each row in X, the method first predicts the LeafNode into which the row falls and then computes average response value in that LeafNode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
A 2-dimensional array for which the rows are the samples at which to predict. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
An array with predictions for each row of X. |
PredictorLocalPolynomial #
The default prediction class for the 'Gradient' tree type.
predict #
For each row in X, the method first predicts the LeafNode into which the row falls and then computes uses the parameters theta0, theta1 and theta2 saved on the LeafNode to estimate the predicted value $$ \texttt{theta0} + \texttt{theta1} \texttt{X}[i, 0] + \texttt{theta2} \texttt{X}[i, 0]^2. $$
Note: This predict class requires that the decision tree/random forest uses a LocalPolynomialLeafNode and either LeafBuilderPartialLinear or LeafBuilderPartialQuadratic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
A 2-dimensional array for which the rows are the samples at which to predict. |
required |
**kwargs
|
orders : list[int] | int A list of integers or a single integer specifying which orders should be predicted. Orders 0, 1 and 2 correspond to the 0th, 1st and 2nd order derivative. Default is orders=[0, 1, 2] if not provided. |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
A 2-dim array with the predicted values for each row of X and columns corresponding to the orders. |
PredictorQuantile #
The default prediction class for the 'Quantile' tree type.
predict #
For each row in X, the method first predicts the LeafNode into which the row falls and then computes the quantiles in that leaf node.
For random forests the quantiles across all trees are computed jointly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
A 2-dimensional array for which the rows are the samples at which to predict. |
required |
**kwargs
|
quantile : list[float] | float A list of quantiles or a single quantile which should be predicted. |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
A 1- or 2-dim array with the predicted quantiles for each row of X and columns corresponding to different quantiles (if quantiles was a list). |