Skip to content

Commit 5f37b09

Browse files
authored
docs: add the code samples for metrics{auc, roc_auc_score, roc_curve} (#520)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
1 parent 3b80f95 commit 5f37b09

File tree

1 file changed

+78
-0
lines changed
  • third_party/bigframes_vendored/sklearn/metrics

1 file changed

+78
-0
lines changed

third_party/bigframes_vendored/sklearn/metrics/_ranking.py

+78
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ def auc(x, y) -> float:
2727
way to summarize a precision-recall curve, see
2828
:func:`average_precision_score`.
2929
30+
**Examples:**
31+
32+
>>> import bigframes.pandas as bpd
33+
>>> import bigframes.ml.metrics
34+
>>> bpd.options.display.progress_bar = None
35+
36+
>>> x = bpd.DataFrame([1, 1, 2, 2])
37+
>>> y = bpd.DataFrame([2, 3, 4, 5])
38+
>>> auc = bigframes.ml.metrics.auc(x, y)
39+
>>> auc
40+
3.5
41+
42+
The input can be Series:
43+
44+
>>> df = bpd.DataFrame(
45+
... {"x": [1, 1, 2, 2],
46+
... "y": [2, 3, 4, 5],}
47+
... )
48+
>>> auc = bigframes.ml.metrics.auc(df["x"], df["y"])
49+
>>> auc
50+
3.5
51+
52+
3053
Args:
3154
x (Series or DataFrame of shape (n_samples,)):
3255
X coordinates. These must be either monotonic increasing or monotonic
@@ -44,6 +67,28 @@ def roc_auc_score(y_true, y_score) -> float:
4467
"""Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC) \
4568
from prediction scores.
4669
70+
**Examples:**
71+
72+
>>> import bigframes.pandas as bpd
73+
>>> import bigframes.ml.metrics
74+
>>> bpd.options.display.progress_bar = None
75+
76+
>>> y_true = bpd.DataFrame([0, 0, 1, 1, 0, 1, 0, 1, 1, 1])
77+
>>> y_score = bpd.DataFrame([0.1, 0.4, 0.35, 0.8, 0.65, 0.9, 0.5, 0.3, 0.6, 0.45])
78+
>>> roc_auc_score = bigframes.ml.metrics.roc_auc_score(y_true, y_score)
79+
>>> roc_auc_score
80+
0.625
81+
82+
The input can be Series:
83+
84+
>>> df = bpd.DataFrame(
85+
... {"y_true": [0, 0, 1, 1, 0, 1, 0, 1, 1, 1],
86+
... "y_score": [0.1, 0.4, 0.35, 0.8, 0.65, 0.9, 0.5, 0.3, 0.6, 0.45],}
87+
... )
88+
>>> roc_auc_score = bigframes.ml.metrics.roc_auc_score(df["y_true"], df["y_score"])
89+
>>> roc_auc_score
90+
0.625
91+
4792
Args:
4893
y_true (Series or DataFrame of shape (n_samples,)):
4994
True labels or binary label indicators. The binary and multiclass cases
@@ -72,6 +117,39 @@ def roc_curve(
72117
):
73118
"""Compute Receiver operating characteristic (ROC).
74119
120+
**Examples:**
121+
122+
>>> import bigframes.pandas as bpd
123+
>>> import bigframes.ml.metrics
124+
>>> bpd.options.display.progress_bar = None
125+
126+
>>> y_true = bpd.DataFrame([1, 1, 2, 2])
127+
>>> y_score = bpd.DataFrame([0.1, 0.4, 0.35, 0.8])
128+
>>> fpr, tpr, thresholds = bigframes.ml.metrics.roc_curve(y_true, y_score, drop_intermediate=False)
129+
>>> fpr
130+
0 0.0
131+
1 0.0
132+
2 0.0
133+
3 0.0
134+
4 0.0
135+
Name: fpr, dtype: Float64
136+
137+
>>> tpr
138+
0 0.0
139+
1 0.333333
140+
2 0.5
141+
3 0.833333
142+
4 1.0
143+
Name: tpr, dtype: Float64
144+
145+
>>> thresholds
146+
0 inf
147+
1 0.8
148+
2 0.4
149+
3 0.35
150+
4 0.1
151+
Name: thresholds, dtype: Float64
152+
75153
Args:
76154
y_true: Series or DataFrame of shape (n_samples,)
77155
True binary labels. If labels are not either {-1, 1} or {0, 1}, then

0 commit comments

Comments
 (0)