这个作业是用R语言训练二次判别式(QDA)和逻辑回归分类器

MAST90138 S2 2020 Assignment 3

问题1 [60分]:
在此问题中,您将训练二次判别式(QDA)和逻辑回归
分类器预测测试集中的类别标签(0或1)。
(a)使用R中的标准函数来训练QDA分类器和逻辑分类器
训练集中的p个预测变量。发生了什么?为什么会发生呢?你做
建议在测试集上使用这两个分类器? (提示:对于后勤分类器,
使用摘要功能来查看经过训练的模型对象)[10]
(b)使用prcomp和plsr(软件包pls)函数分别获取PCA和
训练集中的解释变量的PLS(偏最小二乘)分量。
在这里,当考虑PLS的协方差最大化问题时,我们将
X =(X1,…,Xp)之间的协方差
T和Y = 1 {G = 1},指示变量
个人属于第1组。对于每种情况,您都需要使用“投影矩阵”
(例如,在课堂上讨论过的PCA的Γ和PLS的Φ)由该函数报告以重新计算
“手动”检查组件,以了解您如何获取组件。 [10]
(c)使用PLS组件训练QDA分类器,使用PCA组件训练另一个。在每种情况下,请根据遗漏清单选择要使用的组件数
交叉验证(CV);考虑最多使用50个组件。绘制一劳永逸的简历
针对所考虑的组件数量的错误。报告最终选择的数量
组件。 (请参阅第7周的实验以获取一些想法)
对后勤分类器执行相同的操作。
[20]
(d)对于每个QDA和后勤分类器,您希望使用哪个版本(PCA或PLS)?
为什么? (在下一个答案中不了解测试集结果的情况下回答此问题
问题)[5]
(e)将(c)中训练有素的分类器应用于测试集,并报告结果分类
错误(测试错误)。注意如何将测试集中的数据居中
产生您的预测。第7周的实验可能会再给您一些想法。 [15]
2
Problem 2 [30 marks]:
In this problem you will train random forest (RF) classifiers to predict the class labels (0 or
1) in the test set.
(a) Using the randomForest package in R, construct a random forest classifier using all p
predictor variables in the training set. When training the classifier, use the default value
of m (the number of random candidate variables for each split), but justify your choice
for the number of trees B using the out-of-bag (OOB) classification error. Plot a graph
showing the OOB error against the number of trees used. [15]
(b) Show two graphs that illustrate the importance of the Xj variables, for both decrease in
OOB prediction accuracy and decrease in node impurities measured by Gini index. Is
there an explanation of why those particular Xj
’s are the most important for classification
in this rainfall example? [5]
(c) Apply the resulting trained classifier to the test data Xtest, and compute the resulting
classification error. Try training your RF multiple times. Do you always get the same
classification error? If yes, why? If not, why and what can you do to make the forest
more stable and why? [10]