Repository navigation
Description
Split out from #408, which is now fixed for the regularization half.
Background
#408 found the canonical benchmark was passing penalty_l2(0.001) flat while sklearn used C=1.0. The correct mapping is alpha = 1/(C * n_samples), so the old constant was 8.3x too weak on iris and 1.4x too strong on digits. PR #430 fixed that with penalty_l2_from_c(C, n_samples).
With regularization now equal, a structural difference is visible that the mismatched alpha had been partly masking:
| row | Flow | sklearn |
|---|---|---|
| iris accuracy | 0.899999976 | 0.933333333 |
iris coef_frobenius_norm |
4.937423 | 4.517331 |
| digits accuracy | 0.969444454 | 0.972222222 |
digits coef_frobenius_norm |
15.171825 | 10.364157 |
sklearn fits one multinomial softmax; flow-scikit fits one-vs-rest. On iris the entire accuracy difference is one test sample of thirty: at equal regularization OvR gets 27 and multinomial gets 28.
Consequence right now
The iris score gap is 0.0333 against a score_abs_tolerance of 0.02, so the row reclassifies to not parity verified, the canonical count drops from 19/19 to 18/19, and publish_headline_v2.py refuses to publish. That was an accepted, deliberate tradeoff: the benchmark is now honest and the claim is temporarily lower, rather than the claim being propped up by comparing differently-regularized models.
What would fix it
Implement multinomial (softmax) logistic regression and use it for the multiclass case, matching sklearn's default. The objective is the cross-entropy over a softmax across all classes fitted jointly, rather than K independent binary fits combined afterwards.
Notes for whoever takes it:
multiclass_logistic_fit/multiclass_logistic_decidealready exist inlib/scikit/linear.flow; check whether that path is OvR too, and whether the benchmark uses it.- The penalty convention established by fix: match sklearn's C=1.0 in the canonical LogisticRegression benchmark (#408) #430 must carry over: Flow minimises the mean loss plus
0.5 * alpha * ||w||^2, soalpha = 1/(C * n_samples)remains the mapping. - sklearn does not penalize the intercept. Flow already does not; keep it that way.
- Softmax is numerically delicate. Subtract the row max before exponentiating. Note Flow's constraint against inline
exp()in a nested while loop, recorded in AGENTS.md. - Both canonical LogisticRegression rows will move. Report before and after prominently rather than burying it, and state the effect on the 18/19 count.
Restoring 19/19
If multinomial closes iris to within 0.02, the row returns to eligible and the count goes back to 19/19 on honest terms. If it does not, the remaining difference should be recorded in parity_contract.json as a declared semantic difference with the measurement attached, in the same style as the KMeans work in #203, rather than by widening a tolerance.
Activity
godofecht commentedon Aug 19, 2026
Multinomial closes it. Measured, not predicted.
Implemented multinomial softmax in
logistic_regression_fitand routednc > 2through it. The binary path is untouched. Objective is the mean cross-entropy of the softmax over all classes fitted jointly, plus0.5 * alpha * ||W||^2summed over the class weight rows, intercepts unpenalized, sopenalty_l2_from_c(C, m)from #430 carries over with no change.Canonical benchmark, single run, macOS,
FLOW_OPT_LEVEL=0,-framework Accelerate:Both are inside
score_abs_tolerance0.02. iris was 0.0333 outside.Coefficient diagnostics moved the same way:
coef_frobenius_normcoef_frobenius_norminterceptsThe intercepts are the clearest signal that the two models are now the same object. One-vs-rest pushed every intercept far negative because each binary subproblem sees a 1:2 class imbalance; the joint softmax does not.
Diffed every
RESULT|andDETAIL|record betweenorigin/mainand the branch: 165 records, keys identical, 10 differ, and all 10 are the two LogisticRegression rows and their details. The other 17 canonical rows are byte-identical.Cost: iris fit 0.077 ms -> 0.139 ms, digits fit 17.25 ms -> 25.97 ms. The joint problem is one LBFGS over
nc * (n + 1)parameters instead ofncindependent ones overn + 1, and on digits it runs to the 100-iteration cap where the OvR subproblems converged earlier.PR to follow.
godofecht commentedon Aug 19, 2026
State of
mainright now, and a baseline subtlety worth not forgettingAfter #430 merged,
main'sRemaining issue implementationworkflow fails, exactly as predicted and accepted:Two things to note.
Only iris breaks eligibility. The digits gap of 0.00277777 is well inside its
score_abs_toleranceof 0.02. It is flagged because the disparity gate compares against the frozen baseline, not because the row fails parity. So the canonical count is 18/19, not 17/19.The word "regressed" is misleading here, and the baseline is the reason. That baseline was frozen while the benchmark was comparing a Flow model at
alpha = 0.001against a sklearn model atC = 1.0, which on iris is 8.3x weaker regularization. The old4e-09agreement was an artifact of two differently-regularized models happening to land on the same accuracy, not evidence of parity. The new numbers are the first honest measurement of this row.Consequence for whoever finishes this issue: once multinomial lands,
disparity_history.jsonstill holds a snapshot taken under the mismatched-alpha benchmark. Comparing against it will keep producing spurious regression lines for these two rows even after the gap closes. The baseline needs re-freezing onmainafter the fix, and it is worth saying in that PR that the pre-#430 snapshot is not a valid comparison point for LogisticRegression.This is the same class of problem #425 addressed for the published page: a ratio or a delta measured against a baseline taken under different conditions is not a measurement of change. Here the conditions were a benchmark bug rather than a machine change.