-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMLBirdsARM.Rmd
More file actions
98 lines (73 loc) · 2.35 KB
/
MLBirdsARM.Rmd
File metadata and controls
98 lines (73 loc) · 2.35 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
title: "MLBirdsARM"
author: "Andrew Edds"
date: "10/3/2022"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
##### LOADING THE PACKAGES AND LIBRARIES #####
##### install as needed
library(arules)
library(rtweet)
library(twitteR)
library(ROAuth)
library(jsonlite)
library(streamR)
library(rjson)
library(tokenizers)
library(tidyverse)
library(plyr)
library(dplyr)
library(ggplot2)
library(syuzhet)
library(stringr)
library(arulesViz)
```
```{r}
##### CREATING BLANK CSV AND READING BIRDS DATASET #####
BirdCallTransactions = 'CallTransactions.csv'
Birds = read.csv("C:/Users/15202/Desktop/Birds_United_States.csv")
```
```{r}
##### APENDING BLANK CSV WITH BIRD CALL TRANSACTIONS #####
calls = file(BirdCallTransactions)
Tokens = tokenizers::tokenize_words(Birds$type[1], stopwords=stopwords::stopwords('en'),
lowercase=TRUE, strip_punct = TRUE, simplify=TRUE)
cat(unlist(str_squish(Tokens)), "\n", file=calls,sep=',')
close(calls)
calls = file(BirdCallTransactions, open='a')
for(i in 2:nrow(Birds)){
tokens = tokenizers::tokenize_words(Birds$type[i], stopwords=stopwords::stopwords('en'),
lowercase=TRUE, strip_punct = TRUE, simplify=TRUE)
cat(unlist(str_squish(tokens)), "\n", file=calls,sep=',')
}
close(calls)
```
```{r}
##### READING AS TRANSACTIONS #####
callsTrans <- read.transactions(BirdCallTransactions, rm.duplicates=FALSE,format='basket', sep=',')
```
```{r, results='hide'}
##### RULE MINING #####
BirdCallRules = arules :: apriori(callsTrans, parameter=list(support=0.01, confidence = 0.01, minlen=2, maxlen=15))
```
```{r}
##### SORTING RULES BY SUPPORT, LIFT, AND CONFIDENCE #####
supportSortedRules <- sort(BirdCallRules, by='support', decreasing=TRUE)
liftSortedRules <- sort(BirdCallRules, by='lift', decreasing=TRUE)
confidenceSortedRules <- sort(BirdCallRules, by='confidence', decreasing=TRUE)
inspect(supportSortedRules[1:15])
inspect(liftSortedRules[1:15])
inspect(confidenceSortedRules[1:15])
```
```{r}
##### PLOT 1 #####
plot(supportSortedRules[1:25], method='graph', engine='htmlwidget', shading = 'confidence')
```
```{r}
##### PLOT 2 #####
plot(liftSortedRules[1:15], method='graph', shading = 'confidence')
```