|
ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
|
A projection pursuit decision tree for classification. More...
#include <ClassificationTree.hpp>
Public Types | |
| using | FeatureMatrix = types::FeatureMatrix |
| using | FeatureVector = types::FeatureVector |
| using | GroupIndices = std::map<types::GroupId, int> |
| using | GroupPartition = stats::GroupPartition |
| using | Groups = std::set<types::GroupId> |
| using | Outcome = types::Outcome |
| using | OutcomeVector = types::OutcomeVector |
| using | Ptr = std::unique_ptr<ClassificationTree> |
| using | RNG = stats::RNG |
Public Types inherited from ppforest2::Tree | |
| using | FeatureMatrix = types::FeatureMatrix |
| using | FeatureVector = types::FeatureVector |
| using | GroupPartition = stats::GroupPartition |
| using | Outcome = types::Outcome |
| using | OutcomeVector = types::OutcomeVector |
| using | Ptr = std::unique_ptr<Tree> |
| using | RNG = stats::RNG |
| using | Root = TreeNode::Ptr |
Public Types inherited from ppforest2::Model | |
| using | Ptr = std::shared_ptr<Model> |
Public Member Functions | |
| ClassificationTree (TreeNode::Ptr root, TrainingSpec::Ptr spec, Groups groups) | |
| void | accept (Model::Visitor &visitor) const override |
| Accept a model visitor (mode-specific dispatch). | |
| FeatureMatrix | predict (FeatureMatrix const &x, Proportions) const |
One-hot encoding of the predicted group per row, columns laid out by groups(). | |
| FeatureMatrix | predict (FeatureMatrix const &x, Proportions, GroupIndices const &indices) const |
| One-hot encoding per row, with an explicit column layout. | |
| FeatureVector | predict (FeatureVector const &x, Proportions, GroupIndices const &indices) const |
One-hot encoding for one observation, with an explicit column layout passed as a precomputed {group → column} map. | |
| types::Outcome | predict (types::FeatureVector const &x) const override |
| Predict a single observation. | |
| types::FeatureVector | predict (types::FeatureVector const &x, Proportions) const |
One-hot encoding of the predicted group for one observation, with columns laid out by groups(). | |
Public Member Functions inherited from ppforest2::Tree | |
| bool | operator!= (Tree const &other) const |
| bool | operator== (Tree const &other) const |
| virtual types::OutcomeVector | predict (types::FeatureMatrix const &x) const |
| Predict a matrix of observations. | |
| types::Outcome | predict (types::FeatureVector const &x) const override |
| Predict a single observation. | |
Public Member Functions inherited from ppforest2::Model | |
| virtual | ~Model ()=default |
Static Public Member Functions | |
| static Ptr | train (TrainingSpec const &s, FeatureMatrix &x, OutcomeVector &y, GroupPartition const &y_part, RNG &rng) |
| Train a classification tree with an external RNG. | |
Static Public Member Functions inherited from ppforest2::Tree | |
| static Ptr | train (TrainingSpec const &spec, types::FeatureMatrix &x, types::OutcomeVector &y) |
| Train a tree from a response vector. | |
| static Ptr | train (TrainingSpec const &spec, types::FeatureMatrix &x, types::OutcomeVector &y, stats::RNG &rng) |
| Train a tree from a response vector. | |
Static Public Member Functions inherited from ppforest2::Model | |
| static void | check_train_inputs (types::FeatureMatrix const &x, types::OutcomeVector const &y) |
| Validate common training inputs (y non-empty, matching x rows). | |
| static Ptr | train (TrainingSpec const &spec, types::FeatureMatrix &x, types::OutcomeVector &y) |
| Train a model from a training specification. | |
Public Attributes | |
| Groups | groups |
| Set of group labels this tree predicts over. | |
Public Attributes inherited from ppforest2::Tree | |
| Root | root |
| Root node of the tree. | |
Public Attributes inherited from ppforest2::Model | |
| bool | degenerate = false |
| Whether the model contains degenerate nodes/splits. | |
| TrainingSpec::Ptr | training_spec |
| Training specification used to build this model. | |
Additional Inherited Members | |
Protected Member Functions inherited from ppforest2::Tree | |
| Tree (TreeNode::Ptr root, TrainingSpec::Ptr spec) | |
Static Protected Member Functions inherited from ppforest2::Tree | |
| static Root | build_root (TrainingSpec const &spec, FeatureMatrix &x, OutcomeVector &y, GroupPartition const &y_part, RNG &rng) |
| Build the root node of a tree. | |
A projection pursuit decision tree for classification.
Leaves hold integer group labels produced by the configured leaf strategy (default MajorityVote). The predict(data, Proportions) overload returns a one-hot encoding of the predicted group.
| using ppforest2::ClassificationTree::GroupIndices = std::map<types::GroupId, int> |
| using ppforest2::ClassificationTree::Groups = std::set<types::GroupId> |
| using ppforest2::ClassificationTree::Ptr = std::unique_ptr<ClassificationTree> |
|
inline |
|
overridevirtual |
Accept a model visitor (mode-specific dispatch).
Implements ppforest2::Tree.
| FeatureMatrix ppforest2::ClassificationTree::predict | ( | FeatureMatrix const & | x, |
| Proportions | ) const |
One-hot encoding of the predicted group per row, columns laid out by groups().
| FeatureMatrix ppforest2::ClassificationTree::predict | ( | FeatureMatrix const & | x, |
| Proportions | , | ||
| GroupIndices const & | indices ) const |
One-hot encoding per row, with an explicit column layout.
Iterates rows calling the single-row predict(..., indices) overload. ClassificationForest::predict(..., Proportions) reuses this so every bagged tree's proportions land in the forest's column layout.
| FeatureVector ppforest2::ClassificationTree::predict | ( | FeatureVector const & | x, |
| Proportions | , | ||
| GroupIndices const & | indices ) const |
One-hot encoding for one observation, with an explicit column layout passed as a precomputed {group → column} map.
Base primitive. indices must contain every label this tree can predict (otherwise at() throws). The matrix overload, and ClassificationForest, both build the indices once at entry and call this overload per row so the map is never rebuilt in a loop.
|
overridevirtual |
Predict a single observation.
Walks the tree and returns the leaf value. Same implementation for both modes — the leaf value is produced by the mode-specific leaf strategy during training.
Implements ppforest2::Model.
| types::FeatureVector ppforest2::ClassificationTree::predict | ( | types::FeatureVector const & | x, |
| Proportions | ) const |
One-hot encoding of the predicted group for one observation, with columns laid out by groups().
|
static |
Train a classification tree with an external RNG.
x and y are non-const for signature symmetry with RegressionTree::train — classification doesn't mutate either.
| s | Training specification (must have mode = Classification). |
| x | Feature matrix (n × p). |
| y | Response vector (integer class labels encoded as floats). |
| y_part | Initial root group partition. |
| rng | Random number generator. |
| Groups ppforest2::ClassificationTree::groups |
Set of group labels this tree predicts over.
Canonical column layout for predict(FeatureMatrix, Proportions). Populated by train (from the parent's y_part.groups) and by the JSON deserializer (from meta.groups). Independent of root->node_groups() so that a stop/leaf combination producing a single-leaf root doesn't shrink the prediction matrix relative to what the model was trained for.