ML.NET,缺少“得分列”

时间:2018-09-14 15:29:32

标签: c# .net-core ml.net

我想在ML.NET中制作我的第一个应用程序。我打赌威斯康星州Prognostic Breast Cancer Dataset。我自己生成.csv文件。该文件的一条记录如下所示:

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个不同的特征(列)。

我的 CancerData.cs 如下:

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

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

}

我的 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:得分列缺失

使用ClassificationMetrics metrics = evaluator.Evaluate(model, testData);方法。

当我在Score中添加CancerPrediction列时,我仍然遇到相同的异常。

我看到某人在StackOverflow上遇到了同样的问题,但似乎没有答案,我无法对此发表评论,因为我没有足够的声誉。是虫子吗?也许我的数据准备不正确?我在ML.NET

中使用ver. 0.5.0

感谢您的任何建议!

EDIT1:

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

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

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

我得到一个例外:

  

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

在线:

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

EDIT2

外观:

enter image description here

EDIT3

Separator更改为','并加载没有被我赞叹的原始数据集,但它仍然大喊大叫,因为没有Score,所以很烦人

0 个答案:

没有答案