1 Star 0 Fork 0

Trembling/my-first-binder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Ch12.R 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
liyanonline 提交于 2022-01-22 15:08 . Add files via upload
# Clear plots
if(!is.null(dev.list())) dev.off()
# Clean workspace
rm(list=ls())
# Clear console
cat("\014")
# setwd("E:/SSPU/Courses/Courses/BI/Wiley.Data.Mining.for.Business.Analytics.Concepts.Techniques.and.Applications.in.R.1118879368/codes")
####Table 12.1
# install.packages("DiscriMiner")
library(DiscriMiner)
mowers.df <- read.csv("RidingMowers.csv")
da.reg <- linDA(mowers.df[,1:2], mowers.df[,3])
da.reg$functions
#### Table 12.2
da.reg <- linDA(mowers.df[,1:2], mowers.df[,3])
# compute probabilities manually (below); or, use lda() in package MASS with predict()
propensity.owner <- exp(da.reg$scores[,2])/(exp(da.reg$scores[,1])+exp(da.reg$scores[,2]))
data.frame(Actual=mowers.df$Ownership,
da.reg$classification, da.reg$scores, propensity.owner=propensity.owner)
#### Table 12.3
library(DiscriMiner)
library(caret)
accidents.df <- read.csv("Accidents.csv")
lda.reg <- linDA(accidents.df[,1:10], accidents.df[,11])
lda.reg$functions
confusionMatrix(lda.reg$classification, factor(accidents.df$MAX_SEV) )
#### Table 12.4
propensity <- exp(lda.reg$scores[,1:3])/
(exp(lda.reg$scores[,1])+exp(lda.reg$scores[,2])+exp(lda.reg$scores[,3]))
res <- data.frame(Classification = lda.reg$classification,
Actual = accidents.df$MAX_SEV,
Score = round(da.reg$scores,2),
Propensity = round(propensity,2))
head(res)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tremblingv5/my-first-binder.git
git@gitee.com:tremblingv5/my-first-binder.git
tremblingv5
my-first-binder
my-first-binder
main

搜索帮助