DecisionTreeClassifier<T>

Models & Types · AiDotNet.Classification.Trees

A decision tree classifier that learns a hierarchy of decision rules from training data.

Inheritance: ClassifierBase<T> → ProbabilisticClassifierBase<T> → DecisionTreeClassifier<T>

Implements: ITreeBasedClassifier<T>

For Beginners

Imagine playing a game of “20 Questions” to classify things. The decision tree learns which questions (based on features) best separate the different classes.

Example: Classifying whether to play tennis

  1. Is it raining? -> No: Go to step 2, Yes: Don’t play
  2. Is humidity > 75%? -> No: Play!, Yes: Don’t play

Each question splits the data based on a feature value, and leaves contain the final decisions.

How It Works

Decision trees are non-parametric supervised learning algorithms that learn decision rules inferred from data features. They partition the feature space into regions and assign class labels to each region.

Example

var newSample = new Matrix<double>(new double[,] { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 }, { 7.0, 8.0 } });
var labels = new Vector<double>(new double[] { 0.0, 1.0, 0.0, 1.0 });
var features = new Matrix<double>(new double[,] { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 }, { 7.0, 8.0 } });
// Use AiModelBuilder facade for decisiontreeclassifier classification
var builder = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new DecisionTreeClassifier<double>(
        new DecisionTreeClassifierOptions<double>()));
            
var result = builder.Build(features, labels);
var prediction = result.Predict(newSample);

Constructors

Constructor Summary
DecisionTreeClassifier(DecisionTreeClassifierOptions<T> options, IRegularization<T, Matrix<T>, Vector<T>> regularization) Initializes a new instance of the DecisionTreeClassifier class.

Properties

Property Summary
Vector<T> FeatureImportances { get; set; }
int LeafCount { get; }
int MaxDepth { get; }
int NodeCount { get; }

Methods

Method Summary
IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters)
Matrix<T> PredictProbabilities(Matrix<T> input)
ModelMetadata<T> GetModelMetadata()
Vector<T> ComputeGradients(Matrix<T> input, Vector<T> target, ILossFunction<T> lossFunction)
void ApplyGradients(Vector<T> gradients, T learningRate)
void Train(Matrix<T> x, Vector<T> y) Returns the model type identifier for this classifier.