skgrad documentation#
skgrad is a Python package for analytic input gradients and Jacobians of
supported fitted scikit-learn models. Install and import it as skgrad. It
returns derivatives of model outputs with respect to input features; use
UnifiedIG when you want feature attributions against a reference background.
scikit-learn does not expose input derivatives. skgrad computes them in closed form.
For a supported fitted estimator f and input x, skgrad returns ∂f/∂x
analytically, to floating-point precision—without finite differences, automatic
differentiation, model conversion, or model approximation. The same NumPy
interface handles supported affine models, neural networks, kernel SVMs, and
continuous preprocessing pipelines.
Classification derivatives use decision scores or logits, not probabilities.
For one scalar output, input_gradient returns (samples, features); the full
Jacobian has shape (samples, outputs, features). Select target explicitly
for a multi-output model, or request input_jacobian. Unsupported models raise
an error instead of falling back to numerical differentiation.
A ReLU network is piecewise linear. Its fitted weights and active units give its input derivative directly; no finite-difference step or framework conversion is needed. At a kink, skgrad uses the zero derivative convention for ReLU.
Start with installation and your first gradient, then explore worked examples. Check model coverage before applying the interface to a different estimator or preprocessing chain.
For automated readers, llms.txt links to complete example files and rendered API documentation.