首页 > 解决方案 > 如何计算R中混淆矩阵的特异性?

问题描述

R-Porgramming:使用 ISLR 库的 Smarket 数据集,我如何计算(代码)混淆矩阵的特异性(如表(glm.pred,Direction.2005)所示)?到目前为止,这是我的代码:

train = (Year<2005) # Vector of 1250 elements
Smarket.2005 = Smarket[!train,]
dim(Smarket.2005) # 252 observations
Direction.2005 = Direction[!train]

# Refit model using just Lag1 and Lag2
glm.fits = glm(Direction~Lag1+Lag2, data = Smarket, family = binomial, subset = train)
glm.probs = predict(glm.fits, Smarket.2005, type = "response")
glm.pred = rep("Down", 252)
glm.pred[glm.probs > .5] = "Up"
table(glm.pred, Direction.2005)
mean(glm.pred == Direction.2005) # 55.95 correct predictions for train
mean(glm.pred != Direction.2005)

标签: r

解决方案


推荐阅读