ML.NET-功能列“ Features”的架构不匹配:预期的Vector <Single>,获得了Vector <Int32>

时间:2019-10-17 15:47:30

标签: c# classification multiclass-classification ml.net

我只是尝试创建我以前使用Azure ML,Visual Interface,Python等构建的第一个 ML.NET 项目,但是现在我想使用 C#

我正在遵循this教程,但是数据集和用途完全不同。

数据集有很多额外的列,但是我的数据模型如下所示(指向数据集中列的索引):

using Microsoft.ML.Data;

namespace ML_Net
{

    public class Earthquake
    {
        [LoadColumn(1)]
        public int geo_level_1_id { get; set; }
        [LoadColumn(2)]
        public int geo_level_2_id { get; set; }
        [LoadColumn(3)]
        public int geo_level_3_id { get; set; }
        [LoadColumn(4)]
        public int count_floors_pre_eq { get; set; }
        [LoadColumn(5)]
        public int age { get; set; }
        [LoadColumn(6)]
        public int area { get; set; }
        [LoadColumn(7)]
        public int height { get; set; }
        [LoadColumn(8)]
        public int count_families { get; set; }
        [LoadColumn(26)]
        public int has_secondary_use { get; set; }
        [LoadColumn(27)]
        public double square { get; set; }
        [LoadColumn(39)]
        public double difference { get; set; }
        [LoadColumn(40)]
        public int damage_grade { get; set; }
    }

    public class DamagePrediction
    {
        [ColumnName("PredictedLabel")]
        public int damage_grade;
    }
}

错误来自训练功能:

public static IEstimator<ITransformer> BuildAndTrainModel(IDataView trainingDataView, IEstimator<ITransformer> pipeline)
{
    var trainingPipeline = pipeline
        .Append(_mlContext.MulticlassClassification.Trainers
        .SdcaMaximumEntropy("Label", "Features"))
        .Append(_mlContext.Transforms.Conversion
        .MapKeyToValue("PredictedLabel"));

    _trainedModel = trainingPipeline.Fit(trainingDataView);
    _predEngine = _mlContext.Model
        .CreatePredictionEngine<Earthquake, DamagePrediction>(_trainedModel);

    Earthquake building = new Earthquake()
    {
        geo_level_1_id = 1,
        geo_level_2_id = 42,
        geo_level_3_id = 941,
        count_floors_pre_eq = 2,
        age = 0,
        area = 24,
        height = 4,
        count_families = 2,
        has_secondary_use = 0,
        square = 4.898979485566356,
        difference = 0.8989794855663558
    };

    var prediction = _predEngine.Predict(building);
    Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {prediction.damage_grade} ===============");


    return trainingPipeline;
}

哪个说:

  

引发的异常:“ System.ArgumentOutOfRangeException”在   Microsoft.ML.Data.dll类型的未处理异常   Microsoft.ML.Data.dll中发生了'System.ArgumentOutOfRangeException   功能列“功能”的架构不匹配:预期   向量,得到向量

我似乎无法理解问题所在,您能帮我一些想法吗?

我仅处理数字数据,这就是为什么我不添加变换或特征化的原因,但也许归一化会有所帮助。因为我有一些浮点数。

提前感谢您的所有创意!

0 个答案:

没有答案