【问题标题】:Binary Classification Model Inaccurate二元分类模型不准确
【发布时间】: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。

标签: c# ml.net


【解决方案1】:

我将训练算法切换到快速森林,并在正确输出的情况下获得了高达 99.97% 的准确率。

【讨论】:

    猜你喜欢
    • 2019-10-21
    • 1970-01-01
    • 2022-01-21
    • 2016-03-11
    • 2015-06-26
    • 1970-01-01
    • 2021-11-02
    • 2021-07-19
    • 2019-09-27
    相关资源
    最近更新 更多