Skip to content

FEA Add d2_log_loss_score - #28351

Merged
jeremiedbb merged 16 commits into
scikit-learn:mainfrom
OmarManzoor:d2_log_loss
May 2, 2024
Merged

jeremiedbb merged 16 commits into
scikit-learn:mainfrom
OmarManzoor:d2_log_loss

Conversation

@OmarManzoor

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes: #20943

What does this implement/fix? Explain your changes.

  • Adds d2_log_loss_score

Any other comments?

@github-actions

github-actions Bot commented Feb 2, 2024 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 1dd08df. Link to the linter CI: here

@OmarManzoor

Copy link
Copy Markdown
Contributor Author

@lorentzenchr Could you kindly have a look to see if this formulation looks okay? If this looks correct then we can add the general case which handles more than one class and also all the corresponding things required like the addition of documentation, more tests etc. step by step.

@lorentzenchr lorentzenchr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This goes in the right direction.

Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
@OmarManzoor
OmarManzoor marked this pull request as ready for review February 12, 2024 09:45
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Resolved

@lorentzenchr lorentzenchr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Close to finish.

Comment thread doc/modules/model_evaluation.rst Resolved
Comment thread doc/whats_new/v1.5.rst Resolved
Comment thread sklearn/metrics/_classification.py Resolved
@OmarManzoor

Copy link
Copy Markdown
Contributor Author

@lorentzenchr Would it make sense to include this in 1.5?

@lorentzenchr lorentzenchr added this to the 1.5 milestone Apr 30, 2024

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, just a few minor comments.

Comment thread sklearn/metrics/_classification.py Outdated
Comment on lines +3361 to +3364
if sample_weight is not None:
weights = np.asarray(sample_weight)
else:
weights = np.ones(shape=len(y_true), dtype=np.int64)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if sample_weight is not None:
weights = np.asarray(sample_weight)
else:
weights = np.ones(shape=len(y_true), dtype=np.int64)
weights = _check_sample_weight(sample_weight, y_true)

Comment on lines +2833 to +2840
The :func:`d2_log_loss_score` function implements the special case
of D² with the log loss, see :ref:`log_loss`, i.e.:

.. math::

\text{dev}(y, \hat{y}) = \text{log_loss}(y, \hat{y}).

Here are some usage examples of the :func:`d2_log_loss_score` function::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please mention that the y_null for the log loss is the per-class frequency, here or in the introdction paragraph above where the y_null for other losses are described.

Comment thread sklearn/metrics/_classification.py Resolved
Comment thread sklearn/metrics/_classification.py Outdated
y_true : array-like or label indicator matrix
The actuals labels for the n_samples samples.

y_pred : array-like of float, shape = (n_samples, n_classes) or (n_samples,)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
y_pred : array-like of float, shape = (n_samples, n_classes) or (n_samples,)
y_pred : array-like of shape (n_samples, n_classes) or (n_samples,)

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks @OmarManzoor

@jeremiedbb
jeremiedbb enabled auto-merge (squash) May 2, 2024 13:50
|details-end|

|details-start|
**D² log loss score**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is under „regression metrics“ but it’s a classification metric. Wen can fix that in another PR as it involves a larger change of the user guide.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Haha you spot it as well. I assumed I would just merge it discretly and open an issue right after 😄

@jeremiedbb
jeremiedbb merged commit 8d89e8d into scikit-learn:main May 2, 2024
@OmarManzoor
OmarManzoor deleted the d2_log_loss branch May 2, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more D2 scores

3 participants