package modelkit
Build not checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=7a7af032790248b5d1d5392bbf29f8c8163df2e7f50ab5801cdaed5fd2c543e1
sha512=185bc224afc9b141d54b89a564694438a268429ba9c58dd3a402da31cb29f3e1eefd3643a76766ce9170c5f6c927f307873d51e4e3ce08aece00884cebbe0e2a
doc/modelkit/Modelkit/Sgd_classifier/index.html
Module Modelkit.Sgd_classifier
Incremental linear classification trained by stochastic gradient descent.
Penalties, learning-rate schedules, stopping reasons, batch semantics, and checkpoint immutability follow Sgd_regressor; the shared variant types are re-exported so schedule values interoperate. start additionally registers the complete class set for the stream: labels are sorted into ascending order, must be distinct, and must number at least two. Every positively weighted row of a later batch must carry a registered class or partial_fit returns a typed validation error; zero-weight rows are never inspected because they cannot change the parameters. fit registers the positively weighted classes of its single matrix, matching the other built-in classifiers.
Two registered classes train one model whose positive class is the higher label; three or more train one one-versus-rest model per ascending class. All models share the update counter, learning rate, and per-batch permutation, and each row updates every model before the counter advances. Hinge uses the margin loss max 0 (1 - y * score) with y in -1, +1; Log_loss uses the stable binomial deviance with gradient sigmoid score - y for y in 0, 1. Sample weights scale the loss gradient without normalizing individual updates; intercepts are never penalized. The reported objective is the weighted mean over rows of the summed per-model loss plus the declared penalty over all coefficient rows.
Sgd_classifier.coefficients has one row for binary problems and one row per class otherwise, and Sgd_classifier.decision_function returns one column per model in the same order. Binary prediction selects the higher class when its score is strictly positive; multiclass prediction takes the first maximum score, so exact ties select the lowest label. Sgd_classifier.binary_decision_function exposes the single binary score column as a vector for pipeline dispatch and returns a typed compatibility error for multiclass models. Sgd_classifier.predict_proba is available only for Log_loss: binary probabilities are the sigmoid of the score and its complement, and multiclass probabilities normalize the one-versus-rest sigmoids, becoming uniform when every sigmoid underflows.
One batch costs O(n * m * p) time and O(n + m * p) temporary storage for n samples, m models, and p features. Checkpoints and fitted values store O(m * p) data and are in-memory training state, not a persistent artifact format.
type learning_rate = Sgd_regressor.learning_rate = type report = {converged : bool;batches_processed : int;updates : int;objective : float;stopping_reason : stopping_reason;
}type params = {loss : loss;penalty : penalty;alpha : float;l1_ratio : float;fit_intercept : bool;learning_rate : learning_rate;eta0 : float;max_epochs : int;tolerance : float option;shuffle : bool;
}val start :
t ->
rng:Rng.t ->
feature_schema:Feature_schema.t ->
classes:int array ->
(checkpoint, Error.t) resultRegisters the distinct class labels and starts a zero-initialized checkpoint without consuming the RNG.
val partial_fit :
checkpoint ->
?sample_weight:Sample_weight.t ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
y:Target.classification Target.t ->
unit ->
(checkpoint, Error.t) resultval to_fitted : checkpoint -> (fitted, Error.t) resultReturns a prediction-ready snapshot after at least one batch.
val checkpoint : fitted -> checkpointReturns an independent checkpoint suitable for further training.
val checkpoint_classes : checkpoint -> int arrayval checkpoint_updates : checkpoint -> intval checkpoint_batches_processed : checkpoint -> intval classes : fitted -> int arrayReturns the registered labels in ascending order.
Returns a 1 * features matrix for two classes and a classes * features matrix in classes order otherwise.
val decision_function :
fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Matrix.t, Error.t) resultReturns one score column per model: a single column for two classes and one column per ascending class otherwise.
val predict_proba :
fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(Matrix.t, Error.t) resultReturns a samples * classes matrix for Log_loss and a typed compatibility error for Hinge.
include CLASSIFIER
with type t := t
and type params := params
and type fitted := fitted
and type rng = Rng.t
include ESTIMATOR
with type target = Target.classification Target.t
and type prediction = Target.classification Target.t
with type t := t
with type params := params
with type fitted := fitted
with type rng = Rng.t
type target = Target.classification Target.ttype prediction = Target.classification Target.ttype rng = Rng.tval fit :
t ->
?sample_weight:Sample_weight.t ->
rng:rng ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
y:target ->
unit ->
(fitted, Error.t) resultval predict :
fitted ->
feature_schema:Feature_schema.t ->
x:Matrix.t ->
(prediction, Error.t) resultval feature_schema : fitted -> Feature_schema.t