3

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

And it get 31 diffrent features (columns).

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;
}

And CancerPrediction.cs

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

}

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();
    }
}

What i get, is:

ArgumentOutOfRangeException: Score column is missing

On ClassificationMetrics metrics = evaluator.Evaluate(model, testData); method.

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

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

Thanks for any advices!

EDIT1:

When i add into CancerPrediction.cs that line:

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

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

I get an exception:

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

in line:

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

EDIT2

How it looks:

enter image description here

EDIT3

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

4

1 回答 1

3

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

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

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

我建议你BinaryClassificationEvaluator用来评估二元分类器模型。

确切的问题如下:评估者期望列'Score'是一个向量列,其中包含每个类的分数。它找到的是“分数”列,它是一个标量(只是正类的分数)。

所以它抛出了一些令人费解的信息

缺少分数列

于 2018-09-14T20:20:12.783 回答