Microsoft.ML 使用 LoadFromEnumerable 时添加标签

Microsoft.ML Adding Label when using LoadFromEnumerable

有些东西不起作用,我想不通... 我想从列表中加载数据。我已经尝试了几个代码

MLContext mlContext = new MLContext();

        var listData = new List<ProductEntry>
        {
            new ProductEntry {CoPurchaseProductID = 12, ProductID = 4},
            new ProductEntry {CoPurchaseProductID = 12, ProductID = 3},
            new ProductEntry {CoPurchaseProductID = 11, ProductID = 5},
            new ProductEntry {CoPurchaseProductID = 11, ProductID = 3}
        };
        var data = mlContext.Data.LoadFromEnumerable(listData);
        var options = new MatrixFactorizationTrainer.Options
        {
            MatrixColumnIndexColumnName = nameof(ProductEntry.ProductID),
            MatrixRowIndexColumnName = nameof(ProductEntry.CoPurchaseProductID),
            LabelColumnName = "Label",
            LossFunction = MatrixFactorizationTrainer.LossFunctionType.SquareLossOneClass,
            Alpha = 0.01,
            Lambda = 0.025,
            Quiet = false,
            C = 0.00001,
            ApproximationRank = 10,
            NumberOfIterations = 20
        };

        var est = mlContext.Recommendation().Trainers.MatrixFactorization(options);
        ITransformer model = est.Fit(data);

        var predictionengine = mlContext.Model.CreatePredictionEngine<ProductEntry, Copurchase_prediction>(model);

        Console.WriteLine("Calculating the top 3 products for product 3...");
        var top5 = (from m in Enumerable.Range(1, 262111)
                    let p = predictionengine.Predict(
                        new ProductEntry()
                        {
                            ProductID = 3,
                            CoPurchaseProductID = (uint)m
                        })
                    orderby p.Score descending
                    select (ProductID: m, Score: p.Score)).Take(10);
        foreach (var t in top5)
            Console.WriteLine($"  Score:{t.Score}\tProduct: {t.ProductID}");

        Console.ReadKey();

我遇到了关于“标签”的问题 这是 类:

public class Copurchase_prediction
    {
        public float Score { get; set; }
    }

    public class ProductEntry
    {
        [KeyType(count: 262111)]
        public float Label { get; set; }

        [KeyType(count: 262111)]
        public uint ProductID { get; set; }

        [KeyType(count: 262111)]
        public uint CoPurchaseProductID { get; set; }
    }

出现错误:

System.ArgumentOutOfRangeException: '用 KeyType 属性标记的成员标签,但对于键类型(参数 'userType')似乎不是有效的数据类型'

有什么想法吗? 谢谢大家!

删除 public float Label { get; set; } 属性

[KeyType(count: 262111)] 注释

Label 不是键