-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix CV macro to output the warnings data view properly. #385
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 all commits
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 |
---|---|---|
|
@@ -528,6 +528,89 @@ public void TestCrossValidationMacroWithMultiClass() | |
} | ||
Assert.Equal(0, rowCount); | ||
} | ||
|
||
var warnings = experiment.GetOutput(crossValidateOutput.Warnings); | ||
using (var cursor = warnings.GetRowCursor(col => true)) | ||
Assert.False(cursor.MoveNext()); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void TestCrossValidationMacroMultiClassWithWarnings() | ||
{ | ||
var dataPath = GetDataPath(@"Train-Tiny-28x28.txt"); | ||
using (var env = new TlcEnvironment(42)) | ||
{ | ||
var subGraph = env.CreateExperiment(); | ||
|
||
var nop = new ML.Transforms.NoOperation(); | ||
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. Using entrypoints graph is fine for now in C# but please consider not using it and instead call the low level C# APIs for component initialization from now on. We will be getting rid of CSharpCodeGenerator as there is no need to use C# code generated APIs when low level C# APIs already exist. Refer to issue #371 |
||
var nopOutput = subGraph.Add(nop); | ||
|
||
var learnerInput = new ML.Trainers.LogisticRegressionClassifier | ||
{ | ||
TrainingData = nopOutput.OutputData, | ||
NumThreads = 1 | ||
}; | ||
var learnerOutput = subGraph.Add(learnerInput); | ||
|
||
var experiment = env.CreateExperiment(); | ||
var importInput = new ML.Data.TextLoader(dataPath); | ||
var importOutput = experiment.Add(importInput); | ||
|
||
var filter = new ML.Transforms.RowRangeFilter(); | ||
filter.Data = importOutput.Data; | ||
filter.Column = "Label"; | ||
filter.Min = 0; | ||
filter.Max = 5; | ||
var filterOutput = experiment.Add(filter); | ||
|
||
var term = new ML.Transforms.TextToKeyConverter(); | ||
term.Column = new[] | ||
{ | ||
new ML.Transforms.TermTransformColumn() | ||
{ | ||
Source = "Label", Name = "Strat", Sort = ML.Transforms.TermTransformSortOrder.Value | ||
} | ||
}; | ||
term.Data = filterOutput.OutputData; | ||
var termOutput = experiment.Add(term); | ||
|
||
var crossValidate = new ML.Models.CrossValidator | ||
{ | ||
Data = termOutput.OutputData, | ||
Nodes = subGraph, | ||
Kind = ML.Models.MacroUtilsTrainerKinds.SignatureMultiClassClassifierTrainer, | ||
TransformModel = null, | ||
StratificationColumn = "Strat" | ||
}; | ||
crossValidate.Inputs.Data = nop.Data; | ||
crossValidate.Outputs.PredictorModel = learnerOutput.PredictorModel; | ||
var crossValidateOutput = experiment.Add(crossValidate); | ||
|
||
experiment.Compile(); | ||
importInput.SetInput(env, experiment); | ||
experiment.Run(); | ||
var warnings = experiment.GetOutput(crossValidateOutput.Warnings); | ||
|
||
var schema = warnings.Schema; | ||
var b = schema.TryGetColumnIndex("WarningText", out int warningCol); | ||
Assert.True(b); | ||
using (var cursor = warnings.GetRowCursor(col => col == warningCol)) | ||
{ | ||
var getter = cursor.GetGetter<DvText>(warningCol); | ||
|
||
b = cursor.MoveNext(); | ||
Assert.True(b); | ||
var warning = default(DvText); | ||
getter(ref warning); | ||
Assert.Contains("test instances with class values not seen in the training set.", warning.ToString()); | ||
b = cursor.MoveNext(); | ||
Assert.True(b); | ||
getter(ref warning); | ||
Assert.Contains("Detected columns of variable length: SortedScores, SortedClasses", warning.ToString()); | ||
b = cursor.MoveNext(); | ||
Assert.False(b); | ||
} | ||
} | ||
} | ||
|
||
|
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.
maybe NaN?
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.
NaN means not a number but if instances are zero then isn't it accurate to say accuracy is zero?
In reply to: 196921243 [](ancestors = 196921243)