二元分类模型不准确
Binary Classification Model Inaccurate
我正在使用 ML.NET 和 SdcaLogisticRegression 以 XOR 门的形式进行二进制分类。
我遇到的问题是模型对我提供的输入输出了不准确的预测。例如,对于输入 0.8 和 0.2,它预测值为 0,概率为 0.459。
能否请您看看我的代码或算法是否不适合制作异或门?
我用不同数量的训练数据训练模型并且每次都收到相似的结果(训练数据文件中的 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。
我将训练算法切换为 Fast Forest,并在正确输出的情况下获得了高达 99.97% 的准确率。
我正在使用 ML.NET 和 SdcaLogisticRegression 以 XOR 门的形式进行二进制分类。
我遇到的问题是模型对我提供的输入输出了不准确的预测。例如,对于输入 0.8 和 0.2,它预测值为 0,概率为 0.459。
能否请您看看我的代码或算法是否不适合制作异或门?
我用不同数量的训练数据训练模型并且每次都收到相似的结果(训练数据文件中的 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。
我将训练算法切换为 Fast Forest,并在正确输出的情况下获得了高达 99.97% 的准确率。