我使用泊松分布运行cv.glmnet
以获得二元结果。 predict
函数返回预测的概率,但不返回预测的类。如何将概率转换为类,以便生成confusionMatrix
来确定AUC等? NB。至少一个预测概率> 1。
cv <- cv.glmnet(deriv.x, deriv.y, foldid = foldid, weights = wts, family = "poisson")
pred <- predict.cv.glmnet(cv, newx = valid.x, s = "lambda.min", "response")
confusionMatrix(pred, valid.y)
Error in confusionMatrix.default(pred, valid.y) :
the data cannot have more levels than the reference
答案 0 :(得分:0)
这是因为你返回的是概率,而不是类,所以试试吧:
cv <- cv.glmnet(deriv.x, deriv.y, foldid = foldid, weights = wts, family = "poisson")
pred <- predict.cv.glmnet(cv, newx = valid.x, s = "lambda.min", "response")
pred <- ifelse(pred > 0.5,1,0)
confusionMatrix(pred, valid.y)
您可以选择自己的值进行四舍五入。