-
Notifications
You must be signed in to change notification settings - Fork 21
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
[WIP] Add new scorer: MaNoScorer #289
Merged
+296
−8
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cb36630
Add new scorer: MaNoScorer
ambroiseodt 540d521
Update MaNoScorer for deep NN case
ambroiseodt 5786d6a
Update MNoScorer test: regression, invalid p-norm, both normalization
ambroiseodt e3a3df1
Add MaNoScorer deep tests
ambroiseodt bbf0143
Add static decorator
ambroiseodt f5ba2d0
Merge branch 'main' into add_mano
tgnassou 0ed73e5
Update metrics to deal with skorch update
ambroiseodt 3ac3ea7
Update metrics to match skorch update
ambroiseodt f280650
Update test for MaNo in the deep case
ambroiseodt 563c86c
Add attribute to detect type of normalization
ambroiseodt 4c940dd
Add pipeline test and choice of normalization
ambroiseodt 93879f4
Add output range test
ambroiseodt 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 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 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 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 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 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,6 +2,7 @@ | |
# Remi Flamary <remi.flamary@polytechnique.edu> | ||
# Oleksii Kachaiev <kachayev@gmail.com> | ||
# Yanis Lalou <yanis.lalou@polytechnique.edu> | ||
# Ambroise Odonnat <ambroiseodonnattechnologie@gmail.com> | ||
# | ||
# License: BSD 3-Clause | ||
|
||
|
@@ -23,6 +24,7 @@ | |
CircularValidation, | ||
DeepEmbeddedValidation, | ||
ImportanceWeightedScorer, | ||
MaNoScorer, | ||
MixValScorer, | ||
PredictionEntropyScorer, | ||
SoftNeighborhoodDensity, | ||
|
@@ -38,6 +40,7 @@ | |
SoftNeighborhoodDensity(), | ||
DeepEmbeddedValidation(), | ||
CircularValidation(), | ||
MaNoScorer(), | ||
], | ||
) | ||
def test_generic_scorer(scorer, da_dataset): | ||
|
@@ -92,6 +95,7 @@ def test_supervised_scorer(da_dataset): | |
[ | ||
PredictionEntropyScorer(), | ||
SoftNeighborhoodDensity(), | ||
MaNoScorer(), | ||
], | ||
) | ||
def test_scorer_with_entropy_requires_predict_proba(scorer, da_dataset): | ||
|
@@ -351,6 +355,44 @@ def test_mixval_scorer_regression(da_reg_dataset): | |
scorer(estimator, X, y, sample_domain) | ||
|
||
|
||
def test_mano_scorer(da_dataset): | ||
X, y, sample_domain = da_dataset.pack_train(as_sources=["s"], as_targets=["t"]) | ||
estimator = make_da_pipeline( | ||
DensityReweightAdapter(), | ||
LogisticRegression().set_fit_request(sample_weight=True), | ||
) | ||
|
||
estimator.fit(X, y, sample_domain=sample_domain) | ||
|
||
scorer = MaNoScorer() | ||
score_mean = scorer._score(estimator, X, y, sample_domain=sample_domain) | ||
assert isinstance(score_mean, float), "score_mean is not a float" | ||
|
||
# Test softmax normalization | ||
scorer = MaNoScorer(threshold=-1) | ||
score_mean = scorer._score(estimator, X, y, sample_domain=sample_domain) | ||
assert isinstance(score_mean, float), "score_mean is not a float" | ||
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. You don't check if it is the right normalization which is considered no? 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. Understood, will do |
||
|
||
# Test softmax normalization | ||
scorer = MaNoScorer(threshold=float("inf")) | ||
score_mean = scorer._score(estimator, X, y, sample_domain=sample_domain) | ||
assert isinstance(score_mean, float), "score_mean is not a float" | ||
|
||
# Test invalid p-norm order | ||
with pytest.raises(ValueError): | ||
MaNoScorer(p=-1) | ||
|
||
|
||
def test_mano_scorer_regression(da_reg_dataset): | ||
X, y, sample_domain = da_reg_dataset.pack(as_sources=["s"], as_targets=["t"]) | ||
|
||
estimator = make_da_pipeline(DensityReweightAdapter(), LogisticRegression()) | ||
|
||
scorer = MaNoScorer() | ||
with pytest.raises(ValueError): | ||
scorer(estimator, X, y, sample_domain) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"scorer", | ||
[ | ||
|
@@ -360,6 +402,7 @@ def test_mixval_scorer_regression(da_reg_dataset): | |
SoftNeighborhoodDensity(), | ||
CircularValidation(), | ||
MixValScorer(alpha=0.55, random_state=42), | ||
MaNoScorer(), | ||
], | ||
) | ||
def test_scorer_with_nd_input(scorer, da_dataset): | ||
|
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.
change name
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.
To what? it was the name already given
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.
understood, will do