我能够从string[]
列名中动态训练和创建我的回归模型。但是,当我尝试传入具有与 Dictionary Key Pair 属性相同的参数名称的动态对象时,它会引发错误:
System.ArgumentOutOfRangeException: 'Could not find input column '<MyColumn>''
<MyColumn>
模型要查找的第一个参数在哪里。
private static void TestSinglePrediction(MLContext mlContext, dynamic ratingDataSample, int actual)
{
ITransformer loadedModel;
using (var stream = new FileStream(_modelPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
loadedModel = mlContext.Model.Load(stream);
}
var predictionFunction = loadedModel.MakePredictionFunction<dynamic, RatingPrediction>(mlContext);
var prediction = predictionFunction.Predict(ratingDataSample);
Console.WriteLine($"**********************************************************************");
Console.WriteLine($"Predicted rating: {prediction.Rating:0.####}, actual rating: {actual}");
Console.WriteLine($"**********************************************************************");
}
我怀疑这是因为动态对象不包含[Column]
我通常会传入的标准类对象所具有的属性。
但是,我最终将拥有数百个通过转置 SQL 查询自动生成的列,因此手动键入每一列对于未来来说不是一种可行的方法。
有什么办法可以在运行时应用该属性吗?或者任何其他方式我可以一般地处理这种情况?谢谢!