Skip to content
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

no need to add combiner if you don't have transforms. #172

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Core/Utilities/Random.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public int NextSigned()
{
// Note that, according to the documentation for System.Random,
// this won't ever achieve int.MaxValue, but oh well.
return _rnd.Next(int.MinValue, int.MinValue);
return _rnd.Next(int.MinValue, int.MaxValue);
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/Microsoft.ML/LearningPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,29 @@ public PredictionModel<TInput, TOutput> Train<TInput, TOutput>()
step = currentItem.ApplyStep(step, experiment);
if (step is ILearningPipelineDataStep dataStep && dataStep.Model != null)
transformModels.Add(dataStep.Model);

else if (step is ILearningPipelinePredictorStep predictorDataStep)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think this change here was unintentional. :D

Copy link
Contributor Author

@Ivanidzo4ka Ivanidzo4ka May 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ctrl+k+d this file, and this is what VS produce to me. It just replace line full of spaces to empty line. #ByDesign

Copy link
Contributor

@TomFinley TomFinley May 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather you hadn't inserted two completely empty lines here at all. :D


In reply to: 188751411 [](ancestors = 188751411)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FALSE ALLEGATIONS! It's actually specific of codeflow. If you look on github PR or merge code, you will see it has only one line, and first line actually suppose to be removed, but for some reason codeflow mark it as yellow instead of red (addition instead of deletion.


In reply to: 188834888 [](ancestors = 188834888,188751411)

{
if (lastTransformModel != null)
transformModels.Insert(0, lastTransformModel);

var localModelInput = new Transforms.ManyHeterogeneousModelCombiner
Var<IPredictorModel> predictorModel;
if (transformModels.Count != 0)
{
PredictorModel = predictorDataStep.Model,
TransformModels = new ArrayVar<ITransformModel>(transformModels.ToArray())
};

var localModelOutput = experiment.Add(localModelInput);
var localModelInput = new Transforms.ManyHeterogeneousModelCombiner
{
PredictorModel = predictorDataStep.Model,
TransformModels = new ArrayVar<ITransformModel>(transformModels.ToArray())
};
var localModelOutput = experiment.Add(localModelInput);
predictorModel = localModelOutput.PredictorModel;
}
else
predictorModel = predictorDataStep.Model;

var scorer = new Transforms.Scorer
{
PredictorModel = localModelOutput.PredictorModel
PredictorModel = predictorModel
};

var scorerOutput = experiment.Add(scorer);
Expand Down
31 changes: 31 additions & 0 deletions test/Microsoft.ML.Tests/LearningPipelineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// See the LICENSE file in the project root for more information.

using Microsoft.ML;
using Microsoft.ML.Data;
using Microsoft.ML.Runtime.Api;
using Microsoft.ML.TestFramework;
using Microsoft.ML.Trainers;
using Microsoft.ML.Transforms;
using System.Linq;
using Xunit;
Expand Down Expand Up @@ -79,5 +81,34 @@ public void TransformOnlyPipeline()
else
Assert.Equal(0, predictionModel.TransformedF1[index]);
}

public class Data
{
[ColumnName("Features")]
[VectorType(2)]
public float[] Features;

[ColumnName("Label")]
public float Label;
}

public class Prediction
{
[ColumnName("PredictedLabel")]
public bool PredictedLabel;
}

[Fact]
public void NoTransformPipeline()
{
var data = new Data[1];
data[0] = new Data();
data[0].Features = new float[] { 0.0f, 1.0f };
data[0].Label = 0f;
var pipeline = new LearningPipeline();
pipeline.Add(CollectionDataSource.Create(data));
pipeline.Add(new FastForestBinaryClassifier());
var model = pipeline.Train<Data, Prediction>();
}
}
}