예제 #1
0
파일: ML.cs 프로젝트: actopozipc/Telluz
        public async Task <List <YearWithValue> > PredictCo2OverYearsAsync(Model modelContainer, int futureYear, int coa_id, List <YearWithValue> emissions, CNTK cNTK)
        {
            //Get Population till future year
            List <YearWithValue> population = await dB.GetPopulationByCoaIdAsync(coa_id);       //get population that is known

            if (CompareBiggestValueToFutureYear(population, futureYear))                        //check if known population is enough to predict emission
            {
                population = await cNTK.PredictPopulationAsync(coa_id, futureYear, population); //get population to predict emission
            }
            EmissionModel[] populationData = new EmissionModel[population.Count];
            for (int i = 0; i < populationData.Count(); i++)
            {
                populationData[i] = new EmissionModel()
                {
                    Year = population[i].Year, Population = population[i].Value.value
                };
            }
            PredictionEngine <EmissionModel, EmissionPrediction> predictionEngine = modelContainer.mLContext.Model.CreatePredictionEngine <EmissionModel, EmissionPrediction>(modelContainer.trainedModel);
            IDataView inputData   = modelContainer.mLContext.Data.LoadFromEnumerable(populationData);
            IDataView predictions = modelContainer.trainedModel.Transform(inputData);

            float[] scoreColumn = predictions.GetColumn <float>("Score").ToArray();

            for (int i = emissions.Count; i < scoreColumn.Length; i++)
            {
                emissions.Add(new YearWithValue(population[i].Year, new Wert(scoreColumn[i], true)));
            }
            return(emissions);
        }
예제 #2
0
파일: ML.cs 프로젝트: actopozipc/Telluz
        public static YearWithValue PredictCo2(MLContext mlContext, ITransformer model, float year, float population)
        {
            var predictionFunction = mlContext.Model.CreatePredictionEngine <EmissionModel, EmissionPrediction>(model);
            var test = new EmissionModel()
            {
                Year = year, Population = population
            };
            var prediction = predictionFunction.Predict(test);

            return(new YearWithValue(year, new Wert(prediction.Co2, true)));
        }