-
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
094df6a
Scores to label mapping for multi-class classification problem.
codemzs 3ea2793
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs f067e0f
update test.
codemzs 2e11917
Merge branch 'master' of https://github.com/dotnet/machinelearning in…
codemzs 431117d
PR feedback.
codemzs ef46c6c
PR feedback.
codemzs 6eae0b6
cleanup.
codemzs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,14 @@ public sealed class TransformModel : ITransformModel | |
/// if transform model A needs column X and model B needs Y, that is NOT produced by A, | ||
/// then trimming A's input schema would cause composition to fail. | ||
/// </summary> | ||
public ISchema InputSchema | ||
{ | ||
get { return _schemaRoot; } | ||
} | ||
public ISchema InputSchema => _schemaRoot; | ||
|
||
/// <summary> | ||
/// The resulting schema once applied to this model. The <see cref="InputSchema"/> might have | ||
/// columns that are not needed by this transform and these columns will be seen in the | ||
/// <see cref="OutputSchema"/> produced by this transform. | ||
/// </summary> | ||
public ISchema OutputSchema => _chain.Schema; | ||
|
||
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". | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using Microsoft.ML.Runtime.Api; | ||
using Microsoft.ML.Runtime.Data; | ||
using Microsoft.ML.Runtime.EntryPoints; | ||
using Microsoft.ML.Runtime.Internal.Utilities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
@@ -29,6 +30,40 @@ 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="names">Label to score mapping</param> | ||
/// <param name="scoreColumnName">Name of the score column</param> | ||
/// <returns></returns> | ||
public bool TryGetScoreLabelNames(out string[] names, string scoreColumnName = DefaultColumnNames.Score) | ||
{ | ||
names = null; | ||
ISchema schema = _predictorModel.OutputSchema; | ||
int colIndex = -1; | ||
if (!schema.TryGetColumnIndex(scoreColumnName, out colIndex)) | ||
return false; | ||
|
||
int expectedLabelCount = schema.GetColumnType(colIndex).ValueCount; | ||
if (!schema.HasSlotNames(colIndex, expectedLabelCount)) | ||
return false; | ||
|
||
VBuffer<DvText> labels = default; | ||
schema.GetMetadata(MetadataUtils.Kinds.SlotNames, colIndex, ref labels); | ||
|
||
if (labels.Length != expectedLabelCount) | ||
return false; | ||
|
||
names = new string[expectedLabelCount]; | ||
int index = 0; | ||
foreach(var label in labels.DenseValues()) | ||
names[index++] = label.ToString(); | ||
|
||
|
||
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> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ahh good. I'm half tempted to compose a regular expression to see how many of these beauties had slipped into the XML docs. :P :D #ByDesign