我在使用ML.NET来预测一系列值,使用的是回归模型。我只对预测一个列(分数列)感兴趣。然而,其他一些列的值在预测类中不可用。我不能将它们设为0,因为这会影响预测结果,所以我猜它们也需要被预测。
我看到一个类似的问题在这里,关于预测多个值。答案建议创建两个模型,但我注意到每个模型中指定的特征列不包括另一个模型的标签列。这意味着在进行预测时这些列不会被使用。我的理解是否有误,或者每个模型的标签列也应该包含在另一个模型的特征列中?
这里有一些示例代码,试图用代码来解释:
public class FooInput{ public float Feature1 { get; set; } public float Feature2 { get; set; } public float Bar {get; set; } public float Baz {get; set; }}public class FooPrediction : FooInput{ public float BarPrediction { get; set; } public float BazPrediction { get; set; }}public ITransformer Train(IEnumerable<FooInput> data){ var mlContext = new MLContext(0); var trainTestData = mlContext.Data.TrainTestSplit(mlContext.Data.LoadFromEnumerable(data)); var pipelineBar = mlContext.Transforms.CopyColumns("Label", "Bar") .Append(mlContext.Transforms.CopyColumns("Score", "BarPrediction")) .Append(mlContext.Transforms.Concatenate("Features", "Feature1", "Feature2", "Baz")) .Append(mlContext.Regression.Trainers.FastTree()); var pipelineBaz = mlContext.Transforms.CopyColumns("Label", "Baz") .Append(mlContext.Transforms.CopyColumns("Score", "BazPrediction")) .Append(mlContext.Transforms.Concatenate("Features", "Feature1", "Feature2", "Bar")) .Append(mlContext.Regression.Trainers.FastTree()); return pipelineBar.Append(pipelineBaz).Fit(trainTestData.TestSet);}
这实际上与上述答案相同,但增加了Baz
作为预测Bar
的模型的特征,反之亦然,增加了Bar
作为预测Baz
的模型的特征。
这是正确的做法吗,或者另一个问题的答案是否达到了预期的结果,即每个列的预测将利用从加载的数据集中其他已预测列的值?
回答:
你可以使用的一种技术称为“插补”,它用一些“猜测”的值替换这些未知的值。插补只是用我们数据集中缺失的值进行替换的过程。
在ML.NET中,你要找的是ReplaceMissingValues
转换。你可以在learn.microsoft.com上找到示例。
你上面讨论的技术也是一种插补形式,你的未知值被从其他已知值中预测的值所替换。这也可以起作用。我建议你尝试这两种形式,看看哪种对你的数据集最有效。