Numerical conventions and fallback policy#
Analytic derivatives#
Affine estimators reuse fitted coefficients. MLPs propagate the chain rule through fitted weights and hidden activations. SVMs differentiate built-in kernels. Polynomial pipelines compose derivatives through expanded monomials, including at zero-valued coordinates.
ReLU has no unique ordinary derivative at zero. skgrad chooses zero there. Floating-point evaluation remains approximate even when the derivative formula is analytic. For a smooth model, central differences are useful for checking that formula, but errors depend on step size, input scale, and precision.
The kernel example checks an analytic result against central differences of sklearn’s own predictions. Test several step sizes when diagnosing disagreement; very small steps amplify subtraction error, while large steps approximate a wider neighborhood.
Should skgrad have a numerical fallback?#
The current API deliberately provides analytic derivatives only. Coverage is strong for its listed families, but important sklearn gaps remain. A hidden fallback would make cost and accuracy depend on an implicit dispatch choice and could approximate a different classification output scale.
UnifiedIG already implements a finite-difference backend for eligible unsupported sklearn models. Keep that choice visible at the attribution layer, with explicit output semantics and numerical settings. Standalone numerical checks can use a clearly chosen prediction callable, as in the worked example.
Numerical gradients are useful for smooth unsupported functions. They do not repair discontinuities: a tree’s ordinary gradient misses its prediction jumps, and a perturbation of a categorical feature may not describe a valid input. Use TreeIG for supported tree paths.
Priorities for broader analytic coverage#
Continuous preprocessing composition is now supported for the transformations listed in pipeline gradients. ColumnTransformer composition, additional affine estimator families, and generalized linear output links are natural next steps. Kernel ridge and supported Gaussian process kernels are further candidates. These remain future directions for 0.1.6.