0

Trying to predict a value by giving the model a sample data. In ML.NET it automatically selects the first row of the training data as sample data. I want to select another row or rows but I cant write the values by hand because there are too many columns(239 to be exact).

I tried converting the data which I read from a csv file to IEnumerable and then predict each using foreach.

var data = mlContext.Data.LoadFromTextFile<MLModel1.ModelInput (@"csv file path", ';', true);

IEnumerable<MLModel1.ModelInput> dataEnumerable = mlContext.Data.CreateEnumerable<MLModel1.ModelInput>(data, reuseRowObject: false);

foreach (var item in dataEnumerable)
{
    Console.WriteLine();
    Console.WriteLine("Gerçek Puan: " + item.Puan);
    var sortedScoresWithLabel = MLModel1.PredictAllLabels(item);
    Console.WriteLine($"{"Class",-40}{"Score",-20}");
    Console.WriteLine($"{"-----",-40}{"-----",-20}");

    foreach (var score in sortedScoresWithLabel)
    {
        Console.WriteLine($"{score.Key,-40}{score.Value,-20}");
    }
}

It works but CreateEnumerable method converts some values to NaN randomly. Is there a fix?

values are like this

xeffio
  • 1
  • 1

1 Answers1

0

Its hard to say without seeing some example data, but it looks like some of your features are strings so its possible some contain a stray ";" that is messing up the column ordering, or you have actual null values.

I'd simply try re-creating you data so every field is quoted (unless it already is), and then use optional allowQuoting in LoadFromTextFile() and then give it another go, e.g

var data = mlContext.Data.LoadFromTextFile<MLModel1.ModelInput (@"csv file path", ';', true, allowQuoting: true);

allowQuoting also changes the behavior of how missing values are treated, with its false as yours currently is missing values could be getting loaded in as null, "When false, empty values are denoted by consecutive separators and missing values by the default missing value for each type"

https://learn.microsoft.com/en-us/dotnet/api/microsoft.ml.textloadersavercatalog.loadfromtextfile?view=ml-dotnet

Carsen J
  • 96
  • 3