2016-04-13 2 views
0

見られないが、私は.CSVファイルからデータを読み込み、次のコマンドを エラー:オブジェクトの性別は「

plsFit <- train(CollegePlans ~ .,data = training,method = "pls",preProc = c("center", "scale"));
toPredict <- c("Female",35800,124,"Not Encouraged","Does not plan to attend")
plsClasses <- predict(plsFit, newdata = toPredict)

を実行し、次のエラーを得た Error in eval(expr, envir, enclos) : object 'Gender' not found

ここで

が構造体である:

str(training) 
'data.frame': 5401 obs. of 5 variables: 
$ Gender    : Factor w/ 2 levels "Female","Male": 2 1 1 2 1 1 1 1 2 1 ... 
$ ParentIncome  : int 53900 24900 65800 11440 16700 47630 39820 4860 65340 66550 ... 
$ IQ     : int 118 87 93 117 102 100 127 95 100 112 ... 
$ ParentEncouragement: Factor w/ 2 levels "Encouraged","Not Encouraged": 1 2 2 1 2 1 1 1 1 1 ... 
$ CollegePlans  : Factor w/ 2 levels "Does not plan to attend",..: 2 1 1 2 1 2 2 1 1 2 ... 

答えて

1

toPredictだけでも1行ならば、あまりにもデータフレームにする必要があります。例えば

toPredict <- data.frame(
    Gender = "Female", 
    ParentIncome = 35800, 
    IQ = 124, 
    ParentEncouragement = "Not Encouraged", 
    CollegePlans = "Does not plan to attend" 
) 
関連する問題