简体   繁体   English

ML.NET:功能列“功能”的架构不匹配

[英]ML.NET: Schema mismatch for feature column 'Features'

I'm trying to learn ML.NET/Get into Machine Learning, but I'm stuck at an issue. 我正在尝试学习ML.NET/进入机器学习,但遇到了一个问题。

My goal is to create a Trained Model that can be used to predict a city based on input. 我的目标是创建可用于基于输入预测城市的训练模型。

This code: 这段代码:

var dataPath = "cities.csv";
var mlContext = new MLContext();
var loader = mlContext.Data.CreateTextLoader<CityData>(hasHeader: false, separatorChar: ',');

var data = loader.Load(dataPath);

string featuresColumnName = "Features";

var pipeline = mlContext.Transforms.Concatenate(featuresColumnName, "PostalCode", "CityName")
        .Append(mlContext.Clustering.Trainers.KMeans(featuresColumnName, clustersCount: 3));

var model = pipeline.Fit(data);

Which should take an CSV as input (Which contains a list of Cities (Column 0 = Postal Code, Column 1 = CityName), and then add these features to the pipeline, gives the following error: 应该以CSV作为输入(其中包含城市列表(列0 =邮政编码,列1 = CityName),然后将这些功能添加到管道中,会产生以下错误:

Unhandled Exception: System.ArgumentOutOfRangeException: Schema mismatch for feature column 'Features': expected Vector<R4>, got Vector<Text>

On the "Fit"- function. 在“适合”功能上。

I've done a bit of digging on the GitHub Repo, but I can't seem to find a solution. 我在GitHub Repo上做了一些挖掘,但似乎找不到解决方案。 I'm working from the Iris- example ( https://docs.microsoft.com/en-us/dotnet/machine-learning/tutorials/iris-clustering ) (Of course with my modifications) 我正在使用虹膜示例( https://docs.microsoft.com/zh-cn/dotnet/machine-learning/tutorials/iris-clustering )(当然,请进行我的修改)

Any ideas? 有任何想法吗?

Using FeaturizeText to transform strings features into a float array ones 使用FeaturizeText将字符串特征转换为浮点数组

var pipeline = mlContext.Transforms
    .Text.FeaturizeText("PostalCodeF", "PostalCode")
    .Append(mlContext.Transforms.Text.FeaturizeText("CityNameF", "CityName"))
    .Append(mlContext.Transforms.Concatenate(featuresColumnName, "PostalCodeF", "CityNameF"))
    .Append(mlContext.Clustering.Trainers.KMeans(featuresColumnName, clustersCount: 3));

var model = pipeline.Fit(data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM