Fitted binary logistic regression
Fit class probabilities and labels, keep row identities, and evaluate grouped holdouts using log loss.
ImplementedAner 0.1.0 or newerAner 0.0.8 adds fitted binary logistic regression for an
AdaptiveFrame with a dimensionless target. Target values
must be exactly 0 or 1, and both classes must occur in training. A
validation or test view may contain a single class. Missing inputs and
required targets are rejected.
Run the synthetic device alert example from the source root.
aner check examples/logistic_alerts.aner
aner run examples/logistic_alerts.anerAfter assigning whole groups to training and holdout populations, the same plan can be used for cross validation and a final fit.
let plan = ml.logistic(alpha: 0.5)
let errors = plan.cross_validate(parts.train(), folds: 2, seed: 42)
let model = plan.fit(parts.train())
print(model.converged())
print(model.evaluate(parts.test()))| Operation | Behavior |
|---|---|
ml.logistic(alpha: 1.0, standardize: true, max_iterations: 100, tolerance: 1e-8) | Creates an immutable LogisticPlan. Supply any named setting on its own. |
plan.fit(training, max_bytes: 67108864, workers: 0) | Returns an immutable FittedLogistic from a protected training view. |
plan.cross_validate(training, folds: 5, seed: 42, workers: 0) | Returns mean log loss for each fold in order. Each fold fits its own scaling. |
model.predict_proba(observations) | Returns a ContextPrediction with one probability of class 1 per row. Values are dimensionless and retain observation IDs. |
model.predict(observations) | Returns contextual labels 0 or 1. A decision score of zero belongs to class 1. |
model.evaluate(held_out) | Returns mean log loss for a labeled, nonempty validation or test view in the fitted experiment. |
model.align_inputs(observations, columns) | Maps independent unlabeled observations into fitted feature order, applying compatible unit conversions. |
model.coefficients(), model.intercept() | Inspect weights and intercept in fitted coordinates. |
model.center(), model.scale() | Inspect fitted feature centers and scales. |
model.converged(), model.iterations(), model.summary() | Inspect convergence, completed updates, and fitting details. |
model.save(path), ml.load_logistic(path, training_anchor[, max_bytes, workers]) | Save to a new file and verify the model by refitting the matching trusted training view with the saved solver. |
The fitting objective is the sum of binary log losses plus
alpha / 2 times the sum of squared feature weights. The intercept is
unpenalized. Alpha must be finite and positive. With standardization enabled,
the plan learns population means and standard deviations from training only.
Constant features use scale one. With scaling disabled, centers are zero and
scales are one. The held out score is the mean log loss without the penalty.
Fit runs on CPU Float64 with damped Newton updates and a bounded Hessian
workspace. The solver checks the largest absolute component of the
objective gradient divided by the number of training rows. Tolerance
must be finite and in (0, 1]. The iteration limit is between 1 and 10,000.
A fit that reaches its stopping limit can return a model with
converged() == false. Cross validation rejects an unconverged fold.
Cross validation uses between two and 32 folds, with at least one whole group per fold. The seed breaks ties between groups of equal size during assignment. Use raw training inputs so each fold learns its own preprocessing. Each inner training split must contain both classes. Keep the outer test set for the final evaluation.
The feature reader works with resident and spilled tables. Eligible fits
reuse a temporary packed feature cache when it fits within max_bytes.
Other fits stream rows through bounded scratch space. The budget covers the
cache, managed numerical allocations, and fitted membership. Existing table
storage, frame and fold metadata, provider internals, thread stacks, and
allocator overhead sit outside that budget. AdaptiveFrame size limits apply.
workers: 0 selects workers automatically from the available CPU allocation
and the amount of work. workers: 1 requests serial execution. A higher value
caps concurrent Aner workers on the cached path. The streaming path uses one
Aner worker, with provider managed threads governed by the numerical backend.
Cached fits merge fixed row chunks in order, which preserves their
reduction order across worker counts. Folds run sequentially. The fitted
summary reports cache bytes, managed peak bytes, and the effective worker
count. Reload uses the recorded solver and needs enough budget for that
solver's workspace and any required input cache.
On the cached path, a full Newton trial computes its loss and derivatives in one pass. An accepted trial reuses those derivatives for the next update. Backtracking still checks the loss before accepting a shorter step. A full trial that meets the gradient tolerance may accept a loss difference within floating point roundoff.
See the Machine learning module reference for the shared API.