我创建了一个ML项目。 我的数据集看起来像这样:
DateTime,DoorStatus,Metal_Temp,Burner_Input,Current_Roof_Temp,Roof_Temp_SetPo
23:35:00, 1, ,70.48548126, 678.4678345, 1142.275269
23:39:00, 1, ,99.99752045, 746.8652344, 1150
23:40:00, 1, ,100, 761.4857178, 1150
23:41:00, 1, 649 ,100, 768.6276855, 1150
23:42:00, 1, 650 ,100, 790.663208, 1150
23:43:00, 1, 651 ,100, 797.7381592, 1150
23:44:00, 1, 653 ,100, 817.0432129, 1150
23:45:00, 1, ,100, 847.1066895, 1150
23:46:00, 1, 656 ,100, 860.579834, 1150
23:47:00, 1, 657 ,100, 908.4719238, 1150
23:48:00, 1, 659 ,100, 936.2180176, 1150
23:49:00, 1, ,100, 945.9560547, 1150
23:50:00, 1, 663 ,100, 946.496582, 1150
23:51:00, 1, 664 ,100, 955.3989258, 1150
23:52:00, 1, 666 ,100, 974.0750732, 1150
23:53:00, 1, 668 ,100, 981.1708984, 1150
23:54:00, 1, 669 ,100, 996.7823486, 1150
该代码在编译和运行方面运行良好,但是它产生的预测结果与我的预期相去甚远! 我试图通过输入时间,门状态,燃烧器输入和当前屋顶温度,设定点来预测Metal_Temp。预测输出Im得到例如。 0.012546、0.014568。
static void Main(string[] args)
{
MLContext mLContext = new MLContext(seed: 0);
var model = Train(mLContext, @"C:\Projects\DotNetCoreProjects\MetalTempPredict\MetalTempPredict\Data\*");
int x = 1;
int y = 0;
while (x > y)
{
TestSinglePredicition(mLContext, model);
x = x + 1;
y = y + 1;
};
}
public static ITransformer Train(MLContext mLContext, string dataPath)
{
IDataView dataView = mLContext.Data.LoadFromTextFile<LargData>(@"C:\Projects\DotNetCoreProjects\MetalTempPredict\MetalTempPredict\Data\*", hasHeader: true, separatorChar: ',');
var pipeline = mLContext.Transforms.CopyColumns(outputColumnName: "Label", inputColumnName: "Metal_Temp")
.Append(mLContext.Transforms.Categorical.OneHotHashEncoding(outputColumnName: "date_timeEnocded", inputColumnName: "date_time"))
.Append(mLContext.Transforms.Categorical.OneHotEncoding(outputColumnName: "DoorStatusEncoded", inputColumnName: "DoorStatus"))
.Append(mLContext.Transforms.Concatenate("Features", "DoorStatusEncoded", "date_timeEnocded", "Metal_Temp", "Burner_Input", "Current_Roof_Temp", "Roof_Temp_SetPoint"))
.Append(mLContext.Regression.Trainers.FastTree());
var model = pipeline.Fit(dataView);
mLContext.Model.Save(model, dataView.Schema, @"C:\Projects\DotNetCoreProjects\MetalTempPredict\MetalTempPredict\Data\Files" + DateTime.Now.ToString("yyyy - MM - dd HH - mm - ss") + ".zip");
return model;
}
private static void Evaluate(MLContext mLContext, ITransformer model)
{
IDataView dataView = mLContext.Data.LoadFromTextFile<LargData>(@"C:\Projects\DotNetCoreProjects\MetalTempPredict\MetalTempPredict\Data\TestData\*", hasHeader: true, separatorChar: ',');
var predictions = model.Transform(dataView);
var metrics = mLContext.Regression.Evaluate(predictions, "Label", "Score");
Console.WriteLine();
Console.WriteLine($"***********************************");
Console.WriteLine($" Model quality metrics evaluation ");
Console.WriteLine($"*----------------------------------");
Console.WriteLine($"* (RSquared takes values between 0 and 1. The closer its value is to 1, the better the model is.) RSquared Score: {metrics.RSquared:#.##}");
Console.WriteLine($" (RMS is one of the evaluation metrics of the regression model. The lower it is, the better the model is.) Root means Squared Error: {metrics.RootMeanSquaredError:#.##}");
}
private static void TestSinglePredicition(MLContext mLContext, ITransformer model)
{
var predictionFunction = mLContext.Model.CreatePredictionEngine<LargData, GetMetalTemp>(model);
var SamplePredict = new LargData();
Console.WriteLine("Time Input");
SamplePredict.date_time = (Console.ReadLine()).ToString();
Console.WriteLine("Door Status");
SamplePredict.DoorStatus = int.Parse(Console.ReadLine());
Console.WriteLine("Enter burner input");
SamplePredict.Burner_Input = float.Parse(Console.ReadLine());
Console.WriteLine("Enter Curr roof temp");
SamplePredict.Current_Roof_Temp = float.Parse(Console.ReadLine());
Console.WriteLine("Enter Roof Temp set point");
SamplePredict.Roof_Temp_SetPoint = float.Parse(Console.ReadLine());
var prediction = predictionFunction.Predict(SamplePredict);
Console.WriteLine($"******************************");
Console.WriteLine($"Predicted Metal_Temp: {prediction.Metal_Temp}");
Console.WriteLine($"******************************");
Console.ReadLine();
}
}
}