@@ -2052,7 +2052,6 @@ def precision_recall_fscore_support(
2052
2052
"sample_weight" : ["array-like" , None ],
2053
2053
"raise_warning" : ["boolean" , Hidden (StrOptions ({"deprecated" }))],
2054
2054
"replace_undefined_by" : [
2055
- Hidden (StrOptions ({"default" })),
2056
2055
Options (Real , {1.0 , np .nan }),
2057
2056
dict ,
2058
2057
],
@@ -2066,7 +2065,7 @@ def class_likelihood_ratios(
2066
2065
labels = None ,
2067
2066
sample_weight = None ,
2068
2067
raise_warning = "deprecated" ,
2069
- replace_undefined_by = "default" ,
2068
+ replace_undefined_by = np . nan ,
2070
2069
):
2071
2070
"""Compute binary classification positive and negative likelihood ratios.
2072
2071
@@ -2178,35 +2177,29 @@ class are present in `y_true`): both likelihood ratios are undefined.
2178
2177
--------
2179
2178
>>> import numpy as np
2180
2179
>>> from sklearn.metrics import class_likelihood_ratios
2181
- >>> class_likelihood_ratios([0, 1, 0, 1, 0], [1, 1, 0, 0, 0],
2182
- ... replace_undefined_by=1.0)
2180
+ >>> class_likelihood_ratios([0, 1, 0, 1, 0], [1, 1, 0, 0, 0])
2183
2181
(1.5, 0.75)
2184
2182
>>> y_true = np.array(["non-cat", "cat", "non-cat", "cat", "non-cat"])
2185
2183
>>> y_pred = np.array(["cat", "cat", "non-cat", "non-cat", "non-cat"])
2186
- >>> class_likelihood_ratios(y_true, y_pred, replace_undefined_by=1.0 )
2184
+ >>> class_likelihood_ratios(y_true, y_pred)
2187
2185
(1.33, 0.66)
2188
2186
>>> y_true = np.array(["non-zebra", "zebra", "non-zebra", "zebra", "non-zebra"])
2189
2187
>>> y_pred = np.array(["zebra", "zebra", "non-zebra", "non-zebra", "non-zebra"])
2190
- >>> class_likelihood_ratios(y_true, y_pred, replace_undefined_by=1.0 )
2188
+ >>> class_likelihood_ratios(y_true, y_pred)
2191
2189
(1.5, 0.75)
2192
2190
2193
2191
To avoid ambiguities, use the notation `labels=[negative_class,
2194
2192
positive_class]`
2195
2193
2196
2194
>>> y_true = np.array(["non-cat", "cat", "non-cat", "cat", "non-cat"])
2197
2195
>>> y_pred = np.array(["cat", "cat", "non-cat", "non-cat", "non-cat"])
2198
- >>> class_likelihood_ratios(y_true, y_pred, labels=["non-cat", "cat"],
2199
- ... replace_undefined_by=1.0)
2196
+ >>> class_likelihood_ratios(y_true, y_pred, labels=["non-cat", "cat"])
2200
2197
(1.5, 0.75)
2201
2198
"""
2202
2199
# TODO(1.9): When `raise_warning` is removed, the following changes need to be made:
2203
2200
# The checks for `raise_warning==True` need to be removed and we will always warn,
2204
- # the default return value of `replace_undefined_by` should be updated from `np.nan`
2205
- # (which was kept for backwards compatibility) to `1.0`, its hidden option
2206
- # ("default") is not used anymore, some warning messages can be removed, the Warns
2207
- # section in the docstring should not mention `raise_warning` anymore and the
2208
- # "Mathematical divergences" section in model_evaluation.rst needs to be updated on
2209
- # the new default behaviour of `replace_undefined_by`.
2201
+ # remove `FutureWarning`, and the Warns section in the docstring should not mention
2202
+ # `raise_warning` anymore.
2210
2203
y_true , y_pred = attach_unique (y_true , y_pred )
2211
2204
y_type , y_true , y_pred = _check_targets (y_true , y_pred )
2212
2205
if y_type != "binary" :
@@ -2220,28 +2213,11 @@ class are present in `y_true`): both likelihood ratios are undefined.
2220
2213
"`UndefinedMetricWarning` will always be raised in case of a division by zero "
2221
2214
"and the value set with the `replace_undefined_by` param will be returned."
2222
2215
)
2223
- mgs_changed_default = (
2224
- "The default return value of `class_likelihood_ratios` in case of a division "
2225
- "by zero has been deprecated in 1.7 and will be changed to the worst scores "
2226
- "(`(1.0, 1.0)`) in version 1.9. Set `replace_undefined_by=1.0` to use the new"
2227
- "default and to silence this Warning."
2228
- )
2229
2216
if raise_warning != "deprecated" :
2230
- warnings .warn (
2231
- " " .join ((msg_deprecated_param , mgs_changed_default )), FutureWarning
2232
- )
2217
+ warnings .warn (msg_deprecated_param , FutureWarning )
2233
2218
else :
2234
- if replace_undefined_by == "default" :
2235
- # TODO(1.9): Remove. If users don't set any return values in case of a
2236
- # division by zero (`raise_warning="deprecated"` and
2237
- # `replace_undefined_by="default"`) they still get a FutureWarning about
2238
- # changing default return values:
2239
- warnings .warn (mgs_changed_default , FutureWarning )
2240
2219
raise_warning = True
2241
2220
2242
- if replace_undefined_by == "default" :
2243
- replace_undefined_by = np .nan
2244
-
2245
2221
if replace_undefined_by == 1.0 :
2246
2222
replace_undefined_by = {"LR+" : 1.0 , "LR-" : 1.0 }
2247
2223
@@ -2293,12 +2269,12 @@ class are present in `y_true`): both likelihood ratios are undefined.
2293
2269
2294
2270
# if `support_pos == 0`a division by zero will occur
2295
2271
if support_pos == 0 :
2296
- # TODO(1.9): Change return values in warning message to new default: the worst
2297
- # possible scores: `(1.0, 1.0)`
2298
2272
msg = (
2299
2273
"No samples of the positive class are present in `y_true`. "
2300
2274
"`positive_likelihood_ratio` and `negative_likelihood_ratio` are both set "
2301
- "to `np.nan`."
2275
+ "to `np.nan`. Use the `replace_undefined_by` param to control this "
2276
+ "behavior. To suppress this warning or turn it into an error, see Python's "
2277
+ "`warnings` module and `warnings.catch_warnings()`."
2302
2278
)
2303
2279
warnings .warn (msg , UndefinedMetricWarning , stacklevel = 2 )
2304
2280
positive_likelihood_ratio = np .nan
@@ -2315,9 +2291,8 @@ class are present in `y_true`): both likelihood ratios are undefined.
2315
2291
else :
2316
2292
msg_beginning = "`positive_likelihood_ratio` is ill-defined and "
2317
2293
msg_end = "set to `np.nan`. Use the `replace_undefined_by` param to "
2318
- "control this behavior."
2319
- # TODO(1.9): Change return value in warning message to new default: `1.0`,
2320
- # which is the worst possible score for "LR+"
2294
+ "control this behavior. To suppress this warning or turn it into an error, "
2295
+ "see Python's `warnings` module and `warnings.catch_warnings()`."
2321
2296
warnings .warn (msg_beginning + msg_end , UndefinedMetricWarning , stacklevel = 2 )
2322
2297
if isinstance (replace_undefined_by , float ) and np .isnan (replace_undefined_by ):
2323
2298
positive_likelihood_ratio = replace_undefined_by
@@ -2332,11 +2307,11 @@ class are present in `y_true`): both likelihood ratios are undefined.
2332
2307
# if `tn == 0`a division by zero will occur
2333
2308
if tn == 0 :
2334
2309
if raise_warning :
2335
- # TODO(1.9): Change return value in warning message to new default: `1.0`,
2336
- # which is the worst possible score for "LR-"
2337
2310
msg = (
2338
2311
"`negative_likelihood_ratio` is ill-defined and set to `np.nan`. "
2339
- "Use the `replace_undefined_by` param to control this behavior."
2312
+ "Use the `replace_undefined_by` param to control this behavior. To "
2313
+ "suppress this warning or turn it into an error, see Python's "
2314
+ "`warnings` module and `warnings.catch_warnings()`."
2340
2315
)
2341
2316
warnings .warn (msg , UndefinedMetricWarning , stacklevel = 2 )
2342
2317
if isinstance (replace_undefined_by , float ) and np .isnan (replace_undefined_by ):
0 commit comments