2017-07-27 20 views
0

我想使用下面的R腳本將列名添加到輸入數據集。如何在機器學習模型中使用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腳本在機器學習模型輸入數據集?

回答

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

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腳本時,有時候也是我的錯誤。

相關問題