训练集有 0 个实例,中止训练异常

Training set has 0 instances, abort training exception

我正在将我的项目重建到 ML.NET 0.10。我从 this link 获取数据,它看起来像这样(我以这种方式将其保存为 .csv 文件:

diagnosis;radius_mean;texture_mean;perimeter_mean;area_mean;smoothness_mean;compactness_mean;concavity_mean;concave points_mean;symmetry_mean;fractal_dimension_mean;radius_se;texture_se;perimeter_se;area_se;smoothness_se;compactness_se;concavity_se;concave points_se;symmetry_se;fractal_dimension_se;radius_worst;texture_worst;perimeter_worst;area_worst;smoothness_worst;compactness_worst;concavity_worst;concave points_worst;symmetry_worst;fractal_dimension_worst
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
B;9.667;18.49;61.49;289.1;0.08946;0.06258;0.02948;0.01514;0.2238;0.06413;0.3776;1.35;2.569;22.73;0.007501;0.01989;0.02714;0.009883;0.0196;0.003913;11.14;25.62;70.88;385.2;0.1234;0.1542;0.1277;0.0656;0.3174;0.08524

我的Dataclass礼物是这样的:

class CancerData
{
    [LoadColumn(0, 30), ColumnName("Features")]
    public float FeatureVector { get; set; }

    [LoadColumn(31)]
    public float Target { get; set; }
}

现在,我的 Program.cs 文件:

var mlContext = new MLContext();
var trainData = mlContext.Data.ReadFromTextFile<CancerData>("Cancer-train.csv", 
                             hasHeader: true, 
                             separatorChar: ';');

var pipeline = mlContext.Transforms
                        .Normalize("Features")
                        .AppendCacheCheckpoint(mlContext)
            .Append(mlContext.BinaryClassification.Trainers.StochasticDualCoordinateAscent(labelColumn: "Target", featureColumn: "Features"));

var model = pipeline.Fit(trainData);

var testData = mlContext.Data.ReadFromTextFile<CancerData>("Cancer-test.csv", 
                             hasHeader: true, 
                             separatorChar: ';');

var metrics = mlContext.BinaryClassification.Evaluate(model.Transform(testData), label: "Target");

从这段代码中,我得到一个异常:

System.InvalidOperationException: 'Training set has 0 instances, aborting training.'

我的问题是,我的代码是否正确?我的 .csv 文件在项目文件夹中,它适用于 ML.NET 0.5。感谢您的任何建议!

LoadColumn(0, 30) 指定从第 0 列到第 30 列加载数据,但 FeatureVector 是单个浮点数。至少应该是 float[]

第一个 列虽然包含文本数据。它应该从 FeatureVector 数组中排除。

癌症数据可能看起来像这样:

class CancerData
{
    [LoadColumn(1, 30), ColumnName("Features")]
    public float[] FeatureVector { get; set; }

    [LoadColumn(31)]
    public float Target { get; set; }
}

如果需要 diagnosis 列,则应为:

class CancerData
{
    [LoadColumn(0)]
    public string Diagnosis {get;set;}

    [LoadColumn(1, 30), ColumnName("Features")]
    public float[] FeatureVector { get; set; }

    [LoadColumn(31)]
    public float Target { get; set; }
}