Skip to content

classification performance measures #1577

Open

Description

@jseabold

Add classification performance statistics

def precision(pred_table):
    """
    Precision given pred_table. Binary classification only. Assumes group 0
    is the True.

    Analagous to (absence of) Type I errors. Probability that a randomly
    selected document is classified correctly. I.e., no false negatives.
    """
    tp, fp, fn, tn = map(float, pred_table.flatten())
    return tp / (tp + fp)


def recall(pred_table):
    """
    Precision given pred_table. Binary classification only. Assumes group 0
    is the True.

    Analagous to (absence of) Type II errors. Out of all the ones that are
    true, how many did you predict as true. I.e., no false positives.
    """
    tp, fp, fn, tn = map(float, pred_table.flatten())
    try:
        return tp / (tp + fn)
    except ZeroDivisionError:
        return np.nan


def accuracy(pred_table):
    """
    Precision given pred_table. Binary classification only. Assumes group 0
    is the True.
    """
    tp, fp, fn, tn = map(float, pred_table.flatten())
    return (tp + tn) / (tp + tn + fp + fn)


def fscore_measure(pred_table, b=1):
    """
    For b, 1 = equal importance. 2 = recall is twice important. .5 recall is
    half as important, etc.
    """
    r = recall(pred_table)
    p = precision(pred_table)
    try:
        return (1 + b**2) * r*p/(b**2 * p + r)
    except ZeroDivisionError:
        return np.nan

Also missing ROC curve.

Activity

  1. added this to the 0.6 milestone on Apr 8, 2014
  2. added 2 commits that reference this issue on Apr 30, 2014
    909618a
    4089579
  3. modified the milestones: 0.6, 0.7 on Aug 16, 2014
  4. ysunmi0427 commented on Jan 26, 2020

    @ysunmi0427

    @jseabold I would like to work on this enhancement. Would you like to guide me to start working on this?

  5. rluedde commented on Jul 7, 2020

    @rluedde

    Correct me if I'm wrong but it looks like this has already been done? In file statsmodels/tools/eval_measures.py

    @ysunmi0427 Do you agree?

  6. anuragwatane commented on Feb 23, 2021

    @anuragwatane

    We would like to work on this issue.

  7. removed this from the 0.7 milestone on Apr 6, 2021
  8. jseabold commented on Apr 6, 2021

    @jseabold
    MemberAuthor

    If anyone would want to work on this, there is a start on a solution in #1650. Reading that would be a good place to start. That branch needs some tests and some small function API changes.

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