我创建了一个Logistic回归模型,并用它来预测出席率:
LogModel <- glm(formula = Attended ~ City + Duration,
family = binomial(logit), data = MyData)
prediction <- predict(LogModel, MyData, type = "response")
为了获得brier分数,我应该在brierscore()
函数中使用哪些参数?
发布于 2016-11-27 02:53:21
请注意,对于glm拟合,fit$residuals
将返回working残差,而不是预测的概率。预测的概率可以使用residuals(fit,type='response')
获得。有关glm拟合的残差类型的帖子,请参阅here和here。
以下是使用mtcars
数据集计算Brier分数的示例:
fit <- glm(am~hp+wt,data=mtcars,family='binomial')
pred.prob <- predict(fit,type='response')
brierScore <- mean((pred.prob-mtcars$am)^2)
# 0.04659236
下面是another post关于如何计算Brier分数的说明。
发布于 2014-08-06 05:00:12
Brier分数实际上是残差平方的平均值。残差存储在每个glm
模型输出中。所以你可以用手来做:
# Create some data (from ?profile.glm)
ldose <- rep(0:5, 2)
numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16)
sex <- factor(rep(c("M", "F"), c(6, 6)))
SF <- cbind(numdead, numalive = 20 - numdead)
# Run a model
budworm.lg0 <- glm(SF ~ sex + ldose - 1, family = binomial)
# Brier score
mean(budworm.lg0$residuals^2)
https://stackoverflow.com/questions/25149023
复制