如何使用机器学习模型中的R脚本将列名添加到输入数据集

时间:2017-07-27 12:36:30

标签: r azure-machine-learning-studio

我正在尝试使用下面的R脚本将列名添加到输入数据集中。

dataset1 <- maml.mapInputPort(1)#class: data.frame
# Sample operation
cols <- c("age",
    "workclass",
    "fnlwgt",
    "education",
    "education-num",
    "marital-status",
    "occupation",
    "relationship",
    "race",
    "sex",
    "capital-gain",
    "capital-loss",
    "hours-per-week",
    "native-country",
    "income")
 colnames(data.frame) <- cols
 data.set = dataset1;
 maml.mapOutputPort("data.set");

但我收到如下图所示的错误。

enter image description here

您能告诉我如何使用机器学习模型中的R脚本将列名添加到输入数据集中吗?

2 个答案:

答案 0 :(得分:0)

最后,我解决了我的问题,即使用下面的R脚本将列名添加到输入数据集。

dataset1 <- maml.mapInputPort(1)#class: data.frame
# Sample operation
cols <- c("age",
"workclass",
"fnlwgt",
"education",
"education-num",
"marital-status",
"occupation",
"relationship",
"race",
"sex",
"capital-gain",
"capital-loss",
"hours-per-week",
"native-country",
"income")
colnames(dataset) <- cols
data.set = dataset1;
maml.mapOutputPort("data.set");
早些时候,我在这一行上做错了 colnames(data.frame)<-cols

现在我使用这行代码colnames(dataset) <- cols

更新上面一行

答案 1 :(得分:0)

我认为必须是dataset1而不是dataset

dataset1 <- maml.mapInputPort(1) #class: data.frame

# Sample operation

cols <- c("age",
    "workclass",
    "fnlwgt",
    "education",
    "education-num",
    "marital-status",
    "occupation",
    "relationship",
    "race",
    "sex",
    "capital-gain",
    "capital-loss",
    "hours-per-week",
    "native-country",
    "income")

colnames(dataset1) <- cols

maml.mapOutputPort("dataset1");

您必须在命名数据集/声明变量时保持一致。使用R脚本时,有时也是我的错误。