Implementation:Interpretml Interpret ExampleRegressionObjective
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, EBM_Core |
| Last Updated | 2026-02-07 12:00 GMT |
Overview
Provides a documented example/template for implementing custom regression objective functions in the EBM framework.
Description
The ExampleRegressionObjective.hpp file defines the ExampleRegressionObjective struct as a reference implementation showing how to create a new regression objective. It demonstrates all required methods: the constructor accepting Config and custom parameters (param0, param1), CheckRegressionTarget for validation, LinkParam for link function parameters, learning rate and gain adjustment methods, GradientConstant/HessianConstant for factoring out constant multipliers, FinishMetric for post-processing the accumulated metric, and the three computation methods CalcMetric, CalcGradient, and CalcGradientHessian. The example uses an identity link function and implements a basic MSE-like objective where gradient = 2 * error and hessian = 2. It uses the OBJECTIVE_BOILERPLATE macro and explains each method's purpose in comments.
Usage
Serves as documentation and a template for developers adding new objective functions to the EBM library. Not intended for production use, but provides a complete working example of the objective interface.
Code Reference
Source Location
- Repository: Interpretml_Interpret
- File: shared/libebm/compute/objectives/ExampleRegressionObjective.hpp
Signature
template<typename TFloat> struct ExampleRegressionObjective : RegressionObjective {
OBJECTIVE_BOILERPLATE(ExampleRegressionObjective, MINIMIZE_METRIC,
Objective_Other, Link_identity, true)
TFloat m_param0;
TFloat m_param1;
static constexpr double Two = 2.0;
inline ExampleRegressionObjective(const Config& config,
const double param0, const double param1);
inline bool CheckRegressionTarget(const double target) const noexcept;
inline double LinkParam() const noexcept;
GPU_DEVICE inline TFloat CalcMetric(
const TFloat& score, const TFloat& target) const noexcept;
GPU_DEVICE inline TFloat CalcGradient(
const TFloat& score, const TFloat& target) const noexcept;
GPU_DEVICE inline GradientHessian<TFloat> CalcGradientHessian(
const TFloat& score, const TFloat& target) const noexcept;
};
I/O Contract
| Method | Input | Output |
|---|---|---|
| CalcMetric | score, target | (prediction - target)^2 |
| CalcGradient | score, target | 2 * (prediction - target) |
| CalcGradientHessian | score, target | gradient=2*error, hessian=2 |
Usage Examples
# This is a template objective - not directly called by users.
# Developers use it as a reference when creating new objectives.
from interpret.glassbox import ExplainableBoostingRegressor
ebm = ExplainableBoostingRegressor()
ebm.fit(X, y) # Production code uses RmseRegressionObjective instead