作业8答案

练习1 关联分析

  1. 在Titanic数据集上实现关联分析算法
  2. 对1中的算法进行评估
> data("Titanic")
> df <- as.data.frame(Titanic)
> titanic.raw <- NULL
> for(i in 1:4){
       titanic.raw <- cbind(titanic.raw,rep(as.character(df[,i]),df$Freq))
  }
> titanic.raw <- as.data.frame(titanic.raw)
> names(titanic.raw) <- names(df)[1:4]
> install.pachkages("arules")
> library(arules)
> rules<-apriori(titanic.raw,control=list(verbose=F),parameter=list(minlen=2,supp=0.005,conf=0.8),appearance=list(rhs=c("Survived=No","Survived=Yes"),default="lhs"))
> quality(rules) <- round(quality(rules),digits=3)
> rules.sorted <- sort(rules,by="lift")
> inspect(rules.sorted)
> plot(rules,method="graph")

练习2 回归分析

  1. 计算iris数据集中个变量之间的相关系数
  2. 选取1中计算的相关系数最大的两个变量计算其拟合函数
  3. 对拟合效果进行评估
> cor(iris[,1:4])
             Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length    1.0000000  -0.1175698    0.8717538   0.8179411
Sepal.Width    -0.1175698   1.0000000   -0.4284401  -0.3661259
Petal.Length    0.8717538  -0.4284401    1.0000000   0.9628654
Petal.Width     0.8179411  -0.3661259    0.9628654   1.0000000
> (lm1 <- lm(Petal.Length ~ Petal.Width))
> summary(lm1)

练习3 分类算法

  1. 支持向量机分类的主要原理是什么?
  2. 在iris数据集上实现支持向量机算法
  3. 用合适的图形评估2中算法的分类效果
  4. 计算2中算法的预测正确率
> install.packages("e1071")
> library(e1071)
> svm_model <- svm(Species~Petal.Length+Petal.Width,data=iris)
> plot(svm_model,iris,Petal.Length~Petal.Width)

练习4 聚类算法

  1. 使用搜索引擎搜索层次聚类的具体原理以及方法
  2. 查找相关资料实现R语言的系统聚类
  3. 在iris数据集上实现系统聚类
  4. 使用合适的图形输出查看聚类效果
> iris.hc <- hclust( dist(iris[,1:4]))
> plclust( iris.hc, labels = FALSE, hang = -1)
> re <- rect.hclust(iris.hc, k = 3)
> iris.id <- cutree(iris.hc, 3)

练习5 数据挖掘原理

  1. 监督式学习和无监督学习区别是什么
  2. 列举三种分类算法并解释其原理

results matching ""

    No results matching ""