-
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
Prevent learning pipeline from adding null transform model to the pipeline #154
Changes from 2 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 |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.ML; | ||
using Microsoft.ML.Runtime.Api; | ||
using Microsoft.ML.TestFramework; | ||
using Microsoft.ML.Transforms; | ||
using System.Linq; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
@@ -42,5 +44,40 @@ public void CanAddAndRemoveFromPipeline() | |
pipeline.Add(new Trainers.StochasticDualCoordinateAscentRegressor()); | ||
Assert.Equal(3, pipeline.Count); | ||
} | ||
|
||
class InputData | ||
{ | ||
[Column(ordinal: "1")] | ||
public string F1; | ||
} | ||
|
||
class TransformedData | ||
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. explicit access modifer, same for class above #Closed |
||
{ | ||
[ColumnName("F1")] | ||
public float[] TransformedF1; | ||
} | ||
|
||
[Fact] | ||
public void TransformOnlyPipeline() | ||
{ | ||
const string _dataPath = @"..\..\Data\breast-cancer.txt"; | ||
var pipeline = new LearningPipeline(); | ||
pipeline.Add(new TextLoader<InputData>(_dataPath, useHeader: false)); | ||
pipeline.Add(new CategoricalHashOneHotVectorizer("F1") { HashBits = 10, Seed = 314489979, OutputKind = CategoricalTransformOutputKind.Bag }); | ||
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 this issue only affecting transforms only pipeline? 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. yeah |
||
var model = pipeline.Train<InputData, TransformedData>(); | ||
var predictionModel = model.Predict(new InputData() { F1 = "5" }); | ||
|
||
Assert.NotNull(predictionModel); | ||
Assert.NotNull(predictionModel.TransformedF1); | ||
Assert.Equal(1024, predictionModel.TransformedF1.Length); | ||
|
||
for (int index = 0; index < 1024; index++) | ||
if (index == 265) | ||
Assert.Equal(1, predictionModel.TransformedF1[index]); | ||
else | ||
Assert.Equal(0, predictionModel.TransformedF1[index]); | ||
|
||
predictionModel.TransformedF1 = null; | ||
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.
out of curiosity, why? #Closed 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. compiler warning that is treated as an error. 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. fixed. |
||
} | ||
} | ||
} |
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.
would be nice to add test coverage
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.
Done.