Skip to content

Commit dedc587

Browse files
ENH add np.nan option for zero_division in precision/recall/f-score (scikit-learn#25531)
Co-authored-by: Guillaume Lemaitre <[email protected]>
1 parent 3043ea6 commit dedc587

File tree

4 files changed

+263
-92
lines changed

4 files changed

+263
-92
lines changed

doc/whats_new/v1.3.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Changelog
163163

164164
- |API| The `sample_weight` parameter in `predict` for
165165
:meth:`cluster.KMeans.predict` and :meth:`cluster.MiniBatchKMeans.predict`
166-
is now deprecated and will be removed in v1.5.
166+
is now deprecated and will be removed in v1.5.
167167
:pr:`25251` by :user:`Gleb Levitski <glevv>`.
168168

169169
- |Enhancement| The `sample_weight` parameter now will be used in centroids
@@ -279,9 +279,23 @@ Changelog
279279
:user:`Guillaume Lemaitre <glemaitre>`, :user:`Omar Salman <OmarManzoor>` and
280280
:user:`Jérémie du Boisberranger <jeremiedbb>`.
281281

282+
- |Feature| Adds `zero_division=np.nan` to multiple classification metrics:
283+
:func:`precision_score`, :func:`recall_score`, :func:`f1_score`,
284+
:func:`fbeta_score`, :func:`precision_recall_fscore_support`,
285+
:func:`classification_report`. When `zero_division=np.nan` and there is a
286+
zero division, the metric is undefined and is excluded from averaging. When not used
287+
for averages, the value returned is `np.nan`.
288+
:pr:`25531` by :user:`Marc Torrellas Socastro <marctorsoc>`.
289+
282290
- |Fix| :func:`metric.manhattan_distances` now supports readonly sparse datasets.
283291
:pr:`25432` by :user:`Julien Jerphanion <jjerphan>`.
284292

293+
- |Fix| Fixed :func:`classification_report` so that empty input will return
294+
`np.nan`. Previously, "macro avg" and `weighted avg` would return
295+
e.g. `f1-score=np.nan` and `f1-score=0.0`, being inconsistent. Now, they
296+
both return `np.nan`.
297+
:pr:`25531` by :user:`Marc Torrellas Socastro <marctorsoc>`.
298+
285299
- |Enhancement| :class:`metrics.silhouette_samples` nows accepts a sparse
286300
matrix of pairwise distances between samples, or a feature array.
287301
:pr:`18723` by :user:`Sahil Gupta <sahilgupta2105>` and

0 commit comments

Comments
 (0)