Make lot of predictions from a file

DJamin 386 Reputation points
2021-09-29T10:54:14.6+00:00

Hello,
I have trained a model and I am able to get a single prediction.
I am trying to read a csv file to make lot of predictions. I am reading each line of this file and I get the content of the 2 columns, then from this I can make the prediction of each line in my input file.
To loop over all the lines and get for each line of the file the predition is very slow... I have tried to make 16k prediction and it took 8 hours.

I am not very familiar with ML.NET and I would like to make it faster.

Here is the code I am using :

string[] lines = System.IO.File.ReadAllLines(filename_in);

            foreach (string line in lines)
            {
                    string[] line_elements = line.Split(";");

                    // The necessary inputs
                    string elem1= line_elements[0];
                    string elem2= line_elements[1];

                    // Create single instance for model input
                    ML_categorie.ModelInput sampleData_categorie = new ML_categorie.ModelInput()
                    {
                        Elem1= elem1,
                        Elem2= elem2,
                    };
                    ML_categorie.ModelOutput result_categorie = ML_categorie.Predict(sampleData_categorie);
                    float predict_categorie = result_categorie.Prediction;
                    string categorie = predict_categorie.ToString();

            }
.NET Machine learning
.NET Machine learning
.NET: Microsoft Technologies based on the .NET software framework.Machine learning: A type of artificial intelligence focused on enabling computers to use observed data to evolve new behaviors that have not been explicitly programmed.
150 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. DJamin 386 Reputation points
    2021-09-30T07:43:38.75+00:00

    I have tried to make multiple Predictions with IdataView from the official example :
    https://learn.microsoft.com/fr-fr/dotnet/machine-learning/how-to-guides/machine-learning-model-predictions-ml-net
    But it doesn't work ...
    I don't know how to link :

    HousingData[] housingData = new HousingData[]  
    IDataView predictions = predictionPipeline.Transform(inputData);  
    

    I am not clear how to declare inputData as a IDataView object ?

    And the last example with PredictionEnginePool is completely impossible to understand.

    0 comments No comments