Skip to content

Conversation

@hagenw
Copy link
Member

@hagenw hagenw commented Nov 10, 2025

Add support to select a different metric for calculating the confusion matrix in audplot.confusion_matrix(). This will allow us to easily plot results of other algorithms, e.g. audmetric.event_confusion_matrix() as introduced in audeering/audmetric#77

image

Summary by Sourcery

Add a metric argument to confusion_matrix() for using alternative metrics instead of the default audmetric.confusion_matrix

New Features:

  • Allow passing a custom metric callable to confusion_matrix() to compute the matrix

Enhancements:

  • Update docstring to describe the new metric parameter

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 10, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The change introduces a new metric argument to audplot.confusion_matrix, updating its signature and documentation, and uses the provided metric callable instead of hardcoding audmetric.confusion_matrix.

Sequence diagram for metric argument usage in confusion_matrix()

sequenceDiagram
participant User
participant confusion_matrix
participant MetricFunction
User->>confusion_matrix: Call confusion_matrix(truth, prediction, metric=custom_metric)
confusion_matrix->>MetricFunction: metric(truth, prediction, labels, normalize)
MetricFunction-->>confusion_matrix: Return confusion matrix
confusion_matrix-->>User: Return plot
Loading

Class diagram for updated confusion_matrix() function

classDiagram
class confusion_matrix {
    +labels: Sequence = None
    +label_aliases: dict = None
    +metric: Callable = audmetric.confusion_matrix
    +percentage: bool = False
    +show_both: bool = False
    +ax: matplotlib.axes.Axes = None
    +figsize: tuple = None
    +font_size: int = None
    +cmap: str = None
    +vmin: float = None
    +vmax: float = None
    +title: str = None
    +xlabel: str = None
    +ylabel: str = None
    +xtick_rotation: int = None
    +ytick_rotation: int = None
    +colorbar: bool = True
    +kwargs
    +confusion_matrix(truth, prediction, labels, label_aliases, metric, percentage, show_both, ax, ...)
}
confusion_matrix --> "metric: Callable" MetricFunction
Loading

File-Level Changes

Change Details Files
Support custom metric in confusion_matrix
  • Added metric parameter to function signature with default audmetric.confusion_matrix
  • Documented metric parameter in the docstring with expected arguments
  • Replaced direct calls to audmetric.confusion_matrix with the metric callable
audplot/core/api.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `audplot/core/api.py:178` </location>
<code_context>
         labels = audmetric.utils.infer_labels(truth, prediction)

-    cm = audmetric.confusion_matrix(
+    cm = metric(
         truth,
         prediction,
</code_context>

<issue_to_address>
**issue:** Passing None for normalize may not be supported by all metric callables.

Custom metric functions may not accept None for the normalize argument. Please standardize this value or document the requirement for custom metrics to handle None appropriately.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (6af2b71) to head (e6ed93d).

Additional details and impacted files
Files with missing lines Coverage Δ
audplot/core/api.py 100.0% <100.0%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants