ML.NET中的“得分列”不见了 [英] ML.NET, "Score Column" is missing

查看:98
本文介绍了ML.NET中的“得分列”不见了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ML.NET中制作我的第一个应用程序。我打赌威斯康星州预后的乳腺癌数据集。我自己生成.csv文件。该文件的一条记录如下所示:

I want to make my first app in ML.NET. I bet on Wisconsin Prognostic Breast Cancer Dataset. I generete .csv file by myself. One record of that file looks like this:

B;11.62;18.18;76.38;408.8;0.1175;0.1483;0.102;0.05564;0.1957;0.07255;0.4101;1.74;3.027;27.85;0.01459;0.03206;0.04961;0.01841;0.01807;0.005217;13.36;25.4;88.14;528.1;0.178;0.2878;0.3186;0.1416;0.266;0.0927

它获得31个不同的特征(列)。

And it get 31 diffrent features (columns).

我的 CancerData.cs 看起来像这样:

My CancerData.cs looks like this:

class CancerData
{

    [Column(ordinal: "0")]
    public string Diagnosis;

    [Column(ordinal: "1")]
    public float RadiusMean;

    [Column(ordinal: "2")]
    public float TextureMean;

    [Column(ordinal: "3")]
    public float PerimeterMean;

   //.........

   [Column(ordinal: "28")] 
    public float ConcavPointsWorst;

    [Column(ordinal: "29")]
    public float SymmetryWorst;

    [Column(ordinal: "30")]
    public float FractalDimensionWorst;

    [Column(ordinal: "31", name: "Label")]
    public string Label;
}

CancerPrediction.cs

And CancerPrediction.cs

class CancerPrediction
{
    [ColumnName("PredictedLabel")]
    public string Diagnosis;

}

我的 程序。 cs

My Program.cs :

class Program
{

    static void Main(string[] args)
    {
        PredictionModel<CancerData, CancerPrediction> model = Train();
        Evaluate(model);
    }

    public static PredictionModel<CancerData, CancerPrediction> Train()
    {
        var pipeline = new LearningPipeline();
        pipeline.Add(new TextLoader("Cancer-train.csv").CreateFrom<CancerData>(useHeader: true, separator: ';'));
        pipeline.Add(new Dictionarizer(("Diagnosis", "Label")));
        pipeline.Add(new ColumnConcatenator(outputColumn: "Features",
            "RadiusMean",
            "TextureMean",
            "PerimeterMean",
            //... all of the features
            "FractalDimensionWorst"));
        pipeline.Add(new StochasticDualCoordinateAscentBinaryClassifier());
        pipeline.Add(new PredictedLabelColumnOriginalValueConverter() { PredictedLabelColumn = "PredictedLabel" });
        PredictionModel<CancerData, CancerPrediction> model = pipeline.Train<CancerData, CancerPrediction>();
        model.WriteAsync(modelPath);
        return model;

    }

    public static void Evaluate(PredictionModel<CancerData, CancerPrediction> model)
    {
        var testData = new TextLoader("Cancer-test.csv").CreateFrom<CancerData>(useHeader: true, separator: ';');
        var evaluator = new ClassificationEvaluator();
        ClassificationMetrics metrics = evaluator.Evaluate(model, testData);
        var accuracy = Math.Round(metrics.AccuracyMicro, 2);
        Console.WriteLine("The accuracy is: " + accuracy);
        Console.ReadLine();
    }
}

我得到的是:


ArgumentOutOfRangeException:缺少分数列

ArgumentOutOfRangeException: Score column is missing

ClassificationMetrics指标= evaluator.Evaluate(model,testData); 方法。

当我在 CancerPrediction 中添加分数列时,我仍然得到相同的异常。

When i add Score Column in CancerPrediction, i still get the same exception.

我看到有人在 StackOverflow ,但是它似乎没有答案,我无法对此发表评论,因为我没有足够的声誉。是虫子吗?也许我的数据准备不正确?我在 ver中使用 ML.NET 。 0.5.0

I saw that someone have the same problem on StackOverflow but it looks like it is without answer and i cant make a comment on it because i dont have enough reputation. Is it a bug? maybe my data is not prepared properly? Im using ML.NET in ver. 0.5.0

感谢任何建议!

编辑1:

当我添加到 CancerPrediction.cs 时,该行:

class CancerPrediction
{
    [ColumnName("PredictedLabel")]
    public string PredictedDiagnosis;

    [ColumnName("Score")]
    public string Score; // => new column!
}

我有一个例外:


System.InvalidOperationException:'无法将'R4'类型的IDataView列'Score'绑定到'System.String'类型的字段或属性'Score'。'

System.InvalidOperationException: 'Can't bind the IDataView column 'Score' of type 'R4' to field or property 'Score' of type 'System.String'.'

在行中:

PredictionModel<CancerData, CancerPrediction> model = pipeline.Train<CancerData, CancerPrediction>();

EDIT2

外观:

< img src = https://i.stack.imgur.com/SB76X.png alt =在此处输入图片描述>

EDIT3

分隔符更改为','并加载我不喜欢的原始数据集,但它仍然大喊大叫,因为没有得分,所以令人讨厌

Change Separator to ',' and load original dataset not prepered by me it still yelling, taht there is no Score, so annoying

推荐答案

我相信我知道问题出在哪里。

I believe I know what the problem is.

您正在使用 StochasticDualCoordinateAscentBinaryClassifier ,它是一个二进制分类器。

You are using a StochasticDualCoordinateAscentBinaryClassifier, which is a binary classifier.

您正尝试使用 ClassificationEvaluator 评估结果,ClassificationEvaluator 是多类分类评估器。

You are trying to evaluate results using ClassificationEvaluator, which is a multiclass classification evaluator.

我建议您使用 BinaryClassificationEvaluator 来评估二进制分类器模型。

I suggest you use BinaryClassificationEvaluator to evaluate binary classifier models.

确切的问题如下:评估者希望得分列是包含每个类得分的向量列。它找到的是分数列,它是一个标量(仅是肯定类的分数)。

The exact problem is follows: the evaluator expects the column 'Score' to be a vector column that contains a score for every class. What it finds is the 'Score' column which is a scalar (just the score of the positive class).

因此它抛出了一些令人费解的消息

So it throws with somewhat convoluted message


得分列丢失

Score column is missing

这篇关于ML.NET中的“得分列”不见了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆