-
Notifications
You must be signed in to change notification settings - Fork 114
test: Add data_source parameter tests for ROC curve and ComparisonReport #1817
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
Open
sobiya-22
wants to merge
2
commits into
probabl-ai:main
Choose a base branch
from
sobiya-22:issue-1747-data-source-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,3 +232,79 @@ def test_multiclass_classification_kwargs(pyplot, multiclass_classification_repo | |
| display.plot(despine=False) | ||
| assert display.ax_[0].spines["top"].get_visible() | ||
| assert display.ax_[0].spines["right"].get_visible() | ||
|
|
||
|
|
||
| def test_data_source_binary_classification(pyplot, binary_classification_data_no_split): | ||
| """ | ||
| Test passing data_source to ROC plot in ComparisonReport with CrossValidationReport | ||
| """ | ||
| estimator, X, y = binary_classification_data_no_split | ||
| estimator_1 = LogisticRegression() | ||
| estimator_2 = LogisticRegression(C=10) | ||
|
|
||
| report = ComparisonReport( | ||
| reports={ | ||
| "estimator_1": CrossValidationReport(estimator_1, X, y), | ||
| "estimator_2": CrossValidationReport(estimator_2, X, y), | ||
| } | ||
| ) | ||
|
|
||
| display = report.metrics.roc(data_source="X_y", X=X, y=y) | ||
| assert display.data_source == "X_y" | ||
| display.plot() | ||
|
|
||
| display = report.metrics.roc(data_source="train") | ||
| assert display.data_source == "train" | ||
| display.plot() | ||
|
|
||
| display = report.metrics.roc(data_source="test") | ||
| assert display.data_source == "test" | ||
| display.plot() | ||
|
|
||
| n_reports = len(report.reports_) | ||
| n_splits = report.reports_[0]._cv_splitter.n_splits | ||
| expected_auc_entries = n_reports * n_splits | ||
|
|
||
| assert len(display.roc_auc) == expected_auc_entries | ||
| auc_values = display.roc_auc["roc_auc"].values | ||
| assert all(0 <= auc <= 1 for auc in auc_values) | ||
|
|
||
|
|
||
| def test_data_source_multiclass_classification( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, can you check that the outputs are different please? |
||
| pyplot, multiclass_classification_data_no_split | ||
| ): | ||
| "Test data_source in ROC plot for ComparisonReport with multiclass and CV report" | ||
| estimator, X, y = multiclass_classification_data_no_split | ||
| estimator_1 = LogisticRegression() | ||
| estimator_2 = LogisticRegression(C=10) | ||
|
|
||
| report = ComparisonReport( | ||
| reports={ | ||
| "estimator_1": CrossValidationReport(estimator_1, X, y), | ||
| "estimator_2": CrossValidationReport(estimator_2, X, y), | ||
| } | ||
| ) | ||
|
|
||
| class_labels = np.unique(y) | ||
|
|
||
| display = report.metrics.roc(data_source="X_y", X=X, y=y) | ||
| assert display.data_source == "X_y" | ||
| display.plot() | ||
|
|
||
| display = report.metrics.roc(data_source="train") | ||
| assert display.data_source == "train" | ||
| display.plot() | ||
|
|
||
| display = report.metrics.roc(data_source="test") | ||
| assert display.data_source == "test" | ||
| display.plot() | ||
|
|
||
| n_reports = len(report.reports_) | ||
| n_splits = report.reports_[0]._cv_splitter.n_splits | ||
| n_classes = len(class_labels) | ||
| expected_combinations = n_reports * n_classes * n_splits | ||
|
|
||
| assert len(display.roc_auc) == expected_combinations | ||
|
|
||
| auc_values = display.roc_auc["roc_auc"].values | ||
| assert all(0 <= auc <= 1 for auc in auc_values) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,92 @@ def test_multiclass_classification(pyplot, multiclass_classification_data): | |
| assert display.ax_.get_title() == "ROC Curve" | ||
|
|
||
|
|
||
| def test_data_source_binary_classification(pyplot, binary_classification_data): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as in previous file: checking that the outputs are different. |
||
| """Test data_source in ROC plot for ComparisonReport.""" | ||
| estimator, X_train, X_test, y_train, y_test = binary_classification_data | ||
| estimator_2 = clone(estimator).set_params(C=10).fit(X_train, y_train) | ||
|
|
||
| report = ComparisonReport( | ||
| reports={ | ||
| "estimator_1": EstimatorReport( | ||
| estimator, | ||
| X_train=X_train, | ||
| y_train=y_train, | ||
| X_test=X_test, | ||
| y_test=y_test, | ||
| ), | ||
| "estimator_2": EstimatorReport( | ||
| estimator_2, | ||
| X_train=X_train, | ||
| y_train=y_train, | ||
| X_test=X_test, | ||
| y_test=y_test, | ||
| ), | ||
| } | ||
| ) | ||
|
|
||
| display = report.metrics.roc(data_source="X_y", X=X_train, y=y_train) | ||
| assert display.data_source == "X_y" | ||
| display.plot() | ||
|
|
||
| display = report.metrics.roc(data_source="train") | ||
| assert display.data_source == "train" | ||
| display.plot() | ||
|
|
||
| display = report.metrics.roc(data_source="test") | ||
| assert display.data_source == "test" | ||
| display.plot() | ||
|
|
||
| train_auc = display.roc_auc["roc_auc"].values | ||
| assert len(train_auc) == 2 | ||
| assert all(0 <= auc <= 1 for auc in train_auc) | ||
|
|
||
|
|
||
| def test_data_source_multiclass_classification(pyplot, multiclass_classification_data): | ||
| """Test data_source in ROC plot for ComparisonReport with multiclass data""" | ||
| estimator, X_train, X_test, y_train, y_test = multiclass_classification_data | ||
| estimator_2 = clone(estimator).set_params(C=10).fit(X_train, y_train) | ||
|
|
||
| report = ComparisonReport( | ||
| reports={ | ||
| "estimator_1": EstimatorReport( | ||
| estimator, | ||
| X_train=X_train, | ||
| y_train=y_train, | ||
| X_test=X_test, | ||
| y_test=y_test, | ||
| ), | ||
| "estimator_2": EstimatorReport( | ||
| estimator_2, | ||
| X_train=X_train, | ||
| y_train=y_train, | ||
| X_test=X_test, | ||
| y_test=y_test, | ||
| ), | ||
| } | ||
| ) | ||
|
|
||
| class_labels = report.reports_[0].estimator_.classes_ | ||
|
|
||
| display = report.metrics.roc(data_source="X_y", X=X_train, y=y_train) | ||
| assert display.data_source == "X_y" | ||
| display.plot() | ||
|
|
||
| display = report.metrics.roc(data_source="train") | ||
| assert display.data_source == "train" | ||
| display.plot() | ||
|
|
||
| display = report.metrics.roc(data_source="test") | ||
| assert display.data_source == "test" | ||
| display.plot() | ||
|
|
||
| expected_combinations = len(report.report_names_) * len(class_labels) | ||
| assert len(display.roc_auc) == expected_combinations | ||
|
|
||
| auc_values = display.roc_auc["roc_auc"].values | ||
| assert all(0 <= auc <= 1 for auc in auc_values) | ||
|
|
||
|
|
||
| def test_binary_classification_kwargs(pyplot, binary_classification_data): | ||
| """Check that we can pass keyword arguments to the ROC curve plot for | ||
| cross-validation.""" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check that the results when changing the data_source do change please?
For instance, you can use a subsample of X and y when giving the data source
X_yso you don't have to create a new one, and then check that the dataframesdisplay.frame()outputed are different withassert notand the equals function.