diff --git a/src/Microsoft.ML.Core/Utilities/Random.cs b/src/Microsoft.ML.Core/Utilities/Random.cs index 9590d96600..88dd45209f 100644 --- a/src/Microsoft.ML.Core/Utilities/Random.cs +++ b/src/Microsoft.ML.Core/Utilities/Random.cs @@ -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); } } diff --git a/src/Microsoft.ML/LearningPipeline.cs b/src/Microsoft.ML/LearningPipeline.cs index 87389077ed..51677afbf4 100644 --- a/src/Microsoft.ML/LearningPipeline.cs +++ b/src/Microsoft.ML/LearningPipeline.cs @@ -154,23 +154,29 @@ public PredictionModel Train() step = currentItem.ApplyStep(step, experiment); if (step is ILearningPipelineDataStep dataStep && dataStep.Model != null) transformModels.Add(dataStep.Model); - + else if (step is ILearningPipelinePredictorStep predictorDataStep) { if (lastTransformModel != null) transformModels.Insert(0, lastTransformModel); - var localModelInput = new Transforms.ManyHeterogeneousModelCombiner + Var predictorModel; + if (transformModels.Count != 0) { - PredictorModel = predictorDataStep.Model, - TransformModels = new ArrayVar(transformModels.ToArray()) - }; - - var localModelOutput = experiment.Add(localModelInput); + var localModelInput = new Transforms.ManyHeterogeneousModelCombiner + { + PredictorModel = predictorDataStep.Model, + TransformModels = new ArrayVar(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); diff --git a/test/Microsoft.ML.Tests/LearningPipelineTests.cs b/test/Microsoft.ML.Tests/LearningPipelineTests.cs index 30dd844d58..ec7a6b6e92 100644 --- a/test/Microsoft.ML.Tests/LearningPipelineTests.cs +++ b/test/Microsoft.ML.Tests/LearningPipelineTests.cs @@ -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; @@ -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(); + } } }