package modelkit

  1. Overview
  2. Docs

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.

type transformer
type builder
type ('target, 'prediction) estimator
type ('target, 'prediction) t
type ('target, 'prediction) fitted
type capabilities = {
  1. decision_function : bool;
  2. predict_proba : bool;
}
type provenance

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) result
val provenance_package : provenance -> string
val provenance_version : provenance -> string
val provenance_implementation : provenance -> string
type serialization_support =
  1. | Portable_artifact
  2. | External_artifact
  3. | Unsupported

Portable_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 = {
  1. component_name : string;
  2. provenance : provenance option;
  3. serialization_support : serialization_support;
}

Artifact support and optional producer identity for one fitted component.

type artifact_report
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) result

Packages 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) result

Packages 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) result

Packages 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) result

Packages 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) result

Packages 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) result

Packages 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 : builder
val add_transformer : builder -> transformer -> (builder, Error.t) result
val set_estimator : builder -> ('target, 'prediction) estimator -> (('target, 'prediction) t, Error.t) result
module Supervised : sig ... end
val clone : ('target, 'prediction) t -> ('target, 'prediction) t
val with_cache : ('target, 'prediction) t -> Transform_cache.Store.t -> ('target, 'prediction) t

Returns 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 without_cache : ('target, 'prediction) t -> ('target, 'prediction) t
val cache_enabled : ('target, 'prediction) t -> bool
val transformer_names : ('target, 'prediction) t -> string array
val estimator_name : ('target, 'prediction) t -> string
val capabilities : ('target, 'prediction) t -> capabilities
val artifact_report : ('target, 'prediction) fitted -> artifact_report

Reports 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 array
val artifact_estimator : artifact_report -> component_report
val portable_artifact_supported : artifact_report -> bool
val artifact_supported : artifact_report -> bool

True 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) result

Metadata-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) result
val predict_with_metadata : ('target, 'prediction) fitted -> metadata:Metadata.t -> feature_schema:Feature_schema.t -> x:Matrix.t -> ('prediction, Error.t) result
val decision_function_with_metadata : ('target, 'prediction) fitted -> metadata:Metadata.t -> feature_schema:Feature_schema.t -> x:Matrix.t -> (Vector.t, Error.t) result
val predict_proba_with_metadata : ('target, 'prediction) fitted -> metadata:Metadata.t -> feature_schema:Feature_schema.t -> x:Matrix.t -> (Matrix.t, Error.t) result
val 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) result
val transform : ('target, 'prediction) fitted -> feature_schema:Feature_schema.t -> x:Matrix.t -> (Matrix.t, Error.t) result
val predict : ('target, 'prediction) fitted -> feature_schema:Feature_schema.t -> x:Matrix.t -> ('prediction, Error.t) result
val decision_function : ('target, 'prediction) fitted -> feature_schema:Feature_schema.t -> x:Matrix.t -> (Vector.t, Error.t) result
val predict_proba : ('target, 'prediction) fitted -> feature_schema:Feature_schema.t -> x:Matrix.t -> (Matrix.t, Error.t) result
val classes : ('target, 'prediction) fitted -> (int array, Error.t) result

Returns the probability-column class order declared by the terminal estimator.

val input_schema : ('target, 'prediction) fitted -> Feature_schema.t
val output_schema : ('target, 'prediction) fitted -> Feature_schema.t