-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Restore OVA ability to preserve key names on predicted label #3101
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
Changes from 4 commits
33a578e
a73b04e
fbbcfcf
d46ae57
2bb3ecc
a61b914
b68c4e5
06cce1a
10541d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,22 +37,22 @@ void PredictAndMetadata() | |
|
||
var testLoader = ml.Data.LoadFromTextFile(dataPath, TestDatasets.irisData.GetLoaderColumns(), separatorChar: ',', hasHeader: true); | ||
var testData = ml.Data.CreateEnumerable<IrisData>(testLoader, false); | ||
|
||
// During prediction we will get Score column with 3 float values. | ||
// We need to find way to map each score to original label. | ||
// In order to do what we need to get SlotNames from Score column. | ||
// Slot names on top of Score column represent original labels for i-th value in Score array. | ||
VBuffer<ReadOnlyMemory<char>> slotNames = default; | ||
engine.OutputSchema[nameof(IrisPrediction.Score)].GetSlotNames(ref slotNames); | ||
// In order to do what we need to get TrainingLabelValues from Score column. | ||
// TrainingLabelValues on top of Score column represent original labels for i-th value in Score array. | ||
VBuffer<ReadOnlyMemory<char>> originalLabels = default; | ||
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.
In this particular case we should be propagating both slot names and label names, right? Since they're string in both cases? While I see the point in augmenting the test to cover this new metadata type, is there any particular reason to remove the test that the vector has teh appropriate slot names? #WontFix 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. This is old scenario test. Purpose of it to show user how to do work with metadata. All tests with TestEstimatorCore routing would test on presence of slotnames and TrainingLabelValues. And we have plenty of them,. why should we do anything here with slotname? In reply to: 271046772 [](ancestors = 271046772) 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. OK, that's fine. I had the idea that these "showing the user" things were more the point of functional tests, but as you like. In reply to: 271050961 [](ancestors = 271050961,271046772) |
||
engine.OutputSchema[nameof(IrisPrediction.Score)].Annotations.GetValue(AnnotationUtils.Kinds.TrainingLabelValues, ref originalLabels); | ||
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.
Is the distinction with slot names that slots names must be text, while these might be any type? That might excuse not using them. But in such a case I'd argue that we should still have the slot names for descriptive user-facing purposes. so I'd like to confirm we're still doing that. #Resolved 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. No we don't, but I can change that. Any reason while we want continue to propagate slotnames? #Resolved 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. Well, let's imagine I write out a text file, and I have this scores column. With slot names, I get a descriptive header. Without it I don't. Does that make sense? #Resolved 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. Only if original labels were string, but ok. 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. Multiple metadata kinds is good, thanks Ivan. I believe this is what you did, that is, from the code I read you are propagating the labels always, and propogating slot names if tehy're text, and that seems fine to me. In reply to: 269742478 [](ancestors = 269742478) |
||
// Since we apply MapValueToKey estimator with default parameters, key values | ||
// depends on order of occurence in data file. Which is "Iris-setosa", "Iris-versicolor", "Iris-virginica" | ||
// So if we have Score column equal to [0.2, 0.3, 0.5] that's mean what score for | ||
// Iris-setosa is 0.2 | ||
// Iris-versicolor is 0.3 | ||
// Iris-virginica is 0.5. | ||
Assert.True(slotNames.GetItemOrDefault(0).ToString() == "Iris-setosa"); | ||
Assert.True(slotNames.GetItemOrDefault(1).ToString() == "Iris-versicolor"); | ||
Assert.True(slotNames.GetItemOrDefault(2).ToString() == "Iris-virginica"); | ||
Assert.Equal("Iris-setosa", originalLabels.GetItemOrDefault(0).ToString()); | ||
Assert.Equal("Iris-versicolor", originalLabels.GetItemOrDefault(1).ToString()); | ||
Assert.Equal("Iris-virginica", originalLabels.GetItemOrDefault(2).ToString()); | ||
|
||
// Let's look how we can convert key value for PredictedLabel to original labels. | ||
// We need to read KeyValues for "PredictedLabel" column. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,36 @@ public void OVAUncalibrated() | |
Done(); | ||
} | ||
|
||
/// <summary> | ||
/// Test what OVA preserves key values for label. | ||
/// </summary> | ||
[Fact] | ||
public void OvaKeyNames() | ||
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.
Just curious, I heard something fairly troubling from @eerhardt, could we test this sort of scenario still works for things other than OVA? #Resolved 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. Any tests which use In reply to: 269746627 [](ancestors = 269746627) 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. Can we add this to |
||
{ | ||
var textLoaderOptions = new TextLoader.Options() | ||
{ | ||
Columns = new[] | ||
{ new TextLoader.Column("Label", DataKind.Single, 0), | ||
new TextLoader.Column("Row", DataKind.Single, 1), | ||
new TextLoader.Column("Column", DataKind.Single, 2), | ||
}, | ||
HasHeader = true, | ||
Separators = new[] { '\t' } | ||
}; | ||
var textLoader = ML.Data.CreateTextLoader(textLoaderOptions); | ||
var data = textLoader.Load(GetDataPath(TestDatasets.trivialMatrixFactorization.trainFilename)); | ||
|
||
var ap = ML.BinaryClassification.Trainers.AveragedPerceptron(); | ||
var ova = ML.MulticlassClassification.Trainers.OneVersusAll(ap); | ||
|
||
var pipeline = ML.Transforms.Conversion.MapValueToKey("Label") | ||
.Append(ML.Transforms.Concatenate("Features", "Row", "Column")) | ||
.Append(ova) | ||
.Append(ML.Transforms.Conversion.MapKeyToValue("PredictedLabel")); | ||
|
||
var model = pipeline.Fit(data); | ||
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. We should do something with the model to ensure it was created correctly. #Resolved |
||
} | ||
|
||
/// <summary> | ||
/// Pairwise Coupling trainer | ||
/// </summary> | ||
|
@@ -83,12 +113,14 @@ public void MetacomponentsFeaturesRenamed() | |
var data = loader.Load(GetDataPath(TestDatasets.irisData.trainFilename)); | ||
|
||
var sdcaTrainer = ML.BinaryClassification.Trainers.SdcaNonCalibrated( | ||
new SdcaNonCalibratedBinaryTrainer.Options { | ||
new SdcaNonCalibratedBinaryTrainer.Options | ||
{ | ||
LabelColumnName = "Label", | ||
FeatureColumnName = "Vars", | ||
MaximumNumberOfIterations = 100, | ||
Shuffle = true, | ||
NumberOfThreads = 1, }); | ||
NumberOfThreads = 1, | ||
}); | ||
|
||
var pipeline = new ColumnConcatenatingEstimator(Env, "Vars", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth") | ||
.Append(new ValueToKeyMappingEstimator(Env, "Label"), TransformerScope.TrainTest) | ||
|
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 would probably be good to wrap this in curly braces, now that it is more than one line (and that you have this blank line in between the if and the body.