package modelkit
Module Modelkit.PipelineSource
Immutable sequential composition of fitted preprocessing and an estimator.
Transformer stages are fitted only from the matrix supplied to fit. Their fitted values are then reused by transform, predict, decision_function, and predict_proba. Stage names are non-empty and unique across the whole pipeline, and failures carry the responsible Error.Stage context.
Unsupervised stages do not receive targets; Pipeline.Supervised additionally packages target-aware stages in a builder tied to the target kind. Legacy packages route sample weights to the terminal estimator and to transformers opting in with route_sample_weight. Metadata-aware packages use declared per-method requests for weights and groups. Each stage receives a child RNG derived from its logical name and position. Fit and inference are sequential and allocate one dense matrix per transformer stage.
Caching is disabled by default. with_cache attaches an explicit caller-owned store retained by pipeline clones used in cross-validation and search. Cache-capable descendants in nested composition receive that same store.
Identity supplied by a component package. Provenance describes code that produced fitted state; it does not grant artifact serialization support.
val provenance :
package:string ->
version:string ->
implementation:string ->
(provenance, Error.t) resultval provenance_package : provenance -> stringval provenance_version : provenance -> stringval provenance_implementation : provenance -> stringPortable_artifact identifies built-in portable data-only codecs. External_artifact identifies an explicitly attached external codec whose payload validation, runtime dependencies, and trust policy belong to its package. Unsupported means no artifact codec is attached.
type component_report = {component_name : string;provenance : provenance option;serialization_support : serialization_support;
}Artifact support and optional producer identity for one fitted component.
val metadata_transformer :
?provenance:provenance ->
name:string ->
(module METADATA_TRANSFORMER
with type fitted = 'fitted
and type rng = Rng.t
and type t = 'specification
and type target = unit) ->
'specification ->
(transformer, Error.t) resultPackages per-method requests from the specification once. Fit validates both the fit request and the training transform request. No artifact codec is supplied for this adapter.
val transformer :
?route_sample_weight:bool ->
?provenance:provenance ->
name:string ->
(module TRANSFORMER
with type fitted = 'fitted
and type rng = Rng.t
and type t = 'specification
and type target = unit) ->
'specification ->
(transformer, Error.t) resultPackages an unsupervised transformer specification as a named stage. Sample weights reach the stage's fit only when route_sample_weight is true; by default the stage fits unweighted, matching transformers that declare no weight support.
val cacheable_transformer :
?route_sample_weight:bool ->
?provenance:provenance ->
name:string ->
(module Transform_cache.CACHEABLE_TRANSFORMER
with type fitted = 'fitted
and type params = 'params
and type rng = Rng.t
and type t = 'specification
and type target = unit) ->
'specification ->
(transformer, Error.t) resultPackages a stage with an explicit stable fitted-state cache codec. A cache hit restores fitted state and transforms the current training matrix; it does not cache terminal estimators or transformed matrices.
val metadata_estimator :
?provenance:provenance ->
name:string ->
(module METADATA_ESTIMATOR
with type fitted = 'fitted
and type prediction = 'prediction
and type rng = Rng.t
and type t = 'specification
and type target = 'target) ->
?decision_function:
('fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Vector.t, Error.t) result) ->
?predict_proba:
('fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Matrix.t, Error.t) result) ->
?classes:('fitted -> int array) ->
'specification ->
(('target, 'prediction) estimator, Error.t) resultPackages a terminal fit request and optional prediction capabilities. Weight delivery follows that request; class-weight resolution, when needed, belongs to the consumer. No artifact codec is supplied.
val estimator :
?provenance:provenance ->
name:string ->
(module ESTIMATOR
with type fitted = 'fitted
and type prediction = 'prediction
and type rng = Rng.t
and type t = 'specification
and type target = 'target) ->
?decision_function:
('fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Vector.t, Error.t) result) ->
?predict_proba:
('fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Matrix.t, Error.t) result) ->
?classes:('fitted -> int array) ->
'specification ->
(('target, 'prediction) estimator, Error.t) resultPackages a terminal estimator and its explicitly supported capabilities. When supplied, classes declares the class label corresponding to each predict_proba column.
val classifier :
?class_weight:Class_weight.t ->
?provenance:provenance ->
name:string ->
(module ESTIMATOR
with type fitted = 'fitted
and type prediction = 'prediction
and type rng = Rng.t
and type t = 'specification
and type target = Target.classification Target.t) ->
?decision_function:
('fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Vector.t, Error.t) result) ->
?predict_proba:
('fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Matrix.t, Error.t) result) ->
?classes:('fitted -> int array) ->
'specification ->
((Target.classification Target.t, 'prediction) estimator, Error.t) resultPackages a classification terminal like estimator and, when class_weight is supplied, resolves it on each fit's own labels and sample weights before the estimator sees them.
val empty : builderval add_transformer : builder -> transformer -> (builder, Error.t) resultmodule Supervised : sig ... endval with_cache :
('target, 'prediction) t ->
Transform_cache.Store.t ->
('target, 'prediction) tReturns a specification whose cacheable transformer stages reuse the explicitly scoped store. Keys cover ordered feature schema and values, targets for supervised stages, routed sample weights, configuration, and logical stage seed. Nested unsupported leaves fail before fitting begins. CV and search clones retain the store and derive schedule-independent keys from logical work identities.
val cache_enabled : ('target, 'prediction) t -> boolval transformer_names : ('target, 'prediction) t -> string arrayval estimator_name : ('target, 'prediction) t -> stringval capabilities : ('target, 'prediction) t -> capabilitiesval artifact_report : ('target, 'prediction) fitted -> artifact_reportReports component provenance and whether every fitted component has a attached artifact codec, distinguishing built-in portable and external support. An unsupported component may still be fitted and used normally; artifact encoding returns a typed error.
val artifact_transformers : artifact_report -> component_report arrayval artifact_estimator : artifact_report -> component_reportval portable_artifact_supported : artifact_report -> boolval artifact_supported : artifact_report -> boolTrue when every component has an attached codec, including explicitly selected external codecs. portable_artifact_supported accepts only built-in portable codecs.
val fit_with_metadata :
('target, 'prediction) t ->
metadata:Metadata.t ->
rng:Rng.t ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
y:'target ->
unit ->
(('target, 'prediction) fitted, Error.t) resultMetadata-aware operations validate all supplied row lengths and all declared requests before any consumer runs. Fit preflight includes the transforms of training rows. Requests are structural: configured children are checked even when a column selection later proves empty. Metadata remains row-aligned through feature transformations; values are neither transformed nor implicitly reused from fitting. Existing operations use absent metadata, apart from the legacy fit's optional sample weights. CV and search can select these inputs from their metadata carrier.
val transform_with_metadata :
('target, 'prediction) fitted ->
metadata:Metadata.t ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Matrix.t, Error.t) resultval predict_with_metadata :
('target, 'prediction) fitted ->
metadata:Metadata.t ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
('prediction, Error.t) resultval decision_function_with_metadata :
('target, 'prediction) fitted ->
metadata:Metadata.t ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Vector.t, Error.t) resultval predict_proba_with_metadata :
('target, 'prediction) fitted ->
metadata:Metadata.t ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Matrix.t, Error.t) resultval fit :
('target, 'prediction) t ->
?sample_weight:Sample_weight.t ->
rng:Rng.t ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
y:'target ->
unit ->
(('target, 'prediction) fitted, Error.t) resultval predict :
('target, 'prediction) fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
('prediction, Error.t) resultReturns the probability-column class order declared by the terminal estimator.
val input_schema : ('target, 'prediction) fitted -> Feature_schema.tval output_schema : ('target, 'prediction) fitted -> Feature_schema.t