Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created June 23, 2018 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/8eef3e798ad7492dd27295d3a0298d7e to your computer and use it in GitHub Desktop.
Save NMZivkovic/8eef3e798ad7492dd27295d3a0298d7e to your computer and use it in GitHub Desktop.
public sealed class ModelBuilder
{
private readonly string _trainingDataLocation;
private readonly ILearningPipelineItem _algorythm;
public ModelBuilder(string trainingDataLocation, ILearningPipelineItem algorythm)
{
_trainingDataLocation = trainingDataLocation;
_algorythm = algorythm;
}
/// <summary>
/// Using training data location that is passed trough constructor this method is building
/// and training machine learning model.
/// </summary>
/// <returns>Trained machine learning model.</returns>
public PredictionModel<BikeSharingDemandSample, BikeSharingDemandPrediction> BuildAndTrain()
{
var pipeline = new LearningPipeline();
pipeline.Add(new TextLoader(_trainingDataLocation).CreateFrom<BikeSharingDemandSample>(useHeader: true, separator: ','));
pipeline.Add(new ColumnCopier(("Count", "Label")));
pipeline.Add(new ColumnConcatenator("Features",
"Season",
"Year",
"Month",
"Hour",
"Weekday",
"Weather",
"Temperature",
"NormalizedTemperature",
"Humidity",
"Windspeed"));
pipeline.Add(_algorythm);
return pipeline.Train<BikeSharingDemandSample, BikeSharingDemandPrediction>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment