我正在尝试创建一个应用程序,该应用程序根据用户的生活方式和药物的限制来预测服药时间。
我的意思是:
我从患者身上获得以下信息:
•他/她多少次进餐?
•他/她什么时候醒来入睡
•他/她必须服用多少药
从药物方面的限制:
•是空腹应该吃的药吗
•是否应随餐一起吃药?
•患者是否需要在用餐和服药之间稍作休息(尚未在下面的屏幕上显示)
•等
样本数据集:
https://ibb.co/Gvry945
我应该使用哪种类型的模型/力学/算法来预测服药时间?回归正确吗?我需要预测1,2,3,4有时5列。
我基于以下内容编写了一个简单的代码:
https://docs.microsoft.com/pl-pl/dotnet/machine-learning/tutorials/predict-prices
How to predict multiple labels with ML.NET using regression task?
工作正常,我可以预测超过1列。但是,我的问题仍然是空白单元格。当我试图从这些数据中预测某些数据时,它总是显示错误的值,并且只有在所有单元格都完整后才能正常工作。
那么,我应该将我的数据集散布到更少的数据集(所有单元格都完整)吗?例如:
https://ibb.co/m8HVPvb
当我只预测TimeToTakeMedicine1
https://ibb.co/qNk9xQL
当我预测TimeToTakeMedicine1和TimeToTakeMedicine2
https://ibb.co/GnRc1c0
当我预测TimeToTakeMedicine1,TimeToTakeMedicine2,TimeToTakeMedicine3等时。
有没有更简单,更好的方法来解决这个问题?
用于预测TimeToTakeMedicine1,TimeToTakeMedicine2,TimeToTakeMedicine3的工作代码(为简单起见,我摆脱了OnEmptyStomach,WithMeal和IsPossible)
using System;
using System.IO;
using Microsoft.ML;
using Microsoft.ML.Trainers;
namespace NextTry
{
class Program
{
static readonly string _trainDataPath = Path.Combine(Environment.CurrentDirectory, "DataFolder", "DataForPredictT1T2T3.csv");
static void Main(string[] args)
{
MLContext mlContext = new MLContext(seed: 0);
var model = Train(mlContext, _trainDataPath);
TestSinglePrediction(mlContext, model);
}
public static ITransformer Train(MLContext mlContext, string dataPath)
{
IDataView dataView = mlContext.Data.LoadFromTextFile<Medicine>(dataPath, hasHeader: true, separatorChar: ',');
var pipelineForMeal1 = mlContext.Transforms.CopyColumns(outputColumnName: "Label", inputColumnName: "TimeToTakeMedicine1")
.Append(mlContext.Transforms.Concatenate("Features", "MealTime1", "MealTime2", "MealTime3", "MealCount", "ActivityHoursWakeUp", "ActivityHoursSleep", "PillsCount"))
.Append(mlContext.Regression.Trainers.FastTree())
.Append(mlContext.Transforms.CopyColumns(outputColumnName: "timeToTakeMedicine1", inputColumnName: "Score"));
var pipelineForMeal2 = mlContext.Transforms.CopyColumns(outputColumnName: "Label", inputColumnName: "TimeToTakeMedicine2")
.Append(mlContext.Transforms.Concatenate("Features", "MealTime1", "MealTime2", "MealTime3", "MealCount", "ActivityHoursWakeUp", "ActivityHoursSleep", "PillsCount"))
.Append(mlContext.Regression.Trainers.FastTree())
.Append(mlContext.Transforms.CopyColumns(outputColumnName: "timeToTakeMedicine2", inputColumnName: "Score"));
var pipelineForMeal3 = mlContext.Transforms.CopyColumns(outputColumnName: "Label", inputColumnName: "TimeToTakeMedicine3")
.Append(mlContext.Transforms.Concatenate("Features", "MealTime1", "MealTime2", "MealTime3", "MealCount", "ActivityHoursWakeUp", "ActivityHoursSleep", "PillsCount"))
.Append(mlContext.Regression.Trainers.FastTree())
.Append(mlContext.Transforms.CopyColumns(outputColumnName: "timeToTakeMedicine3", inputColumnName: "Score"));
var model = pipelineForMeal1
.Append(pipelineForMeal2)
.Append(pipelineForMeal3)
.Fit(dataView);
return model;
}
private static void TestSinglePrediction(MLContext mlContext, ITransformer model)
{
var predictionFunction = mlContext.Model.CreatePredictionEngine<Medicine, MedicineTimeTakeMedicinePrediction>(model);
var medicineSample = new Medicine()
{
MealTime1 = 6,
MealTime2 = 12,
MealTime3 = 22,
MealCount = 3,
PillsCount = 3
};
var prediction = predictionFunction.Predict(medicineSample);
Console.WriteLine($"Predicted TimeToTakePill: {prediction.TimeToTakeMedicine1:0.####} ");
Console.WriteLine($"Predicted TimeToTakePill: {prediction.TimeToTakeMedicine2:0.####}");
Console.WriteLine($"Predicted TimeToTakePill: {prediction.TimeToTakeMedicine3:0.####}");
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ML.Data;
namespace NextTry
{
public class Medicine
{
[LoadColumn(0)]
public float MealTime1 { get; set; }
[LoadColumn(1)]
public float MealTime2 { get; set; }
[LoadColumn(2)]
public float MealTime3 { get; set; }
[LoadColumn(3)]
public float MealCount { get; set; }
[LoadColumn(4)]
public float ActivityHoursWakeUp { get; set; }
[LoadColumn(5)]
public float ActivityHoursSleep { get; set; }
[LoadColumn(6)]
public float PillsCount { get; set; }
[LoadColumn(7)]
public float TimeToTakeMedicine1 { get; set; }
[LoadColumn(8)]
public float TimeToTakeMedicine2 { get; set; }
[LoadColumn(9)]
public float TimeToTakeMedicine3 { get; set; }
}
public class MedicineTimeTakeMedicinePrediction
{
[ColumnName("timeToTakeMedicine1")]
public float TimeToTakeMedicine1 { get; set; }
[ColumnName("timeToTakeMedicine2")]
public float TimeToTakeMedicine2 { get; set; }
[ColumnName("timeToTakeMedicine3")]
public float TimeToTakeMedicine3 { get; set; }
}
}
答案 0 :(得分:0)
我遇到了同样的问题。您要做的一件事是,将具有相同功能的所有模型立即附加到一个管道中。