Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save indraone01/50ab60ac065cd418b1808fc6379aa9f7 to your computer and use it in GitHub Desktop.
Save indraone01/50ab60ac065cd418b1808fc6379aa9f7 to your computer and use it in GitHub Desktop.
This code is part of the ML.NET taxi fare prediction demo.
/// <summary>
/// The program class.
/// </summary>
class Program
{
// file paths to data files
static readonly string dataPath = Path.Combine(Environment.CurrentDirectory, "yellow_tripdata_2018-12.csv");
/// <summary>
/// The main application entry point.
/// </summary>
/// <param name="args">The command line arguments.</param>
static void Main(string[] args)
{
// create the machine learning context
var mlContext = new MLContext();
// set up the text loader
var textLoader = mlContext.Data.CreateTextLoader(
new TextLoader.Options()
{
Separators = new[] { ',' },
HasHeader = true,
Columns = new[]
{
new TextLoader.Column("VendorId", DataKind.String, 0),
new TextLoader.Column("RateCode", DataKind.String, 5),
new TextLoader.Column("PassengerCount", DataKind.Single, 3),
new TextLoader.Column("TripDistance", DataKind.Single, 4),
new TextLoader.Column("PaymentType", DataKind.String, 9),
new TextLoader.Column("FareAmount", DataKind.Single, 10)
}
}
);
// load the data
Console.Write("Loading training data....");
var dataView = textLoader.Load(dataPath);
Console.WriteLine("done");
// split into a training and test partition
var partitions = mlContext.Regression.TrainTestSplit(dataView, testFraction: 0.2);
// rest of the code goes here...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment