Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save indraone01/fa5598107d817ed36f8e766167048eb6 to your computer and use it in GitHub Desktop.
Save indraone01/fa5598107d817ed36f8e766167048eb6 to your computer and use it in GitHub Desktop.
This code is part of the ML.NET taxi fare demo
// set up a learning pipeline
var pipeline = mlContext.Transforms.CopyColumns(
inputColumnName:"FareAmount",
outputColumnName:"Label")
// one-hot encode all text features
.Append(mlContext.Transforms.Categorical.OneHotEncoding("VendorId"))
.Append(mlContext.Transforms.Categorical.OneHotEncoding("RateCode"))
.Append(mlContext.Transforms.Categorical.OneHotEncoding("PaymentType"))
// combine all input features into a single column
.Append(mlContext.Transforms.Concatenate(
"Features",
"VendorId",
"RateCode",
"PassengerCount",
"TripDistance",
"PaymentType"))
// cache the data to speed up training
.AppendCacheCheckpoint(mlContext)
// use the fast tree learner
.Append(mlContext.Regression.Trainers.FastTree());
// train the model
Console.Write("Training the model....");
var model = pipeline.Fit(partitions.TrainSet);
Console.WriteLine("done");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment