Repository navigation
Description
Found while implementing #433. Pre-existing on main, not introduced by that work.
Reproduction, verified
Perfectly separable binary problem, class 0 at x=-1 and class 1 at x=+1, fitted with logistic_regression_fit(X, y, 2, 300, 0.5, penalty_none()):
x=-1.000000 true=0.000000 proba=0.999940 decided=1.000000
x=-1.000000 true=0.000000 proba=0.999940 decided=1.000000
x=-1.000000 true=0.000000 proba=0.999940 decided=1.000000
x=1.000000 true=1.000000 proba=0.000060 decided=0.000000
x=1.000000 true=1.000000 proba=0.000060 decided=0.000000
x=1.000000 true=1.000000 proba=0.000060 decided=0.000000
correct: 0 of 6
Accuracy 0.0 on a problem a constant classifier gets 0.5 on.
The cause
The OvR training loop sets label = 1.0 when y[i] == classes[c], so for the binary case model.weights is the class-0 classifier and sigmoid(score) is P(class 0). That is consistent: proba is 0.99994 exactly where the true label is 0.
logistic_decide then does the opposite:
if probs[i] >= threshold {
labels[i] = model.classes[1]
} else {
labels[i] = model.classes[0]
}
High P(class 0) maps to classes[1]. The two functions disagree about which class the probability refers to.
Why this matters more than a normal bug
This is the exact API pair the project advertises as a deliberate design improvement over scikit-learn. From docs/design-rationale.md, position 4:
The
predictfunctions return probabilities. Thedecidefunctions take an explicit threshold.
The stated reason is that sklearn's hidden 0.5 threshold is opaque. So the headline API distinction is the one that is broken, and it is broken in the direction that silently produces confidently wrong labels rather than erroring.
Scope to check
logistic_predict(argmax over per-class scores) appears unaffected; the canonical benchmark uses that path, which is why this has not shown up in any row.sgd_classifier_decideandlinear_svc_decidehave the same shape atlinear.flow:1478-1480and insvm.flow. Check whether they share the defect before fixing only this one.pipeline_decidedelegates and would inherit it.- Whichever way it is fixed, decide which convention is correct first. sklearn's
predict_probareturns P(class 1) in column 1, so matching that means changinglogistic_predict_probato return P(class 1) and leavingdecidealone. Changingdecideinstead would leavepredict_probareturning P(class 0), which no caller would expect.
Test that should exist
The reproduction above, asserting accuracy on a separable problem is 1.0 rather than 0.0. Note a test that only checks predict would have passed throughout.
Activity
docs: state the binary predict_proba convention in design-rationale