特征列'Features'的架构不匹配:预期的Vector,获得了Vector参数名称:inputSchema 该错误发生在以下代码中
static readonly string _dataPat=Path.Combine(Environment.CurrentDirectory, "Data", "train_data.csv");
static void Main(string[] args)
{
var mlContext = new MLContext(seed: 0);
IDataView data = mlContext.Data.LoadFromTextFile<IrisData>(_dataPath, separatorChar: ',', hasHeader: true);
string featuresColumnName = "Features";
var pipeline = mlContext.Transforms
.Concatenate(featuresColumnName,"Class", "Sex", "AgeGroup", "Embarked")
.Append(mlContext.Clustering.Trainers.KMeans(featuresColumnName, numberOfClusters: 2));
var model = pipeline.Fit(data);
错误与代码一致
var model = pipeline.Fit(data);
我的班级IrisData
public class IrisData
{
[LoadColumn(0)]
public string Class;
[LoadColumn(1)]
public string Sex;
[LoadColumn(2)]
public string AgeGroup;
[LoadColumn(3)]
public string Embarked;
}
答案 0 :(得分:0)
您的Features
列必须是float
s的向量。但是您正在创建一个string
s的向量。
您将需要将这些字符串转换为数字。一种方法是使用OneHotEncoding。参见https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/prepare-data-ml-net#work-with-categorical-data