decision-tree

    Deterministic classification and regression decision trees for MoonBit

    machine-learning
    decision-tree
    classification
    regression
    Download zip
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    3 months ago
    Downloads
    39

    No dependencies

    #MoonBit Decision Tree

    A deterministic decision-tree library written in MoonBit for dense, finite numeric datasets. The current release trains classification and regression trees with optional per-row sample weights, predicts single rows or batches, reports metrics and model structure, performs deterministic validation and configuration selection, applies cost-complexity pruning, diagnoses feature effects, and exports unweighted trees as text, JSON, or Graphviz DOT.

    #Installation

    Install the published 0.2.0 package from Mooncakes:

    moon add chenzexin02-hash/decision-tree

    Import it from moon.pkg:

    import {
    "chenzexin02-hash/decision-tree" @tree,
    }

    For source development, clone the repository and run the verification commands below.

    #Classification

    let dataset = @tree.classification_dataset(
    [[0.0], [1.0], [2.0], [3.0]],
    [0, 0, 1, 1],
    2,
    ).unwrap()
    let model = @tree.train_classifier(
    dataset,
    @tree.ClassificationConfig::default(),
    ).unwrap()
    let label = model.predict([2.5]).unwrap()
    let probabilities = model.predict_proba([2.5]).unwrap()

    Classification supports Gini and entropy criteria. Equal-gain splits are resolved by feature index and then by sorted threshold order. A leaf predicts the lowest class index among tied class counts.

    #Regression

    let dataset = @tree.regression_dataset(
    [[0.0], [1.0], [2.0], [3.0]],
    [0.0, 2.0, 4.0, 6.0],
    ).unwrap()
    let model = @tree.train_regressor(
    dataset,
    @tree.RegressionConfig::default(),
    ).unwrap()
    let prediction = model.predict([2.5]).unwrap()

    Regression splits minimize weighted population variance and leaves predict their training-target mean.

    #Sample-Weighted Training

    weighted_classification_dataset and weighted_regression_dataset accept one finite, nonnegative weight per row and require a positive total weight. Their typed training functions use weighted impurity or variance reduction and return independent weighted model types with prediction, batch prediction, depth, node and leaf counts, decision paths, and normalized feature importance. Weighted accuracy, mean squared error, and mean absolute error helpers are also provided.

    #Training Controls

    Both model types expose explicit configuration for maximum depth, minimum samples required to split, minimum samples in each leaf, and minimum impurity decrease. Classification also selects Gini or entropy. Invalid configuration and malformed datasets return typed TreeError values.

    #Evaluation and Inspection

    Implemented evaluation functions:

    • classification accuracy and confusion matrix;
    • mean squared error, mean absolute error, root mean squared error, and R-squared;
    • deterministic K-fold and stratified K-fold index generation;
    • classification and regression cross-validation summaries;
    • repeated cross-validation with mean, standard deviation, minimum, and maximum summaries;
    • validation-based selection from caller-supplied cost-complexity pruning strengths.

    Trained models expose tree depth, node count, leaf count, normalized impurity-based feature importance, and the decision path for one row. prune(alpha) returns a new cost-complexity-pruned model and leaves the source model unchanged.

    classification_report provides per-class precision, recall, specificity and F1 plus macro and support-weighted aggregates. Probability outputs can be evaluated with multiclass Brier score and log loss. regression_report combines MSE, MAE, RMSE, R-squared, maximum error, mean signed error and explained variance.

    Configuration grids and select_classifier / select_regressor evaluate candidates through deterministic cross-validation. pruning_path returns distinct models at increasing cost-complexity strengths. Prediction explanations include the stable leaf ID, path, leaf statistics and confidence or variance; rules extracts every leaf as structured conditions.

    Permutation importance measures validation-score degradation after deterministic feature rotation. Partial-dependence APIs average class probabilities or regression predictions at caller-supplied feature values.

    #Export

    to_text, to_json, and to_dot require feature names; classification export also requires class names. Name counts are validated. JSON and DOT labels escape quotes, backslashes, and control whitespace. Exports retain split features, thresholds, predictions, sample counts, impurity or variance, and child structure.

    #Runnable Examples

    moon run examples/classification moon run examples/regression moon run examples/validation moon run examples/export moon run examples/weighted

    The examples use only public APIs and are executed by CI.

    #Verification

    moon clean moon fmt --check moon info moon check --deny-warn moon build moon test moon run examples/classification moon run examples/regression moon run examples/validation moon run examples/export moon run examples/weighted powershell -NoProfile -ExecutionPolicy Bypass -File scripts/source-audit.ps1 moon publish --dry-run

    At the repository state documented for 0.2.0, moon test runs 70 tests. The source-audit script reports physical and substantive production/test lines separately and rejects placeholder markers in MoonBit source.

    #Current Scope

    The current release accepts only non-empty dense numeric rows with finite values. Class labels are zero-based integers, and classification requires an explicit class count. Models and datasets are in-memory MoonBit values.

    Categorical feature handling, missing-value policies, ensembles, incremental or multi-output learning, persistence import, and performance benchmarking remain candidates for later releases. Version 0.2.0 does not claim those capabilities. Network services, databases, and parallel or distributed training are outside the current package implementation.

    #Project Status

    This is an original MoonBit implementation, not a line-by-line port. Standard decision-tree concepts and evaluation definitions are listed in docs/references.md. Implementation evidence and acceptance commands are recorded in docs/development-report.md and docs/acceptance-checklist.md.

    Licensed under the Apache License 2.0.

    ClassMetrics

    pub(all) struct ClassMetrics {
    class_index : Int
    support : Int
    true_positive : Int
    false_positive : Int
    false_negative : Int
    true_negative : Int
    precision : Double
    recall : Double
    specificity : Double
    f1 : Double
    } derive(Eq,
    Debug
    )

    ClassificationCandidate

    pub(all) struct ClassificationCandidate {
    config : ClassificationConfig
    mean_accuracy : Double
    } derive(Eq,
    Debug
    )

    ClassificationConfig

    pub(all) struct ClassificationConfig {
    max_depth : Int
    min_samples_split : Int
    min_samples_leaf : Int
    min_impurity_decrease : Double
    criterion : ClassificationCriterion
    } derive(Eq,
    Debug
    )

    Configures deterministic classification-tree training.

    ClassificationConfig::default

    ClassificationCriterion

    pub(all) enum ClassificationCriterion {
    Gini
    Entropy
    } derive(Eq,
    Debug
    )

    Selects the impurity measure used for classification splits.

    ClassificationDataset

    pub(all) struct ClassificationDataset {
    rows : Array[Array[Double]]
    labels : Array[Int]
    feature_total : Int
    class_total : Int
    } derive(Eq,
    Debug
    )

    Stores validated dense numeric rows and integer class labels.

    ClassificationDataset::class_count

    fn ClassificationDataset::class_count(self : ClassificationDataset) -> Int

    ClassificationDataset::feature_count

    fn ClassificationDataset::feature_count(self : ClassificationDataset) -> Int

    ClassificationDataset::label

    fn ClassificationDataset::label(self : ClassificationDataset, index : Int) -> Int

    ClassificationDataset::row

    fn ClassificationDataset::row(self : ClassificationDataset, index : Int) -> Array[Double]

    ClassificationDataset::row_count

    fn ClassificationDataset::row_count(self : ClassificationDataset) -> Int

    ClassificationExplanation

    pub(all) struct ClassificationExplanation {
    prediction : Int
    probabilities : Array[Double]
    confidence : Double
    leaf_id : Int
    leaf_samples : Int
    leaf_impurity : Double
    path : Array[DecisionStep]
    } derive(Eq,
    Debug
    )

    ClassificationNode

    pub(all) enum ClassificationNode {
    ClassificationLeaf(Int, Array[Double], Int, Double)
    ClassificationBranch(Int, Double, ClassificationNode, ClassificationNode, Int, Double, Double)
    } derive(Eq,
    Debug
    )

    Retains all statistics needed for prediction, export, and pruning.

    ClassificationPartialDependence

    pub(all) struct ClassificationPartialDependence {
    feature_index : Int
    values : Array[Double]
    average_probabilities : Array[Array[Double]]
    } derive(Eq,
    Debug
    )

    ClassificationPruningCandidate

    pub(all) struct ClassificationPruningCandidate {
    alpha : Double
    mean_accuracy : Double
    node_count : Int
    leaf_count : Int
    } derive(Eq,
    Debug
    )

    ClassificationPruningSelection

    pub(all) struct ClassificationPruningSelection {
    best_alpha : Double
    best_accuracy : Double
    model : ClassificationTree
    candidates : Array[ClassificationPruningCandidate]
    } derive(Eq,
    Debug
    )

    ClassificationPruningStep

    pub(all) struct ClassificationPruningStep {
    alpha : Double
    model : ClassificationTree
    node_count : Int
    leaf_count : Int
    } derive(Eq,
    Debug
    )

    ClassificationReport

    pub(all) struct ClassificationReport {
    accuracy : Double
    macro_precision : Double
    macro_recall : Double
    macro_f1 : Double
    weighted_precision : Double
    weighted_recall : Double
    weighted_f1 : Double
    classes : Array[ClassMetrics]
    } derive(Eq,
    Debug
    )

    ClassificationRule

    pub(all) struct ClassificationRule {
    leaf_id : Int
    conditions : Array[RuleCondition]
    prediction : Int
    probabilities : Array[Double]
    samples : Int
    impurity : Double
    } derive(Eq,
    Debug
    )

    ClassificationSelection

    pub(all) struct ClassificationSelection {
    best_config : ClassificationConfig
    best_accuracy : Double
    candidates : Array[ClassificationCandidate]
    } derive(Eq,
    Debug
    )

    ClassificationTree

    pub(all) struct ClassificationTree {
    root : ClassificationNode
    feature_total : Int
    class_total : Int
    config : ClassificationConfig
    } derive(Eq,
    Debug
    )

    Stores one immutable trained classification tree.

    ClassificationTree::apply

    fn ClassificationTree::apply(self : ClassificationTree, features : Array[Double]) -> Result[Int, TreeError]

    ClassificationTree::apply_batch

    fn ClassificationTree::apply_batch(self : ClassificationTree, rows : Array[Array[Double]]) -> Result[Array[Int], TreeError]

    ClassificationTree::decision_path

    fn ClassificationTree::decision_path(self : ClassificationTree, features : Array[Double]) -> Result[Array[DecisionStep], TreeError]

    ClassificationTree::depth

    fn ClassificationTree::depth(self : ClassificationTree) -> Int

    ClassificationTree::explain

    fn ClassificationTree::explain(self : ClassificationTree, features : Array[Double]) -> Result[ClassificationExplanation, TreeError]

    ClassificationTree::feature_importance

    fn ClassificationTree::feature_importance(self : ClassificationTree) -> Array[Double]

    ClassificationTree::leaf_count

    fn ClassificationTree::leaf_count(self : ClassificationTree) -> Int

    ClassificationTree::node_count

    fn ClassificationTree::node_count(self : ClassificationTree) -> Int

    ClassificationTree::predict

    fn ClassificationTree::predict(self : ClassificationTree, features : Array[Double]) -> Result[Int, TreeError]

    ClassificationTree::predict_batch

    fn ClassificationTree::predict_batch(self : ClassificationTree, rows : Array[Array[Double]]) -> Result[Array[Int], TreeError]

    ClassificationTree::predict_proba

    fn ClassificationTree::predict_proba(self : ClassificationTree, features : Array[Double]) -> Result[Array[Double], TreeError]

    ClassificationTree::prune

    fn ClassificationTree::prune(self : ClassificationTree, alpha : Double) -> Result[ClassificationTree, TreeError]

    Returns a pruned copy using leaf-risk plus alpha times leaf count.

    ClassificationTree::pruning_path

    Generates distinct models at increasing cost-complexity strengths.

    ClassificationTree::rules

    ClassificationTree::to_dot

    fn ClassificationTree::to_dot(self : ClassificationTree, feature_names : Array[String], class_names : Array[String]) -> Result[String, TreeError]

    ClassificationTree::to_json

    fn ClassificationTree::to_json(self : ClassificationTree, feature_names : Array[String], class_names : Array[String]) -> Result[String, TreeError]

    ClassificationTree::to_text

    fn ClassificationTree::to_text(self : ClassificationTree, feature_names : Array[String], class_names : Array[String]) -> Result[String, TreeError]

    ClassificationValidation

    pub(all) struct ClassificationValidation {
    fold_scores : Array[Double]
    mean_accuracy : Double
    } derive(Eq,
    Debug
    )

    DecisionDirection

    pub(all) enum DecisionDirection {
    GoLeft
    GoRight
    } derive(Eq,
    Debug
    )

    DecisionStep

    pub(all) enum DecisionStep {
    DecisionStep(Int, Double, DecisionDirection)
    } derive(Eq,
    Debug
    )

    Fold

    pub(all) struct Fold {
    train_indices : Array[Int]
    test_indices : Array[Int]
    } derive(Eq,
    Debug
    )

    RegressionCandidate

    pub(all) struct RegressionCandidate {
    config : RegressionConfig
    mean_mse : Double
    mean_mae : Double
    } derive(Eq,
    Debug
    )

    RegressionConfig

    pub(all) struct RegressionConfig {
    max_depth : Int
    min_samples_split : Int
    min_samples_leaf : Int
    min_impurity_decrease : Double
    } derive(Eq,
    Debug
    )

    Configures deterministic regression-tree training.

    RegressionConfig::default

    RegressionDataset

    pub(all) struct RegressionDataset {
    rows : Array[Array[Double]]
    targets : Array[Double]
    feature_total : Int
    } derive(Eq,
    Debug
    )

    Stores validated dense numeric rows and continuous targets.

    RegressionDataset::feature_count

    fn RegressionDataset::feature_count(self : RegressionDataset) -> Int

    RegressionDataset::row

    fn RegressionDataset::row(self : RegressionDataset, index : Int) -> Array[Double]

    RegressionDataset::row_count

    fn RegressionDataset::row_count(self : RegressionDataset) -> Int

    RegressionDataset::target

    fn RegressionDataset::target(self : RegressionDataset, index : Int) -> Double

    RegressionExplanation

    pub(all) struct RegressionExplanation {
    prediction : Double
    leaf_id : Int
    leaf_samples : Int
    leaf_variance : Double
    path : Array[DecisionStep]
    } derive(Eq,
    Debug
    )

    RegressionNode

    pub(all) enum RegressionNode {
    RegressionLeaf(Double, Int, Double)
    RegressionBranch(Int, Double, RegressionNode, RegressionNode, Int, Double, Double)
    } derive(Eq,
    Debug
    )

    Retains prediction and variance statistics for traversal and pruning.

    RegressionPartialDependence

    pub(all) struct RegressionPartialDependence {
    feature_index : Int
    values : Array[Double]
    average_predictions : Array[Double]
    } derive(Eq,
    Debug
    )

    RegressionPruningCandidate

    pub(all) struct RegressionPruningCandidate {
    alpha : Double
    mean_mse : Double
    mean_mae : Double
    node_count : Int
    leaf_count : Int
    } derive(Eq,
    Debug
    )

    RegressionPruningSelection

    pub(all) struct RegressionPruningSelection {
    best_alpha : Double
    best_mse : Double
    best_mae : Double
    model : RegressionTree
    candidates : Array[RegressionPruningCandidate]
    } derive(Eq,
    Debug
    )

    RegressionPruningStep

    pub(all) struct RegressionPruningStep {
    alpha : Double
    model : RegressionTree
    node_count : Int
    leaf_count : Int
    } derive(Eq,
    Debug
    )

    RegressionReport

    pub(all) struct RegressionReport {
    mse : Double
    mae : Double
    rmse : Double
    r2 : Double
    max_error : Double
    mean_error : Double
    explained_variance : Double
    } derive(Eq,
    Debug
    )

    RegressionRule

    pub(all) struct RegressionRule {
    leaf_id : Int
    conditions : Array[RuleCondition]
    prediction : Double
    samples : Int
    variance : Double
    } derive(Eq,
    Debug
    )

    RegressionSelection

    pub(all) struct RegressionSelection {
    best_config : RegressionConfig
    best_mse : Double
    best_mae : Double
    candidates : Array[RegressionCandidate]
    } derive(Eq,
    Debug
    )

    RegressionTree

    pub(all) struct RegressionTree {
    root : RegressionNode
    feature_total : Int
    config : RegressionConfig
    } derive(Eq,
    Debug
    )

    Stores one immutable trained regression tree.

    RegressionTree::apply

    fn RegressionTree::apply(self : RegressionTree, features : Array[Double]) -> Result[Int, TreeError]

    RegressionTree::apply_batch

    fn RegressionTree::apply_batch(self : RegressionTree, rows : Array[Array[Double]]) -> Result[Array[Int], TreeError]

    RegressionTree::decision_path

    fn RegressionTree::decision_path(self : RegressionTree, features : Array[Double]) -> Result[Array[DecisionStep], TreeError]

    RegressionTree::depth

    fn RegressionTree::depth(self : RegressionTree) -> Int

    RegressionTree::explain

    fn RegressionTree::explain(self : RegressionTree, features : Array[Double]) -> Result[RegressionExplanation, TreeError]

    RegressionTree::feature_importance

    fn RegressionTree::feature_importance(self : RegressionTree) -> Array[Double]

    RegressionTree::leaf_count

    fn RegressionTree::leaf_count(self : RegressionTree) -> Int

    RegressionTree::node_count

    fn RegressionTree::node_count(self : RegressionTree) -> Int

    RegressionTree::predict

    fn RegressionTree::predict(self : RegressionTree, features : Array[Double]) -> Result[Double, TreeError]

    RegressionTree::predict_batch

    fn RegressionTree::predict_batch(self : RegressionTree, rows : Array[Array[Double]]) -> Result[Array[Double], TreeError]

    RegressionTree::prune

    fn RegressionTree::prune(self : RegressionTree, alpha : Double) -> Result[RegressionTree, TreeError]

    Returns a pruned copy using leaf-risk plus alpha times leaf count.

    RegressionTree::pruning_path

    Generates distinct models at increasing cost-complexity strengths.

    RegressionTree::rules

    RegressionTree::to_dot

    fn RegressionTree::to_dot(self : RegressionTree, feature_names : Array[String]) -> Result[String, TreeError]

    RegressionTree::to_json

    fn RegressionTree::to_json(self : RegressionTree, feature_names : Array[String]) -> Result[String, TreeError]

    RegressionTree::to_text

    fn RegressionTree::to_text(self : RegressionTree, feature_names : Array[String]) -> Result[String, TreeError]

    RegressionValidation

    pub(all) struct RegressionValidation {
    fold_mse : Array[Double]
    fold_mae : Array[Double]
    mean_mse : Double
    mean_mae : Double
    } derive(Eq,
    Debug
    )

    RepeatedClassificationValidation

    pub(all) struct RepeatedClassificationValidation {
    repeat_means : Array[Double]
    fold_scores : Array[Double]
    mean_accuracy : Double
    standard_deviation : Double
    minimum_accuracy : Double
    maximum_accuracy : Double
    } derive(Eq,
    Debug
    )

    RepeatedRegressionValidation

    pub(all) struct RepeatedRegressionValidation {
    repeat_mse : Array[Double]
    repeat_mae : Array[Double]
    fold_mse : Array[Double]
    fold_mae : Array[Double]
    mean_mse : Double
    mean_mae : Double
    mse_standard_deviation : Double
    mae_standard_deviation : Double
    } derive(Eq,
    Debug
    )

    RuleCondition

    pub(all) enum RuleCondition {
    RuleCondition(Int, Double, DecisionDirection)
    } derive(Eq,
    Debug
    )

    TreeError

    pub(all) enum TreeError {
    InvalidMaxDepth(Int)
    InvalidMinSamplesSplit(Int)
    InvalidMinSamplesLeaf(Int)
    InvalidMinImpurityDecrease(Double)
    InvalidClassCount(Int)
    EmptyDataset
    EmptyFeatureRow(Int)
    TargetCountMismatch(Int, Int)
    InconsistentFeatureCount(Int, Int, Int)
    InvalidClassLabel(Int, Int, Int)
    NonFiniteFeature(Int, Int)
    NonFiniteTarget(Int)
    PredictionFeatureCountMismatch(Int, Int)
    ModelNotTrained
    InvalidFoldCount(Int, Int)
    InvalidFeatureNameCount(Int, Int)
    InvalidClassNameCount(Int, Int)
    InvalidPruningAlpha(Double)
    MetricLengthMismatch(Int, Int)
    EmptyConfigurationGrid
    InvalidTestCount(Int, Int)
    ProbabilityRowCountMismatch(Int, Int)
    InvalidProbabilityWidth(Int, Int, Int)
    InvalidProbabilityValue(Int, Int)
    InvalidProbabilitySum(Int)
    InvalidFeatureIndex(Int, Int)
    WeightCountMismatch(Int, Int)
    InvalidSampleWeight(Int)
    ZeroTotalWeight
    InvalidRepeatCount(Int)
    EmptyPruningGrid
    } derive(Eq,
    Debug
    )

    Reports invalid input without discarding the value or source position.

    WeightedClassificationDataset

    pub(all) struct WeightedClassificationDataset {
    rows : Array[Array[Double]]
    labels : Array[Int]
    weights : Array[Double]
    feature_total : Int
    class_total : Int
    weight_total : Double
    } derive(Eq,
    Debug
    )

    WeightedClassificationDataset::class_count

    WeightedClassificationDataset::feature_count

    WeightedClassificationDataset::row_count

    WeightedClassificationDataset::total_weight

    WeightedClassificationNode

    pub(all) enum WeightedClassificationNode {
    WeightedClassificationLeaf(Int, Array[Double], Int, Double, Double)
    WeightedClassificationBranch(Int, Double, WeightedClassificationNode, WeightedClassificationNode, Int, Double, Double, Double)
    } derive(Eq,
    Debug
    )

    WeightedClassificationTree

    pub(all) struct WeightedClassificationTree {
    root : WeightedClassificationNode
    feature_total : Int
    class_total : Int
    config : ClassificationConfig
    } derive(Eq,
    Debug
    )

    WeightedClassificationTree::decision_path

    fn WeightedClassificationTree::decision_path(self : WeightedClassificationTree, features : Array[Double]) -> Result[Array[DecisionStep], TreeError]

    WeightedClassificationTree::depth

    WeightedClassificationTree::feature_importance

    fn WeightedClassificationTree::feature_importance(self : WeightedClassificationTree) -> Array[Double]

    WeightedClassificationTree::leaf_count

    WeightedClassificationTree::node_count

    WeightedClassificationTree::predict

    fn WeightedClassificationTree::predict(self : WeightedClassificationTree, features : Array[Double]) -> Result[Int, TreeError]

    WeightedClassificationTree::predict_batch

    fn WeightedClassificationTree::predict_batch(self : WeightedClassificationTree, rows : Array[Array[Double]]) -> Result[Array[Int], TreeError]

    WeightedClassificationTree::predict_proba

    fn WeightedClassificationTree::predict_proba(self : WeightedClassificationTree, features : Array[Double]) -> Result[Array[Double], TreeError]

    WeightedRegressionDataset

    pub(all) struct WeightedRegressionDataset {
    rows : Array[Array[Double]]
    targets : Array[Double]
    weights : Array[Double]
    feature_total : Int
    weight_total : Double
    } derive(Eq,
    Debug
    )

    WeightedRegressionDataset::feature_count

    fn WeightedRegressionDataset::feature_count(self : WeightedRegressionDataset) -> Int

    WeightedRegressionDataset::row_count

    WeightedRegressionDataset::total_weight

    fn WeightedRegressionDataset::total_weight(self : WeightedRegressionDataset) -> Double

    WeightedRegressionNode

    pub(all) enum WeightedRegressionNode {
    WeightedRegressionLeaf(Double, Int, Double, Double)
    WeightedRegressionBranch(Int, Double, WeightedRegressionNode, WeightedRegressionNode, Int, Double, Double, Double)
    } derive(Eq,
    Debug
    )

    WeightedRegressionTree

    pub(all) struct WeightedRegressionTree {
    root : WeightedRegressionNode
    feature_total : Int
    config : RegressionConfig
    } derive(Eq,
    Debug
    )

    WeightedRegressionTree::decision_path

    fn WeightedRegressionTree::decision_path(self : WeightedRegressionTree, features : Array[Double]) -> Result[Array[DecisionStep], TreeError]

    WeightedRegressionTree::depth

    WeightedRegressionTree::feature_importance

    fn WeightedRegressionTree::feature_importance(self : WeightedRegressionTree) -> Array[Double]

    WeightedRegressionTree::leaf_count

    fn WeightedRegressionTree::leaf_count(self : WeightedRegressionTree) -> Int

    WeightedRegressionTree::node_count

    fn WeightedRegressionTree::node_count(self : WeightedRegressionTree) -> Int

    WeightedRegressionTree::predict

    fn WeightedRegressionTree::predict(self : WeightedRegressionTree, features : Array[Double]) -> Result[Double, TreeError]

    WeightedRegressionTree::predict_batch

    fn WeightedRegressionTree::predict_batch(self : WeightedRegressionTree, rows : Array[Array[Double]]) -> Result[Array[Double], TreeError]

    checked_entropy_impurity

    fn checked_entropy_impurity(labels : Array[Int], class_count : Int) -> Result[Double, TreeError]

    Validates labels before calculating entropy impurity.

    checked_gini_impurity

    fn checked_gini_impurity(labels : Array[Int], class_count : Int) -> Result[Double, TreeError]

    Validates labels before calculating Gini impurity.

    classification_accuracy

    fn classification_accuracy(actual : Array[Int], predicted : Array[Int]) -> Result[Double, TreeError]

    classification_config_grid

    fn classification_config_grid(max_depths : Array[Int], min_samples_leaf_values : Array[Int], criteria : Array[ClassificationCriterion]) -> Result[Array[ClassificationConfig], TreeError]

    Builds a validated Cartesian product of classification controls.

    classification_dataset

    fn classification_dataset(rows : Array[Array[Double]], labels : Array[Int], class_count : Int) -> Result[ClassificationDataset, TreeError]

    Validates and copies a classification dataset.

    classification_report

    fn classification_report(actual : Array[Int], predicted : Array[Int], class_count : Int) -> Result[ClassificationReport, TreeError]

    Computes one-vs-rest class metrics and macro/weighted aggregates.

    classifier_partial_dependence

    fn classifier_partial_dependence(model : ClassificationTree, dataset : ClassificationDataset, feature_index : Int, values : Array[Double]) -> Result[ClassificationPartialDependence, TreeError]

    classifier_permutation_importance

    fn classifier_permutation_importance(model : ClassificationTree, dataset : ClassificationDataset, seed : Int) -> Result[Array[Double], TreeError]

    Returns baseline accuracy minus accuracy after deterministic column rotation.

    confusion_matrix

    fn confusion_matrix(actual : Array[Int], predicted : Array[Int], class_count : Int) -> Result[Array[Array[Int]], TreeError]

    Rows are actual classes and columns are predicted classes.

    cross_validate_classifier

    fn cross_validate_classifier(dataset : ClassificationDataset, config : ClassificationConfig, fold_count : Int, seed : Int) -> Result[ClassificationValidation, TreeError]

    cross_validate_regressor

    fn cross_validate_regressor(dataset : RegressionDataset, config : RegressionConfig, fold_count : Int, seed : Int) -> Result[RegressionValidation, TreeError]

    entropy_impurity

    fn entropy_impurity(labels : Array[Int], class_count : Int) -> Double

    gini_impurity

    fn gini_impurity(labels : Array[Int], class_count : Int) -> Double

    holdout_indices

    fn holdout_indices(row_count : Int, test_count : Int, seed : Int) -> Result[Fold, TreeError]

    Selects a contiguous seed-rotated test segment and sorted training indices.

    k_fold_indices

    fn k_fold_indices(row_count : Int, fold_count : Int, seed : Int) -> Result[Array[Fold], TreeError]

    Creates deterministic folds from a seed-controlled cyclic order.

    mean_absolute_error

    fn mean_absolute_error(actual : Array[Double], predicted : Array[Double]) -> Result[Double, TreeError]

    mean_squared_error

    fn mean_squared_error(actual : Array[Double], predicted : Array[Double]) -> Result[Double, TreeError]

    mean_value

    fn mean_value(values : Array[Double]) -> Double

    multiclass_brier_score

    fn multiclass_brier_score(actual : Array[Int], probabilities : Array[Array[Double]], class_count : Int) -> Result[Double, TreeError]

    Returns the mean summed squared probability error per row.

    multiclass_log_loss

    fn multiclass_log_loss(actual : Array[Int], probabilities : Array[Array[Double]], class_count : Int) -> Result[Double, TreeError]

    Computes natural-log loss with probabilities clamped at 1e-15.

    r_squared

    fn r_squared(actual : Array[Double], predicted : Array[Double]) -> Result[Double, TreeError]

    Returns 1 for an exact constant-target prediction and 0 otherwise.

    regression_config_grid

    fn regression_config_grid(max_depths : Array[Int], min_samples_leaf_values : Array[Int]) -> Result[Array[RegressionConfig], TreeError]

    Builds a validated Cartesian product of regression controls.

    regression_dataset

    fn regression_dataset(rows : Array[Array[Double]], targets : Array[Double]) -> Result[RegressionDataset, TreeError]

    Validates and copies a regression dataset.

    regression_report

    fn regression_report(actual : Array[Double], predicted : Array[Double]) -> Result[RegressionReport, TreeError]

    regressor_partial_dependence

    fn regressor_partial_dependence(model : RegressionTree, dataset : RegressionDataset, feature_index : Int, values : Array[Double]) -> Result[RegressionPartialDependence, TreeError]

    regressor_permutation_importance

    fn regressor_permutation_importance(model : RegressionTree, dataset : RegressionDataset, seed : Int) -> Result[Array[Double], TreeError]

    Returns shuffled-feature MSE minus baseline MSE.

    repeated_cross_validate_classifier

    fn repeated_cross_validate_classifier(dataset : ClassificationDataset, config : ClassificationConfig, fold_count : Int, repeat_count : Int, seed : Int) -> Result[RepeatedClassificationValidation, TreeError]

    Repeats stratified cross-validation with deterministic derived seeds.

    repeated_cross_validate_regressor

    fn repeated_cross_validate_regressor(dataset : RegressionDataset, config : RegressionConfig, fold_count : Int, repeat_count : Int, seed : Int) -> Result[RepeatedRegressionValidation, TreeError]

    Repeats regression cross-validation with deterministic derived seeds.

    root_mean_squared_error

    fn root_mean_squared_error(actual : Array[Double], predicted : Array[Double]) -> Result[Double, TreeError]

    select_classifier

    fn select_classifier(dataset : ClassificationDataset, configs : Array[ClassificationConfig], fold_count : Int, seed : Int) -> Result[ClassificationSelection, TreeError]

    Evaluates candidates in input order and keeps the first score tie.

    select_classifier_pruning_alpha

    fn select_classifier_pruning_alpha(dataset : ClassificationDataset, config : ClassificationConfig, alphas : Array[Double], fold_count : Int, seed : Int) -> Result[ClassificationPruningSelection, TreeError]

    Selects alpha by mean validation accuracy, then by fewer full-data nodes.

    select_regressor

    fn select_regressor(dataset : RegressionDataset, configs : Array[RegressionConfig], fold_count : Int, seed : Int) -> Result[RegressionSelection, TreeError]

    Evaluates candidates in input order and keeps the first MSE tie.

    select_regressor_pruning_alpha

    fn select_regressor_pruning_alpha(dataset : RegressionDataset, config : RegressionConfig, alphas : Array[Double], fold_count : Int, seed : Int) -> Result[RegressionPruningSelection, TreeError]

    Selects alpha by mean validation MSE, then by fewer full-data nodes.

    stratified_k_fold_indices

    fn stratified_k_fold_indices(labels : Array[Int], class_count : Int, fold_count : Int, seed : Int) -> Result[Array[Fold], TreeError]

    Distributes each class round-robin while retaining deterministic order.

    train_classifier

    fn train_classifier(dataset : ClassificationDataset, config : ClassificationConfig) -> Result[ClassificationTree, TreeError]

    Trains one deterministic classification tree.

    train_regressor

    fn train_regressor(dataset : RegressionDataset, config : RegressionConfig) -> Result[RegressionTree, TreeError]

    Trains one deterministic regression tree.

    train_weighted_classifier

    fn train_weighted_classifier(dataset : WeightedClassificationDataset, config : ClassificationConfig) -> Result[WeightedClassificationTree, TreeError]

    train_weighted_regressor

    fn train_weighted_regressor(dataset : WeightedRegressionDataset, config : RegressionConfig) -> Result[WeightedRegressionTree, TreeError]

    variance_value

    fn variance_value(values : Array[Double]) -> Double

    weighted_classification_accuracy

    fn weighted_classification_accuracy(actual : Array[Int], predicted : Array[Int], weights : Array[Double]) -> Result[Double, TreeError]

    weighted_classification_dataset

    fn weighted_classification_dataset(rows : Array[Array[Double]], labels : Array[Int], weights : Array[Double], class_count : Int) -> Result[WeightedClassificationDataset, TreeError]

    weighted_mean_absolute_error

    fn weighted_mean_absolute_error(actual : Array[Double], predicted : Array[Double], weights : Array[Double]) -> Result[Double, TreeError]

    weighted_mean_squared_error

    fn weighted_mean_squared_error(actual : Array[Double], predicted : Array[Double], weights : Array[Double]) -> Result[Double, TreeError]

    weighted_regression_dataset

    fn weighted_regression_dataset(rows : Array[Array[Double]], targets : Array[Double], weights : Array[Double]) -> Result[WeightedRegressionDataset, TreeError]