我正在尝试使用来自nnet的multinom()对我的数据应用回归。 这就是我所做的:
#------------------Multinom Regression---------------#
#regression
glm.fit=multinom(Duration~., data=train)
summary(glm.fit)
#Prediction
predsval <-predict(glm.fit, newdata=validation[,2:11], "probs")
predict()操作会抛出此错误:
Error in model.frame.default(Terms, newdata, na.action = na.omit, xlev = object$xlevels) :
invalid type (builtin) for variable 'class'
predict()行适用于众多模型,如决策树和神经网络。但对于同一行,它会在多项回归模型上抛出错误。 任何想法?
编辑:
> 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 :(得分:1)
从模型中排除验证集中不存在的变量
glm.fit=multinom(Duration~., data=train[,-12])