Skip to content

Feature Request: bias regression metric  #17854

Closed

Description

@raybellwaves

Following on from #17853

I'm interested in the mean distribution of the error which i'm calling bias (over or under predicting).
I can do this as a one liner in numpy (np.average(y_pred - y_true)) but I would prefer to stay in scikit-learn.

Describe the workflow you want to enable

bias(y_true, y_pred)

Describe your proposed solution

It has mostly been implemented in https://github.com/scikit-learn/scikit-learn/blob/fd237278e/sklearn/metrics/_regression.py#L181

Would just have to adjust

    output_errors = np.average(np.abs(y_pred - y_true),
                               weights=sample_weight, axis=0)

to

    output_errors = np.average(y_pred - y_true,
                               weights=sample_weight, axis=0)

Describe alternatives you've considered, if relevant

Additional context

Discussion of whether this is an error metric or not at #17853 (comment)

Activity

  1. NicolasHug commented on Jul 6, 2020

    @NicolasHug
    Member

    Sorry @raybellwaves I don't really understand how this proposal differs from #17853?

    I would prefer to stay in scikit-learn

    Why? You're using numpy already if you're using scikit-learn

  2. raybellwaves commented on Jul 6, 2020

    @raybellwaves
    ContributorAuthor

    Sorry @raybellwaves I don't really understand how this proposal differs from #17853?

    It doesn't. I agree with the comment that it wouldn't make sense using an existing function and adding another keyword that doesn't align with the function. I probably should have changed the title of that issue rather than open a new one.

    Why? You're using numpy already if you're using scikit-learn

    I guess I would prefer a function that has been unit tested (in scikit-learn) rather than a custom function. However, I understand you have to draw a line somewhere with regards to custom metrics.

  3. adrinjalali commented on Jul 9, 2020

    @adrinjalali
    Member

    On one side, I think bias is a well established enough term for it to be included as a metric. On the other side, optimizing on bias is not something which we usually do when we search in the hyper parameter space.

    Our GS can now handle multiple metrics easily and choose the best estimator based on a combination of them, so I guess it wouldn't be too bad to have bias as a metric?

  4. Kshitij68 commented on Oct 15, 2022

    @Kshitij68
    Contributor

    Hi @lorentzenchr

    Personally I +1 the comment by @thomasjpfan in #17853 that this isn't a good metric.
    Has there been consensus on whether it is desired to be introduced in scikit-learn or not?

  5. lorentzenchr commented on Oct 15, 2022

    @lorentzenchr
    Member

    First of all, a one liner like np.average(y_pred - y_true) is not a good fit for inclusion. This one liner will need tests and documentation, thus a lot of maintenance burden. And in users' code, it will replace a one liner by another one liner. So where is the point? Therefore, I'm -1.

    The other point is that, in my opinion, assessing bias or calibration is a very important topic for ML models, but it seems a bad fit for the metrics module because there you typically have scores for model comparison. Scores have an ordering (e.g. larger is better). Calibration, in general, is different (e.g. sign sensitive) because you want to know if your model over- or underpredicts. Otherwise stated, scores can be optimised, calibration is more like the first order optimality condition (the derivative).

    Currently, we don't have good solutions to detect bias except for the reliability diagram/calibration curve for binary classification, further discussions e.g. in #18020.

    Again, in my opinion, something that would be a good fit for the metrics module is #23767.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions