Forked from mdfarragher/mlnet-taxidemo-createmodel.cs
Created
March 10, 2022 01:21
-
-
Save indraone01/fa5598107d817ed36f8e766167048eb6 to your computer and use it in GitHub Desktop.
This code is part of the ML.NET taxi fare demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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