-
Notifications
You must be signed in to change notification settings - Fork 0
/
us_machine_learning.Rmd
73 lines (48 loc) · 1.24 KB
/
us_machine_learning.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
title: "U.S. Machine Learning Models"
author: "Joseph Lavicka"
date: "`r Sys.Date()`"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
message = FALSE,
warning = FALSE
)
```
# packages
```{r}
library(tidyverse)
```
# basic models
## tree
```{r}
library(tree)
final %>%
select(1,2,4,10:ncol(final)) -> final_tree
set.seed(42)
train <- sample(1:nrow(final_tree), nrow(final_tree)/2)
final.test <- final_tree[-train,]
n.test <- final_tree$n_bool[-train]
trees <- tree(n_bool ~ . -pop, final_tree, subset = train)
tree.pred <- predict(trees, final.test, type = "class")
table(tree.pred, n.test)
summary(trees)
```
## randomForest
```{r}
library(randomForest)
final %>%
select(1,2,4,10:ncol(final)) -> final_tree
set.seed(42)
train <- sample(1:nrow(final_tree), nrow(final_tree)/2)
final.test <- final_tree[-train,]
n.test <- final_tree$n_bool[-train]
bag.acled <- randomForest(n_bool ~ ., data = final_tree, subset = train, mtry = 12, importance = TRUE)
bag.acled
trees <- tree(n_bool ~ ., final_tree, subset = train)
tree.pred <- predict(trees, final.test, type = "class")
table(tree.pred, n.test)
summary(bag.acled)
```