Skip to content

docs: add code samples for metrics.{accuracy_score, confusion_matrix} #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@
def accuracy_score(y_true, y_pred, normalize=True) -> float:
"""Accuracy classification score.

**Examples:**

>>> import bigframes.pandas as bpd
>>> import bigframes.ml.metrics
>>> bpd.options.display.progress_bar = None

>>> y_true = bpd.DataFrame([0, 2, 1, 3])
>>> y_pred = bpd.DataFrame([0, 1, 2, 3])
>>> accuracy_score = bigframes.ml.metrics.accuracy_score(y_true, y_pred)
>>> accuracy_score
0.5

If False, return the number of correctly classified samples:

>>> accuracy_score = bigframes.ml.metrics.accuracy_score(y_true, y_pred, normalize=False)
>>> accuracy_score
2

Args:
y_true (Series or DataFrame of shape (n_samples,)):
Ground truth (correct) labels.
Expand Down Expand Up @@ -58,6 +76,30 @@ def confusion_matrix(
:math:`C_{0,0}`, false negatives is :math:`C_{1,0}`, true positives is
:math:`C_{1,1}` and false positives is :math:`C_{0,1}`.

**Examples:**

>>> import bigframes.pandas as bpd
>>> import bigframes.ml.metrics
>>> bpd.options.display.progress_bar = None

>>> y_true = bpd.DataFrame([2, 0, 2, 2, 0, 1])
>>> y_pred = bpd.DataFrame([0, 0, 2, 2, 0, 2])
>>> confusion_matrix = bigframes.ml.metrics.confusion_matrix(y_true, y_pred)
>>> confusion_matrix
0 1 2
0 2 0 0
1 0 0 1
2 1 0 2

>>> y_true = bpd.DataFrame(["cat", "ant", "cat", "cat", "ant", "bird"])
>>> y_pred = bpd.DataFrame(["ant", "ant", "cat", "cat", "ant", "cat"])
>>> confusion_matrix = bigframes.ml.metrics.confusion_matrix(y_true, y_pred)
>>> confusion_matrix
ant bird cat
ant 2 0 0
bird 0 0 1
cat 1 0 2

Args:
y_true (Series or DataFrame of shape (n_samples,)):
Ground truth (correct) target values.
Expand Down