Skip to content

Commit

Permalink
docs: docstrings for r2
Browse files Browse the repository at this point in the history
  • Loading branch information
CangyuanLi committed Feb 1, 2025
1 parent c27e195 commit 701edcf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions python/rapidstats/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,4 +944,18 @@ def root_mean_squared_error(
)

def r2(self, y_true: ArrayLike, y_score: ArrayLike) -> ConfidenceInterval:
"""Bootstrap R2. See [rapidstats.r2][] for more details.
Parameters
----------
y_true : ArrayLike
Ground truth target
y_score : ArrayLike
Predicted scores
Returns
-------
ConfidenceInterval
A tuple of (lower, mean, upper)
"""
return _bootstrap_r2(_regression_to_df(y_true, y_score), **self._params)
18 changes: 18 additions & 0 deletions python/rapidstats/_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,4 +789,22 @@ def capture_rate_at_quantiles(


def r2(y_true: ArrayLike, y_score: ArrayLike) -> float:
r"""Computes R2 as
\[
1 - \frac{\sum{(y_i - \hat{y_i})^2}{}}{\sum{(y_{i} - \bar{y})^2}}
\]
Parameters
----------
y_true : ArrayLike
Ground truth target
y_score : ArrayLike
Predicted scores
Returns
-------
float
R2
"""
return _r2(_regression_to_df(y_true, y_score))

0 comments on commit 701edcf

Please sign in to comment.