DecisionTreeRegressionBase<T>

Base Classes · AiDotNet.Regression

Provides a base implementation for decision tree regression models that predict continuous values.

Implements: IModelShape, ITreeBasedRegression<T>

Known derived types: DecisionTreeRegression<T>

For Beginners

This is a template for creating decision tree models that predict numerical values.

A decision tree works like a flowchart of yes/no questions to make predictions:

  • Start at the top (root) of the tree
  • At each step, answer a question about your data
  • Follow the appropriate path based on your answer
  • Continue until you reach an endpoint that provides a prediction

This base class provides the common structure and behaviors that all decision tree models share, while allowing specific implementations to customize how the tree is built and used.

Think of it like a blueprint for building different types of decision trees, where specific implementations can fill in the details according to their requirements.

How It Works

This abstract class implements common functionality for decision tree regression models, providing a framework for building predictive models based on decision trees. It manages the tree structure, handles serialization and deserialization, and defines the interface that concrete implementations must support.

Properties

Property Summary
ILossFunction<T> DefaultLossFunction { get; }
T SoftTreeTemperature { get; set; } Gets or sets the temperature parameter for soft decision tree mode.
Vector<T> FeatureImportances { get; set; } Gets the importance scores for each feature used in the model.
bool SupportsParameterInitialization { get; }
bool UseSoftTree { get; set; } Gets or sets whether to use soft (differentiable) tree mode for JIT compilation.
int MaxDepth { get; } Gets the maximum depth of the decision tree.
int NumberOfTrees { get; } Gets the number of trees in this model, which is always 1 for a single decision tree.
long ParameterCount { get; }
string[] FeatureNames { get; set; } Gets or sets the feature names.

Methods

Method Summary
Dictionary<string, T> GetFeatureImportance() Gets the feature importance scores as a dictionary.
DynamicShapeInfo GetDynamicShapeInfo()
IEnumerable<int> GetActiveFeatureIndices() Gets the indices of all features that are used in the decision tree.
IFullModel<T, Matrix<T>, Vector<T>> Clone() Creates a clone of the decision tree model.
IFullModel<T, Matrix<T>, Vector<T>> DeepCopy() Creates a deep copy of the decision tree model.
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters)
ModelMetadata<T> GetModelMetadata() Gets metadata about the decision tree model and its configuration.
ModelOptions GetOptions()
Vector<T> ComputeGradients(Matrix<T> input, Vector<T> target, ILossFunction<T> lossFunction)
Vector<T> GetParameters() Gets the model parameters as a vector representation.
Vector<T> Predict(Matrix<T> input) Predicts target values for the provided input features using the trained decision tree model.
Vector<T> SanitizeParameters(Vector<T> parameters)
bool IsFeatureUsed(int featureIndex) Determines whether a specific feature is used in the decision tree.
byte[] Serialize() Serializes the decision tree model to a byte array for storage or transmission.
int[] GetInputShape()
int[] GetOutputShape()
void ApplyGradients(Vector<T> gradients, T learningRate)
void Deserialize(byte[] modelData) Loads a previously serialized decision tree model from a byte array.
void Dispose()
void LoadModel(string filePath)
void LoadState(Stream stream) Loads the model’s state from a stream.
void SaveModel(string filePath)
void SaveState(Stream stream) Saves the model’s current state to a stream.
void SetParameters(Vector<T> parameters) Creates a new instance of the model with the specified parameters.
void Train(Matrix<T> x, Vector<T> y) Trains the decision tree model using the provided input features and target values.