@@ -1627,6 +1627,11 @@ def fbeta_score(
1627
1627
returns 0.0 and raises ``UndefinedMetricWarning``. This behavior can be
1628
1628
modified by setting ``zero_division``.
1629
1629
1630
+ F-beta score is not implemented as a named scorer that can be passed to
1631
+ the `scoring` parameter of cross-validation tools directly: it requires to be
1632
+ wrapped with :func:`make_scorer` so as to specify the value of `beta`. See
1633
+ examples for details.
1634
+
1630
1635
References
1631
1636
----------
1632
1637
.. [1] R. Baeza-Yates and B. Ribeiro-Neto (2011).
@@ -1650,9 +1655,29 @@ def fbeta_score(
1650
1655
>>> fbeta_score(y_true, y_pred, average=None, beta=0.5)
1651
1656
array([0.71, 0. , 0. ])
1652
1657
>>> y_pred_empty = [0, 0, 0, 0, 0, 0]
1653
- >>> fbeta_score(y_true, y_pred_empty,
1654
- ... average="macro", zero_division=np.nan, beta=0.5)
1658
+ >>> fbeta_score(
1659
+ ... y_true,
1660
+ ... y_pred_empty,
1661
+ ... average="macro",
1662
+ ... zero_division=np.nan,
1663
+ ... beta=0.5,
1664
+ ... )
1655
1665
0.128
1666
+
1667
+ In order to use :func:`fbeta_scorer` as a scorer, a callable
1668
+ scorer objects needs to be created first with :func:`make_scorer`,
1669
+ passing the value for the `beta` parameter.
1670
+
1671
+ >>> from sklearn.metrics import fbeta_score, make_scorer
1672
+ >>> ftwo_scorer = make_scorer(fbeta_score, beta=2)
1673
+ >>> from sklearn.model_selection import GridSearchCV
1674
+ >>> from sklearn.svm import LinearSVC
1675
+ >>> grid = GridSearchCV(
1676
+ ... LinearSVC(dual="auto"),
1677
+ ... param_grid={'C': [1, 10]},
1678
+ ... scoring=ftwo_scorer,
1679
+ ... cv=5
1680
+ ... )
1656
1681
"""
1657
1682
1658
1683
_ , _ , f , _ = precision_recall_fscore_support (
0 commit comments