/// <summary> /// Use your model to make a prediction /// You can change these numbers to test different predictions /// </summary> /// <typeparam name="TSrc"></typeparam> /// <typeparam name="TDst"></typeparam> /// <param name="dataPath"></param> /// <param name="parameters"></param> /// <param name="inputData"></param> /// <returns></returns> public static TDst Predict <TSrc, TDst>(string dataPath, string[] parameters, TSrc inputData) where TSrc : class where TDst : class, new() { // Create a ML.NET environment MLContext mlContext = new MLContext(); IDataView trainingDataView = mlContext.LoadTrainingData <TSrc>(dataPath, inputData); EstimatorChain <KeyToValueMappingTransformer> learningPipeline = mlContext.GetLearningPipeline(parameters); TransformerChain <KeyToValueMappingTransformer> model = trainingDataView.TrainModel(learningPipeline); PredictionFunction <TSrc, TDst> prediction = model.MakePredictionFunction <TSrc, TDst>(mlContext); TDst result = prediction.Predict(inputData); return(result); }