predict
函数中的type="class"
和type="response"
有什么区别?predict()函数的类型参数
对于之间实例:
predict(modelName, newdata=testData, type = "class")
和
predict(modelName, newdata=testData, type = "response")
predict
函数中的type="class"
和type="response"
有什么区别?predict()函数的类型参数
对于之间实例:
predict(modelName, newdata=testData, type = "class")
和
predict(modelName, newdata=testData, type = "response")
看到?predict.lm
: predict.lm
产生如果一个预测矢量或预测和界限的列名fit
,lwr
的矩阵,并且upr
间隔设置。对于type = "terms"
,这是一个每列有一列的矩阵,并且可能具有“常量”属性。
> d <- data.frame(x1=1:10,x2=rep(1:5,each=2),y=1:10+rnorm(10)+rep(1:5,each=2))
> l <- lm(y~x1+x2,d)
> predict(l)
1 2 3 4 5 6 7 8 9 10
2.254772 3.811761 4.959634 6.516623 7.664497 9.221486 10.369359 11.926348 13.074222 14.631211
> predict(l,type="terms")
x1 x2
1 -7.0064511 0.8182315
2 -5.4494620 0.8182315
3 -3.8924728 0.4091157
4 -2.3354837 0.4091157
5 -0.7784946 0.0000000
6 0.7784946 0.0000000
7 2.3354837 -0.4091157
8 3.8924728 -0.4091157
9 5.4494620 -0.8182315
10 7.0064511 -0.8182315
attr(,"constant")
[1] 8.442991
即predict(l)
是predict(l,type="terms")
的行总和+恒定
type = "response"
在GLM使用模型和type = "class"
在rpart包模型(CART)使用。 见:
反应使您的数字结果,而类为您分配给该值的标签。
响应让您确定您的阈值。例如,
glm.fit = glm(Direction~., data=data, family = binomial, subset = train)
glm.probs = predict(glm.fit, test, type = "response")
在glm.probs
我们必须介于0和1。现在我们可以判断阈值的一些数值,比方说0.6。方向有两个可能的结果,向上或向下。
glm.pred = rep("Down",length(test))
glm.pred[glm.probs>.6] = "Up"
哪个'predict'函数?预测是一种通用函数,用于根据各种模型拟合函数的结果进行预测。该函数调用依赖于第一个参数的类的特定方法。 – shadow