Skip to content

linfa-logistic: labels are not Ord ordered, 'neg' is the one first found in data during training #393

Open
@ilautar

Description

@ilautar

Hey,

I'm using linfa-logistic for pet project. I needed some predictions and run into weird problem, where model.predict_probabilities(&input) would give reversed order.

So I was looking into it, also reading code. The documentation says that neg and pos classes are defined depending on Ord of class values, BUT actually they are defined on Ord of count(*) of particular class in data set (ie., larger class is always pos).

This was confusing as heck for me, but I'm not a ML expert (so it might be usual way). Anyhow, I used this workaround to always get probabilities for specific class (I'm using 1 & -1 as targets):

`

        let prob = model.predict_probabilities(&features);
        let labels = model.labels();
        if labels.neg.class == 1 {
            return Some(prob.into_iter().map(|p| 1.0 - p).collect_vec());
        }

        Some(prob.into_iter().collect_vec())

`

Is this a bug or intended? At least this should be documented and (ideally) allow lib users to fix-classes (regardless of input dataset sizes) so that predict_probabilities is stable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions