question

DJamin-2804 avatar image
0 Votes"
DJamin-2804 asked DJamin-2804 edited

Make lot of predictions from a file

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();
    
             }
dotnet-mlnet
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DJamin-2804 avatar image
0 Votes"
DJamin-2804 answered DJamin-2804 edited

OK I have succeeded to make it work by using proper parts of the DataView code here :
https://docs.microsoft.com/fr-fr/dotnet/api/microsoft.ml.idataview?view=ml-dotnet
I can run the 16k predictions in few seconds.
I don't need the PredictionEnginePool as I am fine with the DatView solution.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DJamin-2804 avatar image
0 Votes"
DJamin-2804 answered

I have tried to make multiple Predictions with IdataView from the official example :
https://docs.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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.