***
```{r, warning = FALSE, message = FALSE}
# suggested packages
library(MASS)
library(caret)
library(tidyverse)
library(knitr)
library(kableExtra)
library(mlbench)
library(ISLR)
library(ellipse)
library(randomForest)
library(gbm)
library(glmnet)
library(rpart)
library(rpart.plot)
library(klaR)
library(gam)
library(e1071)
# feel free to use additional packages
```
***
# Classification
```{r, message = FALSE, warning = FALSE}
class_trn = read_csv("https://daviddalpiaz.github.io/stat432sp18/hw/hw08/class-trn.csv")
class_tst = read_csv("https://daviddalpiaz.github.io/stat432sp18/hw/hw08/class-tst.csv")
```
```{r}
accuracy = function(actual, predicted) {
mean(actual == predicted)
}
```
```{r}
# classification task
# place code here that trains the model used to submit your best result
# only supply code needed to train that model
```
```{r, eval = FALSE}
# place code here that stores the test predictions that you submitted
class_pred = # use this variable
```
***
# Regression
```{r, message = FALSE, warning = FALSE}
reg_trn = read_csv("https://daviddalpiaz.github.io/stat432sp18/hw/hw08/reg-trn.csv")
reg_tst = read_csv("https://daviddalpiaz.github.io/stat432sp18/hw/hw08/reg-tst.csv")
```
```{r}
rmse = function(actual, predicted) {
sqrt(mean((actual - predicted) ^ 2))
}
```
```{r}
# regression task
# place code here that trains the model used to submit your best result
# only supply code needed to train that model
```
```{r, eval = FALSE}
# place code here that stores the test predictions that you submitted
reg_pred = # use this variable
```
***
# Spam Filter
```{r, message = FALSE, warning = FALSE}
spam_trn = read_csv("https://daviddalpiaz.github.io/stat432sp18/hw/hw08/spam-trn.csv")
spam_tst = read_csv("https://daviddalpiaz.github.io/stat432sp18/hw/hw08/spam-tst.csv")
```
```{r}
score = function(actual, predicted) {
1 * sum(predicted == "spam" & actual == "spam") +
-25 * sum(predicted == "spam" & actual == "nonspam") +
-1 * sum(predicted == "nonspam" & actual == "spam") +
2 * sum(predicted == "nonspam" & actual == "nonspam")
}
```
```{r}
# spam task
# place code here that trains the model used to submit your best result
# only supply code needed to train that model
```
```{r, eval = FALSE}
# place code here that stores the test predictions that you submitted
spam_pred = # use this variable
```
***