r - 如何计算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)
解决方案
推荐阅读
- python - 熊猫:asfreq 时间序列的奇怪行为
- string - Why commas and underscore is using in Golang. Explain the line 12 in the below code?
- rust - 如何配置 actix-web 以接受来自任何来源的 CORS 请求?
- python - what is the best way to save the memory and save large numpy array to the h5py file?
- microsoft-graph-api - Microsoft Delta Query not returing openextension defined while creating event
- javascript - Is there a method to check if a container needs scrollbars?
- jmeter - Jmeter action based on assertion result
- javascript - 如何从开发人员工具的检查元素中隐藏 html 内容?
- android - DJI MSDK 的哪些功能受“库防失真”模块的影响?
- sql - 在具有不同数据的同时合并多个表