-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Update Feature Contribution Calculation Samples #3241
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3241 +/- ##
==========================================
- Coverage 72.63% 72.62% -0.01%
==========================================
Files 807 805 -2
Lines 145129 145091 -38
Branches 16220 16220
==========================================
- Hits 105415 105376 -39
Misses 35297 35297
- Partials 4417 4418 +1
|
var transformedData = transformer.Transform(data); | ||
|
||
// Define a linear trainer. | ||
var linearTrainer = mlContext.Regression.Trainers.Ols(); |
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.
mlContext.Regression.Trainers.Ols() [](start = 32, length = 35)
Can we not combined it with the pipeline above? Is there any specific reason for doing so? #Resolved
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.
I'd like to compute the feature contributions on the transformed data, so I separate this out into two steps.
In reply to: 273270793 [](ancestors = 273270793)
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.
// Convert training data to IDataView. | ||
var data = mlContext.Data.LoadFromEnumerable(samples); | ||
|
||
// Create a pipeline to concatenate the features into a feature vector and normalize it. |
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.
This doesn't look a part of FCC. May we start with raw data?
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.
I wanted to show that FCC works on featurized data, not on the original columns, so I wanted to make it explicit.
// Define a feature contribution calculator for all the features, and don't normalize the contributions. | ||
// These are "trivial estimators" and they don't need to fit to the data, so we can feed a subset. | ||
var simpleScoredDataset = linearModel.Transform(mlContext.Data.TakeRows(transformedData, 1)); | ||
var linearFeatureContributionCalculator = mlContext.Transforms.CalculateFeatureContribution(linearModel, normalize: false).Fit(simpleScoredDataset); |
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.
Is it possible to do Fit(null)
? Having simpleScoredDataset
is a bit confusing.
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.
It is confusing, but we cannot use null
. We need to pass in something with a schema.
private class Data | ||
{ | ||
public float Label { get; set; } | ||
public float Feature1 { get; set; } |
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.
You have spaces between public fields in the other sample below.
yield return data; | ||
} | ||
} | ||
private static double Sigmoid(double x) |
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.
One line function needs to use => 1.0 / (1.0 + Exp(-x))
.
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.
Overall LGTM. Please address my comments if they make sense to you.
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.
* Updating samples for FCC (cherry picked from commit 6f576de)
This PR cleans up the samples for FCC and creates a new one specifically for calibrated learners.
Fixes #3233