### Microsoft.ML 在使用 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("计算产品3的前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($"  分数:{t.Score}\t产品: {t.ProductID}");        Console.ReadKey();

我遇到了关于“Label”的问题。这是相关的类定义:

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: ‘成员 Label 标记了 KeyType 属性,但似乎不是键类型的有效数据类型(参数 ‘userType’)’

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


回答:

删除 [KeyType(count: 262111)] 注释对于 public float Label { get; set; } 属性

Label 不是键

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注