##########################################
## Homework 2
##########################################
Copyright By PowCoder代写 加微信 powcoder
##########################################
## Question 1. Identify Course Combinations
##########################################
rm(list=ls())
# Load and clean data.
course.df <- read.csv("./Data/Coursetopics.csv")
course.mat <- as.matrix(course.df)
head(course.mat, 10)
library(arules)
# Recast incidence matrix into transcations list.
course.trans <- as(course.mat, "??")
# Generate rules with the highest lift.
options(digits = 2, scipen = 1)
rules <- ??
inspect(head(sort(rules, by = "??"), 5))
##########################################
## Question 2
##########################################
rm(list=ls())
#load the data
bank.df <- read.csv("./Data/UniversalBankFull.csv")
#consider only the required variables
bank.df <- bank.df[ , c(13, 14, 10)]
bank.df$Online <- as.factor(bank.df$Online)
bank.df$CreditCard <- as.factor(bank.df$CreditCard)
bank.df$Personal.Loan <- as.factor(bank.df$Personal.Loan)
str(bank.df)
#partition the data into history (60%) and future (40%) sets
#set the seed for the random number generator for reproducing the partition.
set.seed(12345)
ntotal <- length(bank.df$Personal.Loan)
#Sample row numbers randomly.
nhistory.index <- sort(sample(ntotal, round(ntotal * 0.6)))
history.df <- bank.df[nhistory.index, ]
future.df <- bank.df[-nhistory.index, ]
#check if variables in the dataset are correctly identified for their types
str(bank.df)
str(history.df)
# Find P(Personal.Loan = 1|CreditCard=1, Online=1)
library(??)
loan.nb <- naiveBayes(??, data = history.df)
## predict probabilities
loan.pred.prob <- predict(loan.nb, newdata = future.df, type = "raw")
loan.combined.df <- data.frame(actual = future.df$Personal.Loan, loan.pred.prob)
str(loan.combined.df)
head(loan.combined.df[??, ])
# Find P(CreditCard=0|Personal.Loan=1)
##########################################
## Question 3
##########################################
rm(list=ls())
set.seed(100)
r40000 <- ??norm(40000)
??(r40000, breaks= 200, probability=T, xlab="value", ylab="density")
##########################################
## Question 4
##########################################
rm(list=ls())
benefit.df <- read.csv('./Data/benefits.csv') # read data
head(benefit.df)
str(benefit.df)
??(benefit.df, conf.level = 0.95)
PME <- 0.02
conf.level <- ??
alpha <- ??
z = qnorm(1 - alpha/2)
n = z^2*p*(1-p)/PME^2
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com