-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Scores to Label mapping #239
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; } | ||
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 | ||
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; } | ||
} | ||
|
||
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") | ||
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>); | ||
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); | ||
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 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); | ||
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 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]; | ||
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(); | ||
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 |
||
|
||
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); | ||
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 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"); | ||
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() | ||
{ | ||
|
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)