私は R と機械学習アルゴリズムが初めてで、kaggle scikit exampleを使用して学習しようとしています。
次の 2 つのデータ フレームがあります。
> str(d.train)
'data.frame': 1000 obs. of 40 variables:
$ V1 : num 0.299 -1.174 1.192 1.573 -0.613 ...
> str(d.trainLabels)
'data.frame': 1000 obs. of 1 variable:
$ V1: int 1 0 0 1 0 1 0 1 1 0 ...
私の理解では、ほとんどの R ツールは、同じデータ フレーム内のクラス情報と共に使用することを意図しています。このため、trainLabels を最後の列として train データ フレームに追加しようとしています。
次のコードを試しました:
# http://www.gm.fh-koeln.de/~konen/WPF-DM-Cup/DM-Template/ClassifyTemplate/utils_DMC.r
######################################################################################
# bind the column with name response.predict and contents vec as last column
# to data frame d
######################################################################################
bind_response <- function(d,response.predict,vec)
{
# drop column response.predict if there, do nothing if not there
d <- d[,setdiff(names(d),response.predict)]
# bind column response.predict as last column to data frame d
d <- cbind(d, prediction=vec)
names(d)[names(d)=="prediction"] <- response.predict
return(d)
}
d.totalTrain <- bind_response(d.train, d.trainLabels, "1")
しかし、結果が私が望むものかどうかはわかりません:
> str(d.totalTrain)
'data.frame': 1000 obs. of 41 variables:
...
$ V40 : num 0.101 -1.818 2.987 1.883 0.408 ...
$ c(1, 0, 0, 1, 0, 1, 0, 1, ...