Prediction Class#
The prediction class is used for customizing how a tree.predict functions. The defaults can be seen below.
Predict #
The base Predict 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 |
tree |
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. |
PredictClassification #
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. |
{}
|
PredictRegression #
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. |