API reference#
All functions accept a fitted supported estimator. See semantics for output axes, target selection, errors, and classification scales.
- skgrad.supports(model: object) bool#
Return whether skgrad has an analytic backend for
model.
- skgrad.gradient_properties(model: object) GradientProperties#
Return computational properties of a supported model’s Jacobian.
- skgrad.model_output(model: object, X: object) NDArray[floating]#
Return predictions for regressors or raw scores/logits for classifiers.
- skgrad.input_gradient(model: object, X: object, target: int | None = None) NDArray[floating]#
Return gradients for one selected scalar model output.
- skgrad.input_jacobian(model: object, X: object) NDArray[floating]#
Return input Jacobians with shape
(samples, outputs, features).
- skgrad.value_and_jacobian(model: object, X: object) GradientResult#
Return model values and analytic input Jacobians.
Values have shape
(n_samples, n_outputs). Jacobians have shape(n_samples, n_outputs, n_features). Classifiers return raw decision scores or logits rather than probabilities.
- class skgrad.GradientResult(values: NDArray[floating], jacobian: NDArray[floating])#
Model values and their input Jacobians.
- class skgrad.GradientProperties(constant_jacobian: bool, exact_quadrature_steps: int | None)#
Properties that downstream gradient consumers may optimize around.
Pipeline feature-space views#
- skgrad.pipeline_view(model: object, *, after: str | None = None) PipelineView#
Select the inputs or an intermediate feature space of a fitted Pipeline.
after=Nonekeeps original pipeline inputs. Otherwise give a preprocessing step name, or a nested path such as'preprocess__scale'. The view transforms original observations with the fitted prefix and exposes the remaining predictor asview.model. Prefix steps must be supported continuous transformations. Suffix backend eligibility is checked by the caller.
- class skgrad.PipelineView(source_model: Pipeline, model: object, prefix: Sequence[object], after: str | None)#
A fitted predictor viewed after a named preprocessing step.
Create with
skgrad.pipeline_view().modelaccepts transformed inputs. Convenience gradient methods accept original pipeline inputs and differentiate in the selected space. Fitted steps are shared, not refitted or copied; do not refit the source pipeline while using this view.- get_feature_names_out(input_features: Sequence[str] | None = None) ndarray#
Names of coordinates in the selected feature space.
- input_gradient(X: object, target: int | None = None) ndarray#
Differentiate in selected coordinates, accepting original inputs.
- input_jacobian(X: object) ndarray#
Return all output derivatives in selected coordinates.
- model_output(X: object) ndarray#
Evaluate model outputs from original pipeline inputs.
- transform(X: object) ndarray#
Map original pipeline inputs to the selected feature space.
- value_and_jacobian(X: object) GradientResult#
Return outputs and selected-coordinate Jacobians.