2017-06-19 55 views
0

我試圖使用multinom()從NNET在我的數據應用迴歸。 這裏是我做了什麼:的R - 預測()錯誤:無效的類型(內置)變量「類」

#------------------Multinom Regression---------------# 
    #regression 
    glm.fit=multinom(Duration~., data=train) 
    summary(glm.fit) 
    #Prediction 
    predsval <-predict(glm.fit, newdata=validation[,2:11], "probs") 

的預測()操作拋出這個錯誤:

Error in model.frame.default(Terms, newdata, na.action = na.omit, xlev = object$xlevels) : 
    invalid type (builtin) for variable 'class' 

的預測()行正在爲衆多的模型,如決策樹和神經網絡。但是對於同一行,它會在多重回歸模型中引發錯誤。 有什麼想法?

編輯:

> dput(train[1:5,]) 
structure(list(Duration = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("1", 
"2", "3", "4", "5", "6"), class = "factor"), ActionAVG = c(1079.818182, 
8519.15, 4938.211538, 633.9230769, 487.1341463), ActionCount = c(33L, 
20L, 52L, 13L, 82L), ActionsSTD = c(1325.668286, 14333.15299, 
5746.947505, 1558.555553, 1187.325397), EventCount = c(53L, 1L, 
36L, 9L, 20L), GestureAVG = c(712.001548, 2645.481675, 1724.010753, 
2113.457711, 2757.006369), GestureCount = c(646L, 191L, 93L, 
201L, 157L), gesturesstd = c(1446.855062, 4864.355753, 1967.416169, 
1733.255691, 2572.892938), screencount = c(50L, 12L, 32L, 15L, 
78L), stddiff = c(1356.033565, 6373.766188, 3497.559543, 1770.347893, 
2679.068084), ScreenCountDist = c(13L, 6L, 5L, 7L, 8L), class = structure(c(1L, 
1L, 1L, 1L, 1L), .Label = c("1", "2", "3", "4", "5", "6"), class = "factor")), .Names = c("Duration", 
"ActionAVG", "ActionCount", "ActionsSTD", "EventCount", "GestureAVG", 
"GestureCount", "gesturesstd", "screencount", "stddiff", "ScreenCountDist", 
"class"), row.names = c(NA, 5L), class = "data.frame") 

EDIT_2:

> dput(validation[1:5,]) 
structure(list(Duration = c(5, 2, 3, 3, 3), ActionAVG = c(68.2, 
909.875, 4135, 192.5, 535.75), ActionCount = c(5L, 8L, 1L, 8L, 
4L), ActionsSTD = c(29.32064119, 1362.292022, 0, 293.8877337, 
522.1917751), EventCount = c(13L, 6L, 1L, 3L, 1L), GestureAVG = c(1573.473684, 
2964.966667, 1973.352941, 1072.733333, 560.2692308), GestureCount = c(57L, 
60L, 34L, 15L, 26L), gesturesstd = c(3052.29873, 3258.204122, 
2452.19659, 1439.818365, 454.8399769), screencount = c(8L, 14L, 
3L, 6L, 6L), stddiff = c(2862.564254, 5449.960621, 2345.319105, 
2220.919405, 909.2036427), ScreenCountDist = c(4L, 8L, 3L, 5L, 
4L)), .Names = c("Duration", "ActionAVG", "ActionCount", "ActionsSTD", 
"EventCount", "GestureAVG", "GestureCount", "gesturesstd", "screencount", 
"stddiff", "ScreenCountDist"), row.names = c(2L, 4L, 5L, 7L, 
15L), class = "data.frame") 
+0

可以請你發佈的一個樣本數據?你可以使用'dput(train [1:10,])'和'dput(validation [1:10,])' –

+0

我編輯原始文章,告訴我它是否有幫助(驗證是相同的) – Johnny

+0

嘗試' class(validation $ class)',它應該是''factor'',如果不是,那就是你的問題。 –

回答

1

從模型中排除變量是不存在的驗證組

glm.fit=multinom(Duration~., data=train[,-12]) 
相關問題