-
Notifications
You must be signed in to change notification settings - Fork 0
ENH, TST: Add rtol to classifier and a test. #44
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
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| import numpy as np | ||
| import pytest | ||
| from numpy.testing import assert_allclose | ||
| from sklearn.datasets import make_classification | ||
| from sklearn.datasets import load_digits, make_classification | ||
| from sklearn.metrics import accuracy_score, roc_auc_score | ||
| from sklearn.model_selection import StratifiedKFold, train_test_split | ||
| from sklearn.preprocessing import OneHotEncoder, StandardScaler | ||
|
|
@@ -410,3 +410,43 @@ def test_classification_against_grafo(hidden_layer_sizes, n_classes, activation, | |
| @parametrize_with_checks([GFDLClassifier(), EnsembleGFDLClassifier()]) | ||
| def test_sklearn_api_conformance(estimator, check): | ||
| check(estimator) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("reg_alpha, rtol, expected_acc, expected_roc", [ | ||
| (0.1, 1e-15, 0.9083333333333333, 0.9893414717354735), | ||
| (None, 1e-15, 0.2222222222222222, 0.5518850599798965), | ||
| (None, 1e-3, 0.8972222222222223, 0.9802912857599967), | ||
| ]) | ||
| def test_rtol_classifier(reg_alpha, rtol, expected_acc, expected_roc): | ||
| # For Moore-Penrose, a large singular value cutoff (rtol) | ||
| # may be required to achieve reasonable results. This test | ||
| # showcases that a default low cut of leads to almost random classification | ||
| # output for the Digits datasets which is alleviated by increasing the cut off. | ||
| # This cut off has no effect on ridge solver. | ||
| data = load_digits() | ||
| X, y = data.data, data.target | ||
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, | ||
| random_state=0) | ||
|
|
||
| scaler = StandardScaler().fit(X_train) | ||
| X_train_s = scaler.transform(X_train) | ||
| X_test_s = scaler.transform(X_test) | ||
|
|
||
| activation = "softmax" | ||
| weight_scheme = "normal" | ||
|
Collaborator
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. Might as well just specify the arguments directly in the call to the estimator below, since they're not used for anything else. Since that's minor, I'll let you do that in a follow-up. |
||
| model = GFDLClassifier(hidden_layer_sizes=[800] * 10, | ||
| activation=activation, | ||
| weight_scheme=weight_scheme, | ||
| seed=0, | ||
| reg_alpha=reg_alpha, | ||
| rtol=rtol) | ||
| model.fit(X_train_s, y_train) | ||
|
|
||
| y_hat_cur = model.predict(X_test_s) | ||
| y_hat_cur_proba = model.predict_proba(X_test_s) | ||
|
|
||
| acc_cur = accuracy_score(y_test, y_hat_cur) | ||
| roc_cur = roc_auc_score(y_test, y_hat_cur_proba, multi_class="ovo") | ||
|
|
||
| np.testing.assert_allclose(acc_cur, expected_acc) | ||
| np.testing.assert_allclose(roc_cur, expected_roc) | ||
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.