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

Fix PFI issue in binary classification #4587

Merged
merged 10 commits into from
Jan 8, 2020
Merged

Conversation

yaeldekel
Copy link

This change adds support for running PFI on binary classification models that do not contain a calibrator. Fixes #4517 .

@yaeldekel yaeldekel requested a review from a team as a code owner December 18, 2019 15:10
@codecov
Copy link

codecov bot commented Dec 18, 2019

Codecov Report

Merging #4587 into master will increase coverage by 0.02%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##           master    #4587      +/-   ##
==========================================
+ Coverage   75.62%   75.64%   +0.02%     
==========================================
  Files         938      938              
  Lines      168618   168649      +31     
  Branches    18208    18224      +16     
==========================================
+ Hits       127523   127582      +59     
+ Misses      36066    36041      -25     
+ Partials     5029     5026       -3
Flag Coverage Δ
#Debug 75.64% <85.71%> (+0.02%) ⬆️
#production 71.26% <64.7%> (+0.02%) ⬆️
#test 90.44% <100%> (ø) ⬆️
Impacted Files Coverage Δ
...s/Metrics/CalibratedBinaryClassificationMetrics.cs 62.5% <0%> (-37.5%) ⬇️
...soft.ML.Tests/PermutationFeatureImportanceTests.cs 100% <100%> (ø) ⬆️
...ansforms/PermutationFeatureImportanceExtensions.cs 97.93% <100%> (ø) ⬆️
...soft.ML.Transforms/PermutationFeatureImportance.cs 61.17% <100%> (+1.17%) ⬆️
...L.AutoML/TrainerExtensions/TrainerExtensionUtil.cs 85.15% <0%> (-1.75%) ⬇️
...ML.Transforms/Text/StopWordsRemovingTransformer.cs 86.1% <0%> (-0.16%) ⬇️
src/Microsoft.ML.AutoML/Sweepers/Parameters.cs 85.16% <0%> (+0.84%) ⬆️
...soft.ML.Transforms/Text/WordEmbeddingsExtractor.cs 87.52% <0%> (+1.13%) ⬆️
src/Microsoft.ML.Maml/MAML.cs 26.21% <0%> (+1.45%) ⬆️
... and 3 more

@@ -171,6 +199,23 @@ public static class PermutationFeatureImportanceExtensions
auprc: a.AreaUnderPrecisionRecallCurve - b.AreaUnderPrecisionRecallCurve);
}

private static CalibratedBinaryClassificationMetrics CalibratedBinaryClassifierDelta(
CalibratedBinaryClassificationMetrics a, CalibratedBinaryClassificationMetrics b)
Copy link
Member

@antoniovs1029 antoniovs1029 Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I open this PR in Visual Studio I can see that this new method has 0 references. Is this intended?

Particularly, notice that the BinaryClassifierDelta (which already existed) gets a reference in the PermutationFeatureImportance<TModel> method you modified whether isCalibratedModel is true or not. So I was wondering when/where is the CalibratedBinaryClassifierDelta method supposed to be called? #Resolved

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed it (I added it initially before we decided not to add calibrated metrics to PFI).


In reply to: 359531828 [](ancestors = 359531828)

@gvashishtha
Copy link
Contributor

So based on the ML.NET documentation on PFI, it seems that if you were to take the more time-intensive route of exposing the LogLoss, LogLossReduction, and Entropy metrics, there would be an additional way for users to compare the importance of features (rather than simply R^2)?

What's a situation where R^2 would not be sufficient for doing PFI well?

@antoniovs1029
Copy link
Member

antoniovs1029 commented Jan 2, 2020

What's a situation where R^2 would not be sufficient for doing PFI well?

@gvashishtha

For the record, R^2 is not included as a metric inside BinaryClassificationMetrics (link to code) and so it doesn't exist either in BinaryClassificationMetricsStatistics (link). In the tutorial you linked, Regression is used, and in that case R^2 is included inside its metrics statistics (link).

So the PR here would only affect Binary Classification. Currently BinaryClassificationMetricsStatistics only offers metrics for AreaUnderRocCurve, Accuracy, PositivePrecision, PositiveRecall, NegativePrecision, NegativeRecall, F1Score, and AreaUnderPrecisionRecallCurve. When performing PFI on a Binary Classification model, the change in the metrics is computed for all those metrics, and for every feature. So a user could evaluate the PFI results with any of those metrics (though, in practice, I wouldn't know which metrics would actually be used to choose the most important feature, I guess it depends on the specific case the user is using PFI and there's no objective way of saying if they're "sufficient" or not...).

So, the question remains if it's worth it to make breaking changes in the API to also include LogLoss, LogLossReduction, and Entropy metrics when using PFI with a Binary Classification Calibrated model, by using CalibratedBinaryClassificationMetrics instead. The real question would be if those metrics would be valuable to users running PFI.... and since no one has opened an issue about them, I would tend to think that it's better to not make the breaking changes in the API unless people start asking about them.

predictionTransformer,
data,
() => new BinaryClassificationMetricsStatistics(),
idv => catalog.EvaluateNonCalibrated(idv, labelColumnName),
Copy link
Contributor

@harishsk harishsk Jan 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small Nit:
The only difference between the if (isCalibratedModel) and the else case is the idv parameter. Is it possible to make this a bit more readable by factoring out just that line and using a single call to the PermutationFeatureImportance constructor? #Resolved

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolving this comment, since isCalibratedModel has been removed.


In reply to: 362685943 [](ancestors = 362685943)

@@ -305,6 +305,18 @@ public void TestPfiBinaryClassificationOnSparseFeatures(bool saveModel)

Done();
}

[Fact]
public void TestBinaryClassificationWithoutCalibrator()
Copy link
Contributor

@harishsk harishsk Jan 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test does not Assert anything. Can you please include Asserts for the relevant results that this test is supposed to verify? #Resolved

@harishsk
Copy link
Contributor

harishsk commented Jan 3, 2020

Breaking the API has a high bar and I think this does not meet that bar. I would suggest leaving it as is or adding a new API that returns the calibrated metrics.

@yaeldekel
Copy link
Author

I will leave it as is for now, and make a change that ensures the existing API doesn't break only in case we get customer asks.


In reply to: 570431913 [](ancestors = 570431913)


[BestFriend]
internal CalibratedBinaryClassificationMetrics(double auc, double accuracy, double positivePrecision, double positiveRecall,
double negativePrecision, double negativeRecall, double f1Score, double auprc, double logLoss, double logLossReduction, double entropy)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I believe this constructor is no longer used (after you removed the other code handling the calibrated case). Is there a reason the keep this constructor?

Copy link
Member

@antoniovs1029 antoniovs1029 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it LGTM, only I have the question about if we should keep the CalibratedBinaryClassificationMetrics constructor that is added in this PR.

@antoniovs1029 antoniovs1029 merged commit e38647c into dotnet:master Jan 8, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PFI doesn't work with uncalibrated binary classifiers
5 participants