Skip to content

Commit

Permalink
Merge pull request #20 from jeethu/jeethu/clobber-prevention
Browse files Browse the repository at this point in the history
Make numerai_corr a pure function
  • Loading branch information
ndharasz committed Jan 23, 2024
2 parents 96ea48c + 33cd980 commit 2d6d2b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numerai_tools/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def numerai_corr(
Returns:
pd.Series - the resulting correlation scores for each column in predictions
"""
targets -= targets.mean()
targets = targets - targets.mean()
targets, predictions = filter_sort_index(
targets, predictions, max_filtered_index_ratio
)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from numerai_tools.scoring import (
correlation,
numerai_corr,
tie_broken_rank_correlation,
spearman_correlation,
pearson_correlation,
Expand Down Expand Up @@ -198,3 +199,12 @@ def test_neutralize(self):
[0, 0, 0, 0, 0],
],
).all()

def test_numerai_corr_doesnt_clobber_targets(self):
s = [x/4 for x in range(5)]
df = pd.DataFrame({
"target": s,
"prediction": reversed(s)
})
numerai_corr(df[["prediction"]], df["target"])
assert pd.Series(s).equals(df["target"]), f"{s} != {list(df['target'].values)}"

0 comments on commit 2d6d2b2

Please sign in to comment.