From c27e02f02acf3a66fc56e60b4b9cd19f2cd0c583 Mon Sep 17 00:00:00 2001 From: singjc Date: Thu, 20 Mar 2025 09:23:38 -0400 Subject: [PATCH] feat: Add `decision_function` method to GBDT class The `decision_function` method computes the unnormalized raw scores (logits) from the gradient boosting model for the given test data. This allows the user to interpret the raw values directly, with higher values indicating stronger confidence in the positive class. Example usage: ```rust let raw_scores = gbdt.decision_function(&test_data); ``` --- src/gradient_boost.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/gradient_boost.rs b/src/gradient_boost.rs index cb298c1..41b4b9f 100644 --- a/src/gradient_boost.rs +++ b/src/gradient_boost.rs @@ -382,6 +382,27 @@ impl GBDT { predicted } + /// Compute raw decision scores for the given test data. + /// + /// This function returns the unnormalized raw scores (logits) from the gradient boosting model. + /// It does not apply any transformation such as the logistic sigmoid function, allowing the user + /// to interpret the raw values directly. Higher values indicate stronger confidence in the positive class. + /// + /// This is similar to `decision_function` in scikit-learn or `BinaryLogisticRaw` in XGBoost. + /// + /// # Example + /// ```rust + /// let raw_scores = gbdt.decision_function(&test_data); + /// ``` + /// + /// # Panic + /// If the number of trained trees does not match the configured iterations, it will panic. + pub fn decision_function(&self, test_data: &DataVec) -> PredVec { + assert_eq!(self.conf.iterations, self.trees.len()); + self.predict_n(test_data, 0, self.conf.iterations, test_data.len()) + } + + /// Predict the given data. /// /// Note that for log likelyhood loss type, the predicted value will be