Skip to content
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

Predictions for regression in Datalab #902

Merged
merged 38 commits into from
Dec 7, 2023
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
48b776f
add predictions argument to find_issues method of RegressionLabelIssu…
elisno Nov 22, 2023
a754f6f
move Datalab + regression tests into separate test class
elisno Nov 22, 2023
b0bd9d8
apply black formatter
elisno Nov 22, 2023
c2d3049
add predictions as an argument to Datalab's find_issues method
elisno Nov 22, 2023
c3d004e
split tests up further
elisno Nov 22, 2023
7266f37
add score assertion to test on finding label issue based on features
elisno Nov 22, 2023
3d41559
add datalab tests for label issue checks with predictions for regression
elisno Nov 22, 2023
2511f24
add Datalab test for supplying another model for finding label issues…
elisno Nov 22, 2023
5db1554
apply black formatter
elisno Nov 22, 2023
75cf0c3
clarify settings tasks with register decorator in guide
elisno Nov 22, 2023
d03bfed
set threshold as a field in issue manager (for predictions)
elisno Nov 22, 2023
4fbfd15
add __init__.py for test-module discovery
elisno Dec 1, 2023
62ecc51
Introduce helper classes for validating model outputs
elisno Dec 1, 2023
404c607
remove predictions argument from top-level Datalab-methods.
elisno Dec 1, 2023
60231ac
apply suggestions from review
elisno Dec 1, 2023
77d2977
clarify module name of ClearnLearning reference
elisno Dec 1, 2023
ff58245
update docstring notes on pred_probs for high-level classes (Datalab …
elisno Dec 1, 2023
3fe3728
fix formatting in issue_finder.py
elisno Dec 4, 2023
516645b
Merge branch 'master' into predictions-for-regression-in-datalab
elisno Dec 5, 2023
13325d3
Merge branch 'master' into predictions-for-regression-in-datalab
elisno Dec 5, 2023
6428708
reintroduce pred_probs to kwargs in IssueFinder.get_available_issue_t…
elisno Dec 5, 2023
c921934
add punctuation [skip ci]
elisno Dec 5, 2023
a70ff32
update tests on datalab with regression
elisno Dec 5, 2023
c351149
Apply black formatter to test_datalab.py
elisno Dec 5, 2023
7f99c68
Update cleanlab/datalab/datalab.py
elisno Dec 5, 2023
9956325
Update cleanlab/datalab/internal/issue_finder.py
elisno Dec 5, 2023
181e3b7
simplify generation of regression dataset for testing
elisno Dec 6, 2023
700c238
apply black formatter
elisno Dec 6, 2023
97b26b6
refactor test cases
elisno Dec 6, 2023
4c9fc08
apply black formatter
elisno Dec 6, 2023
41be070
update regression dataset generation for testing
elisno Dec 6, 2023
0974401
adjust tests for regression + datalab
elisno Dec 7, 2023
e201c43
update regression tests
elisno Dec 7, 2023
3dc227a
Apply suggestions from code review
elisno Dec 7, 2023
0f36966
suppress health check for unrelated test on empty near duplicate sets
elisno Dec 7, 2023
af11282
Comment on priority order for find_issues method
elisno Dec 7, 2023
5165eb4
add Datalab regressions issue managers to docs
elisno Dec 7, 2023
41caca5
Apply suggestions from code review
elisno Dec 7, 2023
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
Prev Previous commit
Next Next commit
update tests on datalab with regression
add tests about issue flags
  • Loading branch information
elisno committed Dec 5, 2023
commit a70ff32238daaa2cdb6050fe1fb9161a53443ef6
64 changes: 51 additions & 13 deletions tests/datalab/test_datalab.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ def test_pred_probs_precedence(self, pred_probs, random_embeddings):
class TestDatalabForRegression:
@pytest.fixture
def regression_data(
self, num_examples=200, num_features=3, noise=0.2, error_frac=0.1, error_noise=5
self, num_examples=200, num_features=3, noise=0.01, error_frac=0.05, error_noise=10
):
np.random.seed(SEED)
X = np.random.random(size=(num_examples, num_features))
Expand Down Expand Up @@ -1036,13 +1036,26 @@ def test_regression_with_features(self, lab, regression_data):
summary = lab.get_issue_summary()

assert "label" in summary["issue_type"].values
assert (summary[summary["issue_type"] == "label"]["num_issues"] == 40).all()
assert (summary[summary["issue_type"] == "label"]["num_issues"] == 6).all()
assert np.isclose(
summary[summary["issue_type"] == "label"]["score"].values[0], 0.672974, atol=1e-5
summary[summary["issue_type"] == "label"]["score"].values[0], 0.915695, atol=1e-5
)
jwmueller marked this conversation as resolved.
Show resolved Hide resolved
issues = lab.get_issues("label")
issue_ids = issues.query("is_label_issue").index
expected_issue_ids = regression_data["error_idx"]

# jaccard similarity
intersection = len(list(set(issue_ids).intersection(set(expected_issue_ids))))
union = len(set(issue_ids)) + len(set(expected_issue_ids)) - intersection
assert float(intersection) / union >= 0.6

# FPR
fpr = len(list(set(issue_ids).difference(set(expected_issue_ids)))) / len(issue_ids)
assert fpr < 0.05


def test_regression_with_predictions(self, lab, regression_data):
"""Test that the regression issue checks find 12 label issues, based on the
"""Test that the regression issue checks find 9 label issues, based on the
predictions of a model.

Instead of running a model, we use the ground-truth to emulate a perfect model's predictions.
Expand All @@ -1056,34 +1069,59 @@ def test_regression_with_predictions(self, lab, regression_data):

lab.find_issues(pred_probs=y_pred)
summary = lab.get_issue_summary()
assert (summary[summary["issue_type"] == "label"]["num_issues"] == 12).all()
assert (summary[summary["issue_type"] == "label"]["num_issues"] == 9).all()
assert np.isclose(
summary[summary["issue_type"] == "label"]["score"].values[0], 0.58768, atol=1e-5
summary[summary["issue_type"] == "label"]["score"].values[0], 0.876453, atol=1e-5
)


issues = lab.get_issues("label")
issue_ids = issues.query("is_label_issue").index
expected_issue_ids = regression_data["error_idx"]

# jaccard similarity
intersection = len(list(set(issue_ids).intersection(set(expected_issue_ids))))
union = len(set(issue_ids)) + len(set(expected_issue_ids)) - intersection
assert float(intersection) / union >= 0.9

# FPR
fpr = len(list(set(issue_ids).difference(set(expected_issue_ids)))) / len(issue_ids)
assert fpr < 0.05

# Apply a threshold for flagging issues. A larger threshold will flag more issues,
# but won't change the score.
lab.find_issues(pred_probs=y_pred, issue_types={"label": {"threshold": 0.5}})
lab.find_issues(pred_probs=y_pred, issue_types={"label": {"threshold": 0.9}})
summary = lab.get_issue_summary()
assert (summary[summary["issue_type"] == "label"]["num_issues"] == 22).all()
assert (summary[summary["issue_type"] == "label"]["num_issues"] == 18).all()
assert np.isclose(
summary[summary["issue_type"] == "label"]["score"].values[0], 0.58768, atol=1e-5
summary[summary["issue_type"] == "label"]["score"].values[0], 0.876453, atol=1e-5
)

def test_regression_with_model_and_features(self, lab, regression_data):
"""Test that the regression issue checks find label issue with another model."""
from sklearn.neighbors import KNeighborsRegressor

model = KNeighborsRegressor(n_neighbors=5)
model = KNeighborsRegressor(n_neighbors=2)
X = regression_data["X"]
lab.find_issues(
features=X, issue_types={"label": {"clean_learning_kwargs": {"model": model}}}
)
summary = lab.get_issue_summary()
assert (summary[summary["issue_type"] == "label"]["num_issues"] == 30).all()
assert (summary[summary["issue_type"] == "label"]["num_issues"] == 8).all()
assert np.isclose(
summary[summary["issue_type"] == "label"]["score"].values[0], 0.777305, atol=1e-5
summary[summary["issue_type"] == "label"]["score"].values[0], 0.945047, atol=1e-5
)
jwmueller marked this conversation as resolved.
Show resolved Hide resolved
issues = lab.get_issues("label")
issue_ids = issues.query("is_label_issue").index
expected_issue_ids = regression_data["error_idx"] # Set to 5% of the data, but random noise may be too small to detect

# jaccard similarity
intersection = len(list(set(issue_ids).intersection(set(expected_issue_ids))))
union = len(set(issue_ids)) + len(set(expected_issue_ids)) - intersection
assert float(intersection) / union >= 0.80

# FPR
fpr = len(list(set(issue_ids).difference(set(expected_issue_ids)))) / len(issue_ids)
assert fpr < 0.05


class TestDatalabFindOutlierIssues:
Expand Down
Loading