'How to create one PredictEnginePool which serves multiple models?

My project is an online foods order app, the key feature of this app is the "Daily nutrients intake monitor". This monitor shows the differences of daily intake recommendation values of 30 types of nutrients vs the actual nutrients contains from the foods in user's shoppingcart.

I created 30 models base on those nutrients and each one of them has an InputData which inherits from a base class - NutrientInputDataBase, below is the example of Added sugar InputData class and the base class:

public class AddedSugarUlInputData : NutrientInputDataBase
{
    [ColumnName(@"AddedSugar-AMDR-UL")]
    public float AddedSugar_AMDR_UL { get; set; }
}

public class NutrientInputDataBase
{
    [ColumnName(@"Sex")]
    public float Sex { get; set; }

    [ColumnName(@"Age")]
    public float Age { get; set; }

    [ColumnName(@"Activity")]
    public float Activity { get; set; }

    [ColumnName(@"BMI")]
    public float BMI { get; set; }

    [ColumnName(@"Disease")]
    public float Disease { get; set; }
}

From the official documents: https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/serve-model-web-api-ml-net i understood that i need to create a 'PredictionEnginePool' and i already know how to register the PredictionEnginePool in the application startup file. My app logic is when user added or removed an item from the shoppingcart, the front end will request the api, the backend will get the user profile first(to obtain the input data for the prediction), then return a packaged objects which contains all 30 types of nutrients prediction results.

My question is, should i register the PredictionEnginePool for each one of the nutrient model individually in the Startup file? or in anyother effecient way which i haven't be awared of?



Solution 1:[1]

There's multiple ways for you to go about it.

  1. Register each of your models PredictionEnginePool. The FromFile and FromUri methods allow you to specify a name for each of your models so when you use them to make predictions in your application you can reference them by name.

  2. Save your model to a database as a blob. Then you can add logic on your application to load a specific model based on the criteria you specify. The downside to this is you'd have to fetch your models more dynamically rather than having a PredictionEnginePool ready to go.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luis Quintanilla