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

add append function to pipeline #284

Merged
merged 5 commits into from
Jun 11, 2018
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
14 changes: 12 additions & 2 deletions src/Microsoft.ML/LearningPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public LearningPipeline()
/// </summary>
/// <param name="seed">Specify seed for random generator</param>
/// <param name="conc">Specify concurrency factor (default value - autoselection)</param>
internal LearningPipeline(int? seed=null, int conc=0)
internal LearningPipeline(int? seed = null, int conc = 0)
{
_seed = seed;
_conc = conc;
Expand Down Expand Up @@ -109,6 +109,16 @@ internal LearningPipeline(int? seed=null, int conc=0)
/// <param name="item">Any ML component (data loader, transform or trainer) defined as <see cref="ILearningPipelineItem"/>.</param>
public void Add(ILearningPipelineItem item) => Items.Add(item);

/// <summary>
/// Add a data loader, transform or trainer into the pipeline.
/// </summary>
/// <param name="item">Any ML component (data loader, transform or trainer) defined as <see cref="ILearningPipelineItem"/>.</param>
/// <returns>Pipeline with added item</returns>
public LearningPipeline Append(ILearningPipelineItem item)
{
Add(item);
return this;
}
/// <summary>
/// Remove all the loaders/transforms/trainers from the pipeline.
/// </summary>
Expand Down Expand Up @@ -152,7 +162,7 @@ public PredictionModel<TInput, TOutput> Train<TInput, TOutput>()
where TInput : class
where TOutput : class, new()
{
using (var environment = new TlcEnvironment(seed:_seed, conc:_conc))
using (var environment = new TlcEnvironment(seed: _seed, conc: _conc))
{
Experiment experiment = environment.CreateExperiment();
ILearningPipelineStep step = null;
Expand Down
17 changes: 17 additions & 0 deletions test/Microsoft.ML.Tests/LearningPipelineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,22 @@ public void NullableBooleanLabelPipeline()
pipeline.Add(new FastForestBinaryClassifier());
var model = pipeline.Train<Data, Prediction>();
}

[Fact]
public void AppendPipeline()
{
var pipeline = new LearningPipeline();
pipeline.Append(new CategoricalOneHotVectorizer("String1", "String2"))
.Append(new ColumnConcatenator(outputColumn: "Features", "String1", "String2", "Number1", "Number2"))
.Append(new StochasticDualCoordinateAscentRegressor());
Assert.NotNull(pipeline);
Assert.Equal(3, pipeline.Count);

pipeline.Remove(pipeline.ElementAt(2));
Assert.Equal(2, pipeline.Count);

pipeline.Append(new StochasticDualCoordinateAscentRegressor());
Assert.Equal(3, pipeline.Count);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void TrainAndPredictIrisModelTest()
{
string dataPath = GetDataPath("iris.txt");

var pipeline = new LearningPipeline();
var pipeline = new LearningPipeline(seed:1, conc:1);

pipeline.Add(new TextLoader(dataPath).CreateFrom<IrisData>(useHeader: false));
pipeline.Add(new ColumnConcatenator(outputColumn: "Features",
Expand Down