首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用IDataView时不能确定成员特性的MakePredictionFunction类型

调用IDataView时不能确定成员特性的MakePredictionFunction类型
EN

Stack Overflow用户
提问于 2018-10-13 16:02:51
回答 1查看 3.5K关注 0票数 2

我试图使用新的Microsoft.ML 0.6.0来制作预测函数。

当我叫"model.AsDynamic.MakePredictionFunction“时,我收到

"System.ArgumentOutOfRangeException:‘无法确定成员特性的IDataView类型’“。

代码:

代码语言:javascript
复制
using System;
using Microsoft.ML;
using Microsoft.ML.Runtime.Api;
using Microsoft.ML.Runtime.Data;
using Microsoft.ML.Trainers;
using Microsoft.ML.StaticPipe;

namespace MachineLearning
{
    class MLTest
    {
        public void Run()
        {
            var env = new LocalEnvironment();
            var reader = TextLoader.CreateReader(env, ctx => (label: ctx.LoadBool(0), features: ctx.LoadFloat(1, 3)));
            var traindata = reader.Read(new MultiFileSource("train.txt"));
            var bctx = new BinaryClassificationContext(env);
            var est = reader.MakeNewEstimator()
                .Append(x => (x.label, prediction: bctx.Trainers.Sdca(x.label, x.features.Normalize())));
            var model = est.Fit(traindata);

            //FAILS: System.ArgumentOutOfRangeException: 'Could not determine an IDataView type for member features'
            var predictionFunct = model.AsDynamic.MakePredictionFunction<Issue, Prediction>(env);

        }

        public class Issue
        {
            public float label;
            public Vector<float> features; //what is wrong?
        }

        public class Prediction
        {
            [ColumnName("prediction.predictedLabel")]
            public bool PredictionLabel;

            [ColumnName("prediction.probability")]
            public float Probability;

            [ColumnName("prediction.score")]
            public float Score;
        }
    }
}

文件train.txt包含:

代码语言:javascript
复制
1   0   0   0
1   0   1   0
1   0   0   1
1   0   1   1
0   1   1   1
0   1   0   1
0   1   1   0
0   1   0   0

看起来错误在课堂上是“问题”,但到底是什么错了呢?谢谢

EN

回答 1

Stack Overflow用户

发布于 2019-02-13 16:16:52

你在尝试模式理解以生成数据视图和读取。通过使用启动数组,您可以使用列类型来设置数组的大小。

(这是.10 of ML.NET的版本)

代码语言:javascript
复制
public class Issue
{
        public float label;
        public float[] features; //change this
}

使用SchemaDefinition进行运行时类型映射提示

代码语言:javascript
复制
var inputSchemaDefinition = SchemaDefinition.Create(typeof(Issue), SchemaDefinition.Direction.Both);
inputSchemaDefinition["features"].ColumnType = new VectorType(NumberType.R4, 4);

然后创建引擎:

代码语言:javascript
复制
var predictionEngine = model.CreatePredictionEngine<InputSchema, Prediction>(model as IHostEnvironment, inputSchemaDefinition, outputSchemaDefinition);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52794804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档