0

I am building a multiclass classification program and i want to dynamicaly insert train data from a CSV.

I have tried:

var loader = context.Data.CreateTextLoader(
    new[] 
    {
        new TextLoader.Column("sentiment", DataKind.String,0),

        new TextLoader.Column("content", DataKind.String, 1),
    },
    // First line of the file is a header, not a data row.
    hasHeader: true);

var trainData = loader.Load(_filePath);

var experiment = context.Auto().CreateMulticlassClassificationExperiment(240);

//find best model
var result = experiment.Execute(trainData);
Console.WriteLine(Environment.NewLine);
Console.WriteLine("Best run:");
Console.WriteLine($"Trainer name - {result.BestRun.TrainerName}");

When I run the programm I get this error

System.ArgumentException: 'Provided label column 'Label' not found in training data.'

I know there is a way to create a class on runtime and pass it as a schema in LoadFromText but I haven't been able to make it work yet.

evans
  • 58
  • 8

1 Answers1

0

I think I see what you need. In the Execute method, there's an overload that it can take in a ColumnInformation.

Just create an instance of that and a property on it allows you to specify the label column name.

var labelColumnInfo = new ColumnInformation()
{
    LabelColumnName = "sentiment"
};

Then, you can pass that into the Execute method.

var result = experiment.Execute(trainData, labelColumnInfo);
Jon
  • 2,644
  • 1
  • 22
  • 31
  • Thank you for your answer, i added the code but the application keeps on running after the specified seconds and never prints out the information about the model – evans Feb 10 '20 at 11:25
  • You can pass in a progress handler that should let you know things are going on. Check [this code](https://github.com/jwood803/MLNetExamples/blob/master/MLNetExamples/AutoML/Program.cs#L27) to see how to use it. – Jon Feb 11 '20 at 11:31