如何在C#/ ML.net中修复NaN(非数字)输出

时间:2019-04-25 19:37:47

标签: c# ml.net

程序成功地训练了该模型(具有1600个示例的数据集),但是在进行预测时,它返回NaN(不是数字)。 非常感谢您的任何帮助,但请记住,我既不是经验丰富的程序员,也不是机器学习的专家。

我已经尝试将预测值更改为与数据集相似的值;

//Column Declaration    
public class WineQualityPrediction
    {
        [ColumnName("Label")]
        public float Label;
    }

    class Program
    {
        static void Main(string[] args)
        {
            var pipeline = new LearningPipeline();
            string dataPath = "WineMl.txt";
            pipeline.Add(new TextLoader(dataPath).CreateFrom<WineData>(separator: ','));

            pipeline.Add(new Dictionarizer("Label"));
            pipeline.Add(new ColumnConcatenator("Features", "FixedAcidity", "VolatileAcidity", "CitricAcid", "ResidualSugar", "Chlorides", "FreeSulfurDioxide", "TotalSulfurDioxide", "Density", "pH", "Sulphates", "Alcohol"));

            pipeline.Add(new StochasticDualCoordinateAscentClassifier());
            pipeline.Add(new PredictedLabelColumnOriginalValueConverter() { PredictedLabelColumn = "Label" });

            var model = pipeline.Train<WineData, WineQualityPrediction>();

            var prediction = model.Predict(new WineData { FixedAcidity = 7.4f, VolatileAcidity = 0.7f, CitricAcid = 0.0f, ResidualSugar = 1.9f, Chlorides = 0.076f, FreeSulfurDioxide =11.0f, TotalSulfurDioxide = 34.0f, Density = 0.9978f, pH = 3.51f, Sulphates = 0.56f});

            Console.WriteLine($"Predicted wine quality is: {prediction.Label}");
            Console.ReadLine();
        }
    }
}

0 个答案:

没有答案