-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Scores to Label mapping #239
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 3 commits
094df6a
3ea2793
f067e0f
2e11917
431117d
ef46c6c
6eae0b6
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 |
|---|---|---|
|
|
@@ -25,6 +25,10 @@ public interface ITransformModel | |
| /// </summary> | ||
| ISchema InputSchema { get; } | ||
|
|
||
| /// <summary> | ||
| /// Schema of the transform model. | ||
| /// </summary> | ||
| IDataView Schema { get; } | ||
|
Contributor
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. I think the name |
||
| /// <summary> | ||
| /// Apply the transform(s) in the model to the given input data. | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,14 @@ public ISchema InputSchema | |
| get { return _schemaRoot; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Schema of the transform model. | ||
| /// </summary> | ||
| public IDataView Schema | ||
|
Contributor
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.
A data view is not a schema. #Closed |
||
| { | ||
| get { return _chain; } | ||
| } | ||
|
|
||
|
Contributor
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. Remember we now have C# 7.x's niceties available to us. #Closed |
||
| /// <summary> | ||
| /// Create a TransformModel containing the transforms from "result" back to "input". | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,33 @@ internal Runtime.EntryPoints.TransformModel PredictorModel | |
| get { return _predictorModel; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns labels that correspond to indices of the score array in the case of | ||
| /// multi-class classification problem. | ||
| /// </summary> | ||
| /// <param name="mapping">Label to score mapping</param> | ||
| /// <param name="scoreColumnName">Name of the score column</param> | ||
| /// <returns></returns> | ||
| public bool TryGetScoreLabelMapping(out string[] mapping, string scoreColumnName = "Score") | ||
|
Contributor
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.
DefaultColumnNames.Score maybe? #Resolved |
||
| { | ||
| mapping = null; | ||
| IDataView idv = _predictorModel.Schema; | ||
| int colIndex = -1; | ||
| if (!idv.Schema.TryGetColumnIndex(scoreColumnName, out colIndex)) | ||
| return false; | ||
|
|
||
| VBuffer<DvText> labels = default(VBuffer<DvText>); | ||
|
Contributor
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 be just |
||
| idv.Schema.GetMetadata(MetadataUtils.Kinds.SlotNames, colIndex, ref labels); | ||
|
Contributor
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.
TryGetMetadata? #Resolved
Contributor
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. Right, because this is a In reply to: 190754868 [](ancestors = 190754868) |
||
|
|
||
| Contracts.Assert(labels.IsDense); | ||
|
Contributor
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 can't assume that it is dense, and a
Contributor
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. |
||
|
|
||
| mapping = new string[labels.Count]; | ||
|
Contributor
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.
Length. #Closed |
||
| for (int index = 0; index < labels.Count; index++) | ||
| mapping[index] = labels.Values[index].ToString(); | ||
|
Contributor
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. Rephrase as enumeration over |
||
|
|
||
|
Contributor
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. nit: extra lines #Resolved |
||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Read model from file asynchronously. | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,14 @@ public void TrainAndPredictIrisModelWithStringLabelTest() | |
| pipeline.Add(new StochasticDualCoordinateAscentClassifier()); | ||
|
|
||
| PredictionModel<IrisDataWithStringLabel, IrisPrediction> model = pipeline.Train<IrisDataWithStringLabel, IrisPrediction>(); | ||
| string[] scoreLabels; | ||
| model.TryGetScoreLabelMapping(out scoreLabels); | ||
|
Contributor
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.
Why I can't just define and fill it automatically if it's possible? #Resolved
Contributor
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 reply to: 190754719 [](ancestors = 190754719) |
||
|
|
||
| Assert.NotNull(scoreLabels); | ||
| Assert.Equal(3, scoreLabels.Length); | ||
| Assert.True(scoreLabels[0] == "Iris-setosa"); | ||
| Assert.True(scoreLabels[1] == "Iris-versicolor"); | ||
| Assert.True(scoreLabels[2] == "Iris-virginica"); | ||
|
Contributor
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. I see you know about |
||
|
|
||
| IrisPrediction prediction = model.Predict(new IrisDataWithStringLabel() | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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 comment, even if the thing were fixed to return an
ISchema, is rather odd because models don't have schema. They only have schema once applied to model. You will need something like the above description ofInputSchema, that clarifies the status of this. "Schema of the transform model" is not a meaningful statement. #ClosedThere 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'll also probably want to name it
OutputSchema, since it serves a similar purpose toInputSchema.In reply to: 190936953 [](ancestors = 190936953)