[英]ML.NET, "Score Column" is missing
I want to make my first app in ML.NET.我想在 ML.NET 中制作我的第一个应用程序。 I bet on Wisconsin Prognostic Breast Cancer Dataset .
我打赌威斯康星州预后乳腺癌数据集。 I generete .csv file by myself.
我自己生成 .csv 文件。 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).它有 31 个不同的特征(列)。
My CancerData.cs
looks like this:我的
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;
}
And CancerPrediction.cs
和
CancerPrediction.cs
class CancerPrediction
{
[ColumnName("PredictedLabel")]
public string Diagnosis;
}
My Program.cs
:我的
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
ArgumentOutOfRangeException:缺少分数列
On ClassificationMetrics metrics = evaluator.Evaluate(model, testData);
On
ClassificationMetrics metrics = evaluator.Evaluate(model, testData);
method.方法。
When i add Score
Column in CancerPrediction
, i still get the same exception.当我在
CancerPrediction
添加Score
Column 时,我仍然遇到相同的异常。
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.我看到有人在StackOverflow上有同样的问题,但看起来没有答案,我无法对此发表评论,因为我没有足够的声誉。 Is it a bug?
这是一个错误吗? maybe my data is not prepared properly?
也许我的数据没有准备好? Im using
ML.NET
in ver. 0.5.0
我在版本中使用
ML.NET
ver. 0.5.0
ver. 0.5.0
Thanks for any advices!感谢您的任何建议!
EDIT1:编辑1:
When i add into CancerPrediction.cs
that line:当我添加到
CancerPrediction.cs
中时:
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'.'
System.InvalidOperationException:“无法将类型为“R4”的 IDataView 列“分数”绑定到类型为“System.String”的字段或属性“分数”。
in line:排队:
PredictionModel<CancerData, CancerPrediction> model = pipeline.Train<CancerData, CancerPrediction>();
EDIT2编辑2
How it looks:它的外观:
EDIT3编辑3
Change Separator
to ','
and load original dataset not prepered by me it still yelling, taht there is no Score
, so annoying将
Separator
更改为','
并加载不是我准备的原始数据集,它仍然大喊大叫,没有Score
,太烦人了
I believe I know what the problem is.我相信我知道问题是什么。
You are using a StochasticDualCoordinateAscentBinaryClassifier
, which is a binary classifier.您正在使用
StochasticDualCoordinateAscentBinaryClassifier
,它是一个二元分类器。
You are trying to evaluate results using ClassificationEvaluator
, which is a multiclass classification evaluator.您正在尝试使用
ClassificationEvaluator
评估结果,这是一个多类分类评估器。
I suggest you use BinaryClassificationEvaluator
to evaluate binary classifier models.我建议您使用
BinaryClassificationEvaluator
来评估二元分类器模型。
The exact problem is follows: the evaluator expects the column 'Score' to be a vector column that contains a score for every class.确切的问题如下:评估器期望列“Score”是一个向量列,其中包含每个类的分数。 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
缺少分数列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.