代码拉取完成,页面将自动刷新
# 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。