Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created May 15, 2019 20:00
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 elbruno/de5a414475f593300507a8e12000fd0e to your computer and use it in GitHub Desktop.
Save elbruno/de5a414475f593300507a8e12000fd0e to your computer and use it in GitHub Desktop.
MLNetAutoMLAPIConsole.cs
private const uint ExperimentTime = 180;
static void Main(string[] args)
{
var mlContext = new MLContext();
Train(mlContext);
Console.WriteLine("Process complete! Press any key to close the app.");
Console.ReadKey();
}
public static void Train(MLContext mlContext)
{
try
{
// STEP 1: Load the data
var trainData = mlContext.Data.LoadFromTextFile(path: "AgeRangeData03_AgeGenderLabelEncodedMoreData.csv",
columns: new[]
{
new TextLoader.Column("Age", DataKind.Single, 0),
new TextLoader.Column("Gender", DataKind.Single, 1)
,
new TextLoader.Column("Label", DataKind.Single, 2)
},
hasHeader: true,
separatorChar: ','
);
var progressHandler = new MulticlassExperimentProgressHandler();
ConsoleHelper.ConsoleWriteHeader("=============== Running AutoML experiment ===============");
Console.WriteLine($"Running AutoML multiclass classification experiment for {ExperimentTime} seconds...");
ExperimentResult<MulticlassClassificationMetrics> experimentResult = mlContext.Auto()
.CreateMulticlassClassificationExperiment(ExperimentTime)
.Execute(trainData, "Label", progressHandler: progressHandler);
// Print top models found by AutoML
Console.WriteLine();
PrintTopModels(experimentResult);
Console.WriteLine();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment