提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

    • 10. This question should be answered using the Weekly data set, which is part of the ISLR package. This data is similar in nature to the Smarket data from this chapter’s lab, except that it contains 1, 089 weekly returns for 21 years, from the beginning of 1990 to the end of 2010.
      • (a) Produce some numerical and graphical summaries of the Weekly data. Do there appear to be any patterns?
      • (b) Use the full data set to perform a logistic regression with Direction as the response and the five lag variables plus Volume as predictors. Use the summary function to print the results.
        • Do any of the predictors appear to be statistically significant? If so, which ones?
      • (c) Compute the confusion matrix and overall fraction of correct predictions. Explain what the confusion matrix is telling you about the types of mistakes made by logistic regression.
      • (d) Now fit the logistic regression model using a training data period from 1990 to 2008, with Lag2 as the only predictor. Compute the confusion matrix and the overall fraction of correct predictions for the held out data (that is, the data from 2009 and 2010).
      • (e) Repeat (d) using LDA.
      • (f) Repeat (d) using QDA.
  • 总结

10. This question should be answered using the Weekly data set, which is part of the ISLR package. This data is similar in nature to the Smarket data from this chapter’s lab, except that it contains 1, 089 weekly returns for 21 years, from the beginning of 1990 to the end of 2010.

(a) Produce some numerical and graphical summaries of the Weekly data. Do there appear to be any patterns?

library(ISLR)
library(MASS)
View(Weekly)
# str(Weekly)
summary(Weekly)
attach(Weekly)
#相关阵
cor(Weekly[,-9])

相关性都不大

#数据矩阵散点图
pairs(Weekly[,-9])
par(mfrow=c(3,3))
name=colnames(Weekly[,-9]) #提取列名
for(i in 2:8){hist(Weekly[,i],col =2, breaks =20,xlab=name[i],main="频数直方图")
}
# 箱线图
par(mfrow=c(1,1))
boxplot(Weekly[,2:8],Weekly[,9])

(b) Use the full data set to perform a logistic regression with Direction as the response and the five lag variables plus Volume as predictors. Use the summary function to print the results.

glm.fits <-glm(Direction~Lag1+Lag2+Lag3+Lag4+Lag5+Volume,data=Weekly,family=binomial)
summary(glm.fits)

Do any of the predictors appear to be statistically significant? If so, which ones?

Lag2*显著,具有统计学意义

glm.pred=predict(glm.fits)
glm.pred[1:10]

© Compute the confusion matrix and overall fraction of correct predictions. Explain what the confusion matrix is telling you about the types of mistakes made by logistic regression.

glm.probs <- predict(glm.fits,type = "response")
contrasts(Direction)
glm.pred=rep("Up",length(glm.probs))
glm.pred[glm.probs <.5]="Down"
table(glm.pred ,Direction)
mean(glm.pred==Direction)
54/(48+54)
557/(557+430)

56%的市场动向可以被正确预测
混淆矩阵表明用逻辑斯蒂回归模型预测市场下跌时,只有54/(48+54)=52.9%
混淆矩阵表明用逻辑斯蒂回归模型预测市场上涨时,只有557/(557+430)=56.4%

(d) Now fit the logistic regression model using a training data period from 1990 to 2008, with Lag2 as the only predictor. Compute the confusion matrix and the overall fraction of correct predictions for the held out data (that is, the data from 2009 and 2010).

train = (Year<=2008)
test<- Weekly[!train,] #
dim(test)
Direction_data<-Direction[!train] # glm.fits1 <- glm(Direction~Lag2,data=Weekly,family = binomial,subset = train)
summary(glm.fits1)
glm.probs1 <- predict(glm.fits1,test,type = "response")#
glm.pred1=rep ("Up",length(glm.probs1))
glm.pred1[glm.probs1 <.5]="Down"
table(glm.pred1,Direction_data)
mean(glm.pred1 == Direction_data)9/(9+5)
56/(56+34)

调整后的逻辑回归,62.5%的市场动向可以被正确预测
混淆矩阵表明用逻辑斯蒂回归模型预测市场下跌时,只有9/(9+5)=64.3%
混淆矩阵表明用逻辑斯蒂回归模型预测市场上涨时,只有56/(56+34)=62.2%

(e) Repeat (d) using LDA.

library(MASS)
lda.fit <- lda(Direction~Lag2,data=Weekly,subset = train)
lda.fit
# plot(lda.fit)
lda.pred=predict (lda.fit,test)
names(lda.pred)
lda.class=lda.pred$class
table(lda.class ,Direction_data)
mean(lda.class==Direction_data)# 62.5%

(f) Repeat (d) using QDA.

qda.fit <- qda(Direction~Lag2,data=Weekly,subset = train)
qda.fit
# plot(lda.fit)
qda.pred=predict (qda.fit,test)
names(qda.pred)
qda.class=qda.pred$class
table(qda.class ,Direction_data)
mean(qda.class==Direction_data)# 58.7%

总结

以上均为个人观点,由于个人能力有限,难免有差错,还请多多指教

统计机器学习导论第四章答案相关推荐

  1. 统计机器学习导论第二章答案

    R语言学习笔记 统计机器学习导论第二章部分习题 文章目录 R语言学习笔记 一.8题 8. This exercise relates to the College data set, which ca ...

  2. 李航《统计学习方法》第四章课后答案链接

    李航<统计学习方法>第四章课后答案链接 本博客转载自:http://blog.csdn.net/xiaoxiao_wen/article/details/54097917

  3. 计算机文化基础(高职高专版 第十一版)第四章答案

    1.简述工作簿.工作表.单元格之间的关系. 工作簿:指在Excel中用来存储并处理数据的文件,扩展名是.xlsx.由一个或多个工作表组成.工作表:是由行和列交叉排列的二维表格,也称电子表格,用于组织和 ...

  4. 数据结构与算法python语言实现-第四章答案

    数据结构与算法python语言实现-第四章答案 4.1 def findmax(S, index=0):if index == len(S) - 1:return S[index]max=findma ...

  5. 李弘毅机器学习:第四章—梯度下降法

    李弘毅机器学习:第四章-梯度下降法 什么是梯度下降法? Review: 梯度下降法 Tip1:调整学习速率 小心翼翼地调整学习率 自适应学习率 Adagrad 算法 Adagrad 是什么? Adag ...

  6. 工程导论 第四章 创造力 读书笔记

    阅读工程导论 第四章 笔记 工程师是一个需要创造力的职业,创造力对于工程师来说是不可或缺的一种能力. 而工程的实现不仅需要个人的创造力,还要群体的创造力,个人的创造力来自于个人的专业素养和生活经历,而 ...

  7. 机器学习实战——第四章(分类):朴素贝叶斯

    前言 首先感谢博主:Jack-Cui 主页:http://blog.csdn.net/c406495762 朴素贝叶斯博文地址: https://blog.csdn.net/c406495762/ar ...

  8. 深圳大学计算机英语作业答案,2016年深圳大学大学计算机基础mooc课第四章答案...

    测验:第四章作业 提交时间:2016-11-29 21:11:53试卷状态:已批改已公布成绩 1. 假设将选择符号的判断条件disc<0更改为disc>=0,其他的基本符号不变,那么流程图 ...

  9. 利用逆矩阵解线性方程组_机器人学导论---第四章 操作臂逆运动学(一)4.1-4.11...

    第四章 操作臂逆运动学[(一)4.1-4.11] (一)概述 1.为求出要求的关节角以放置相对于工作台坐标系{S}的工具坐标系{T},可将这个问题分为两部分(1)进行坐标变换求出相对于基坐标{B}的腕 ...

  10. 梅创社c语言答案,c语言程序设计第2版) 教学课件 作者 梅创社答案 第四章答案.docx...

    说明:所有答案均在VC++6.0环境下调试运行通过 第四章 参考答案 选择题 1.B 2.D 3.B 4.B 5.A 6.D 7.C 8.B 9.BEF 10. B 11.D 12.D 13.A 注意 ...

最新文章

  1. matlab-基础 size 获取矩阵的行数与列数
  2. mysql服务等待应答超时_MySQL-Communications link failure异常分析及解决方法
  3. HDU-2149(博弈)
  4. c语言1到20找最大和最小相邻,一组数据里面怎样查找相邻和相同的整数算法设计解决方案...
  5. linux优化pdf,linux系统安全和优化.pdf
  6. 菜鸟python_菜鸟爱Python第1期:Python发展史?对Python最深刻的解读
  7. 邹城的关于机器人教育_【喜报】我校机器人队问鼎全国大学生机器人大赛冠军!...
  8. 如何修复“您的系统已耗尽应用程序内存”错误
  9. 如何用python写程序设置当前打印机为默认打印机,从Python打印到标准打印机?
  10. JavaWeb程序的目录结构(2)
  11. AutoCAD2020简体中文语言包
  12. AutoCAD2007专业版
  13. PDF--变清晰方法
  14. 安装TimeGen波形绘图软件
  15. 完全但不完美信息博弈
  16. 什么是SEO,为什么要做SEO?
  17. python删除指定元素 多个_Python List remove()删除多个元素
  18. 微信小程序10-微搭模板
  19. 语法基础——C语法基础
  20. socket 长链接linux,手把手教你写 Socket 长连接

热门文章

  1. 绕过杀软(二)——免杀exe文件(360、火绒免杀)
  2. VSCode中安装Django插件后实现html语法提示
  3. 用什么计算机演奏音乐,用这个你可以用自己的电脑弹奏美妙的音乐.
  4. 修好了一个罗技鼠标,鼠标左键单击变双击问题解决了。
  5. 手机号码归属地查询api [开源]
  6. 剑桥: 一个完美的读书地方
  7. Eclipse插件开发之拖拽功能
  8. java drawline_如何设置java drawLine画的线的粗细
  9. 浅析免费加密软件应该如何选择性下载
  10. 计算机地图制图的点状符号制作,计算机地图制图地图符号库系统建立全解.doc...