ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::Model Struct Referenceabstract

Abstract base class for predictive models (trees and forests). More...

#include <Model.hpp>

Classes

struct  Visitor
 Visitor interface for model dispatch. More...
 

Public Types

using Ptr = std::shared_ptr<Model>
 

Public Member Functions

virtual ~Model ()=default
 
virtual void accept (Visitor &visitor) const =0
 Accept a model visitor (double dispatch).
 
virtual types::ResponseVector predict (types::FeatureMatrix const &data) const =0
 Predict a matrix of observations.
 
virtual types::FeatureMatrix predict (types::FeatureMatrix const &data, Proportions) const =0
 Predict proportions for a matrix of observations.
 
virtual types::Response predict (types::FeatureVector const &data) const =0
 Predict a single observation.
 

Static Public Member Functions

static Ptr train (TrainingSpec const &spec, types::FeatureMatrix const &x, types::ResponseVector const &y)
 Train a model from a training specification.
 

Public Attributes

bool degenerate = false
 Whether the model contains degenerate nodes/splits.
 
TrainingSpec::Ptr training_spec
 Training specification used to build this model.
 

Detailed Description

Abstract base class for predictive models (trees and forests).

Member Typedef Documentation

◆ Ptr

using ppforest2::Model::Ptr = std::shared_ptr<Model>

Constructor & Destructor Documentation

◆ ~Model()

virtual ppforest2::Model::~Model ( )
virtualdefault

Member Function Documentation

◆ accept()

virtual void ppforest2::Model::accept ( Visitor & visitor) const
pure virtual

Accept a model visitor (double dispatch).

Implemented in ppforest2::Forest, and ppforest2::Tree.

◆ predict() [1/3]

virtual types::ResponseVector ppforest2::Model::predict ( types::FeatureMatrix const & data) const
pure virtual

Predict a matrix of observations.

Parameters
dataFeature matrix (n × p).
Returns
Predicted group labels (n).

Implemented in ppforest2::Forest, and ppforest2::Tree.

◆ predict() [2/3]

virtual types::FeatureMatrix ppforest2::Model::predict ( types::FeatureMatrix const & data,
Proportions  ) const
pure virtual

Predict proportions for a matrix of observations.

Returns an (n × G) matrix. For forests, each row contains the fraction of trees that voted for each group. For single trees, each row is a one-hot encoding of the predicted group.

Parameters
dataFeature matrix (n × p).
Returns
Proportion matrix (n × G), rows sum to 1.0.

Implemented in ppforest2::Forest, and ppforest2::Tree.

◆ predict() [3/3]

virtual types::Response ppforest2::Model::predict ( types::FeatureVector const & data) const
pure virtual

Predict a single observation.

Parameters
dataFeature vector (p).
Returns
Predicted group label.

Implemented in ppforest2::Forest, and ppforest2::Tree.

◆ train()

static Ptr ppforest2::Model::train ( TrainingSpec const & spec,
types::FeatureMatrix const & x,
types::ResponseVector const & y )
static

Train a model from a training specification.

Dispatches to Tree::train or Forest::train based on spec.is_forest().

Parameters
specTraining specification.
xFeature matrix (n × p).
yResponse vector (n).
Returns
Trained model (Tree or Forest).

Member Data Documentation

◆ degenerate

bool ppforest2::Model::degenerate = false

Whether the model contains degenerate nodes/splits.

◆ training_spec

TrainingSpec::Ptr ppforest2::Model::training_spec

Training specification used to build this model.


The documentation for this struct was generated from the following file: