【发布时间】:2019-05-28 05:12:06
【问题描述】:
我正在使用 ML.NET 和 SdcaLogisticRegression 以 XOR 门的形式进行二进制分类。
我遇到的问题是模型对我给它的输入输出的预测不准确。例如,它以 0.459 的概率预测输入 0.8 和 0.2 的值 0。
请问我的代码或算法是否不适合制作异或门?
我用不同数量的训练数据训练了模型,每次都收到相似的结果(训练数据文件中的行在 200 到 1M 行之间)。
IDataView trainingData = context.Data.LoadFromTextFile<XorInput>(trainDataFile, separatorChar: ',', hasHeader: true);
IDataView testData = context.Data.LoadFromTextFile<XorInput>(testDataFile, separatorChar: ',', hasHeader: true);
var trainingPipeline = context.Transforms.Concatenate("Features", "Inputs").Append(context.BinaryClassification.Trainers.SdcaLogisticRegression(labelColumnName: "Label", featureColumnName: "Features"));
ITransformer trainedModel = trainingPipeline.Fit(trainingData);
XorInput sampleInput = new XorInput { Inputs = new float[] {0.8f, 0.2f } };
var predEngine = context.Model.CreatePredictionEngine<XorInput, XorOutputPrediction>(trainedModel);
var resultprediction = predEngine.Predict(sampleInput);
Console.WriteLine($"=============== Single Prediction ===============");
Console.WriteLine($"Inputs: {sampleInput.Inputs[0]}, {sampleInput.Inputs[1]} | Prediction: {(Convert.ToInt16(resultprediction.Prediction))} | Probability: {resultprediction.Probability} ");
Console.WriteLine($"==================================================");
仅供参考,我的 XorInput 和 XorOutputPrediction 类如下所示:
public class XorInput
{
[LoadColumn(0), ColumnName("Label")]
public bool Label;
[LoadColumn(1,2)]
[VectorType(2)]
//[ColumnName("Features")]
public float[] Inputs;
}
public class XorOutputPrediction
{
[ColumnName("PredictedLabel")]
public bool Prediction { get; set; }
public float Probability { get; set; }
public float Score { get; set; }
}
trainDataFile 和 testDataFile 中包含的数据如下所示:
0, 0.9173474, 0.8329648
0, 0.4942033, 0.1281894
0, 0.4558121, 0.1869916
1, 0.738331, 0.4427712
0, 0.8739759, 0.5859472
1, 0.7447554, 0.1089314
1, 0.2433814, 0.6192696
对于 0.8 和 0.2 的输入值,我预计输出预测值为 1。
【问题讨论】:
-
您是否尝试反转输入 0.8 和 0.2?
-
我刚刚用大约 32k 行重新训练了模型,并再次尝试对 0.8 和 0.2 实现正确预测,但概率仅为 0.52 左右。我将如何增加这个?编辑:再次重新训练后,它错误地预测反转和非反转均为 0。