private void DoMechineLearning() { var label = from w in _context.EmoVarData where w.評分 == null select w; foreach (var labellist in label) { EmoData emo = new EmoData { Sleep = Convert.ToInt32(labellist.入睡), Sleeptime = Convert.ToInt32(labellist.時常), AvgHeartRate = Convert.ToInt32(labellist.平均), SocialApp = Convert.ToSingle(labellist.社交軟體), GameApp = Convert.ToSingle(labellist.遊戲軟體), FunApp = Convert.ToSingle(labellist.娛樂軟體), OtherApp = Convert.ToSingle(labellist.其他軟體), Temperture = Convert.ToInt32(labellist.溫度), Humidity = Convert.ToInt32(labellist.濕度), //sunshine == Rain,日照 == 雨量 Sunshine = Convert.ToInt32(labellist.日照), Airquality = Convert.ToInt32(labellist.空氣品質) }; using (var scope = scopeFactory.CreateScope()) { _prediction = scope.ServiceProvider.GetRequiredService <PredictionEnginePool <EmoData, EmoPredict> >(); var res = _prediction.Predict(emo); labellist.評分 = res.Score; } } _context.SaveChanges(); }
public string Post([FromBody] EmoData input) { EmoPredict prediction = _predictionEnginePool.Predict(input); //string sentiment = Convert.ToBoolean(prediction.PredictionLabel) ? "Positive" : "Negative"; return(prediction.Score); }