MLNetAutoMLAPIConsole.cs
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
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