Skip to content

Multinomial softmax parameters are unidentified up to a per-class shift; sklearn centres them, Flow does not #470

Description

@godofecht

From the substantive-disparity survey. LogisticRegression/digits shows intercepts_max_relative_diff = 0.508 and coef_row_l2_norms_max_relative_diff = 0.0125 even though accuracy matches sklearn within 3e-3 and #434 matched the objective.

Softmax is invariant to adding a constant vector to all class scores: (W, b) and (W + c·1ᵀ, b + d) produce identical probabilities. The parameters are only identified up to that shift. sklearn's multinomial fit centres coefficients and intercepts to sum to zero across classes; Flow reports the raw optimum its LBFGS landed on.

So the reported state difference is (at least partly) a parameterization artifact, not a model difference. Fix: centre Flow's multinomial coefficients and intercepts (subtract the class-mean from each feature column and from the intercept vector) at the end of lin433_multinomial_fit. Predictions and probabilities are mathematically invariant — verify bit-level effect on canonical rows and report; if predictions move in the last ulp from the arithmetic, report exactly which records.

iris shows the same pattern smaller (intercepts_max_relative_diff 0.0009).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions