ML.net 代码程序找不到输入列,训练算法时出现超出范围异常

ML.net code program cant find input column, out of range exception when training algorithm

当我训练我的算法时,我的模型出现异常:

System.ArgumentOutOfRangeException: 'Could not find input column 'Features' '

我很确定我正在将正确的变量传递到我的管道 属性,但是我知道 ML 有一个新版本,所以不推荐使用。虽然在这里找不到任何东西:

var model = pipeLine.Fit(dataView);

是什么错误

var pipeLine = mlContext.Transforms
     .Text.FeaturizeText("FeedBack", "Features")
    .Append(mlContext.BinaryClassification.Trainers.FastTree(numberOfLeaves: 50, numberOfTrees: 50, minimumExampleCountPerLeaf: 1));

我的模型来自哪里

var mlContext = new MLContext();

IDataView dataView = mlContext.Data.LoadFromEnumerable(trainingData);

是我的数据视图的来源。

这是我的训练数据

static void LoadTrainingData() {
    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "this is good",
        IsGood = true
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "this is horrible",
        IsGood = true
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "this is horrible",
        IsGood = false
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "this is average and ok",
        IsGood = true
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "bloody awful",
        IsGood = false
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "bad",
        IsGood = false
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "better",
        IsGood = true
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "so much nicer",
        IsGood = true
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "shitty terrible",
        IsGood = false
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "worse",
        IsGood = false
    });

    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "nice and good",
        IsGood = true
    });


    trainingData.Add(new FeedBackTrainingData() {
        FeedBackText = "soooo bad",
        IsGood = false
    });
}


    class FeedBackTrainingData
{

    [LoadColumn(0)]
    [ColumnName("label")]
    public bool IsGood { get; set; }

    [LoadColumn(1)]
    public string FeedBackText { get; set; }


}

我的模特

阅读文档

https://docs.microsoft.com/en-us/dotnet/api/microsoft.ml.textcatalog.featurizetext?view=ml-dotnet

似乎 FeaturizeText 需要参数 (outputColumnName, inputColumnName)

您的数据模型如下所示

{
    FeedBackText = "this is good",
    IsGood = true
}

但是您正在寻找一个名为 "Features" 的列以将其推入 "FeedBack" 列。

 .Text.FeaturizeText("FeedBack", "Features")

试试

 .Text.FeaturizeText("Features", "FeedBackText")

我遇到了同样的问题,我通过使用“SdcaLogisticRegression”找到了解决方案

var pipeLine = mlContext.Transforms.Text.FeaturizeText(outputColumnName: "Features", inputColumnName: "FeedBackText") .Append(mlContext.BinaryClassification.Trainers.SdcaLogisticRegression(labelColumnName: "label", featureColumnName: "Features"));