-
Notifications
You must be signed in to change notification settings - Fork 1
/
Global.R
70 lines (49 loc) · 2.01 KB
/
Global.R
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
#Loading Required Packages
library(shiny)
library(shinydashboard)
library(tidyverse)
library(dplyr)
library(treemap)
library(d3treeR) #helpful to make zoomable treemap
library(data.table) #needed to read large files fast
library(plotly)
library(DT)
library(knitr)
library(arules)#for Rule Mining
library(arulesViz)
library(visNetwork)#network net
library(igraph)
library(RColorBrewer)
library(billboarder)#for D3.js charts
library(shinyWidgets)
# we'll need the development version of data.tree. If you do not have, install it
#devtools::install_github("gluc/data.tree")
#remotes::install_github("d3treeR/d3treeR")
#read/import the file that we use
insta <- fread("./insta_ready.csv")
#tr <- read.transactions('./transactions.csv', format = 'basket', sep=',')
#PREPARE DATA FOR DRAWING 1ST AND 2ND MENUITEMS TREEMAPS
tree1<-insta %>%
distinct(product_name, .keep_all = TRUE)%>%
group_by(department, aisle) %>%
summarize(n=n())
tree2 <- insta %>%
group_by(department, aisle) %>%
summarize(n=n())
#DATA FOR ORDER LEVEL ANALYSIS
orders_heat= insta%>% group_by(order_dow, order_hour_of_day)%>%
summarise(Order_number=n())
#####DEPENDENCIES FOR BASKET ANALYSIS AND DRAWING visNETWORK###############
# get the shopping baskets and draw vis Network
order_baskets <- insta %>%
select(order_id, product_name) %>%
group_by(order_id) %>%
summarise(basket = as.vector(list(product_name)))
transactions <- as(order_baskets$basket, "transactions")
rules1 <- apriori(transactions, parameter = list(supp = 0.003269976, conf = 0.01, maxlen=3), control = list(verbose = FALSE))
#rules_table1<-data.table(lhs=labels(lhs(rules1)), rhs=(labels(rhs(rules1))), quality(rules1))
### Frequent Item Sets #####
support <- 0.008
itemsets <- apriori(transactions, parameter = list(target = "frequent itemsets", supp=support, minlen=2), control = list(verbose = FALSE))
par(mar=c(5,18,2,2)+.1)
sets_order_supp <- DATAFRAME(sort(itemsets, by="support", decreasing = F))