devices <- read.csv(file = 'devices.csv')
head(devices)
## deviceid devicetype
## 1 014D90 nCounter
## 2 014D98 nCounter
## 3 014D9A nCounter
## 4 A81758FFFE03EDBA Elsys.SE ESM5K
## 5 A81758FFFE03EDBC Elsys.SE ESM5K
## 6 civic_carpark_nth_west_corner Cisco Meraki
## name
## 1 Barwon Valley Activity Centre - Childrens Creche
## 2 Barwon Valley Activity Centre - South Car Park entrance
## 3 Barwon Valley Activity Centre - Basketball Courts
## 4 Ryrie/Union median CCTV/wifi cabinet
## 5 Ryrie/Moorabool CCTV/wifi cabinet
## 6 City Hall
## location latitude longitude device_serial
## 1 -38.1686428, 144.3509363 -38.16864 144.3509 014D90
## 2 -38.1691458, 144.3511856 -38.16915 144.3512 014D98
## 3 -38.1687411, 144.3510241 -38.16874 144.3510 014D9A
## 4 -38.1496331, 144.360899 -38.14963 144.3609
## 5 -38.1493579, 144.3595975 -38.14936 144.3596
## 6 -38.147158, 144.358161 -38.14716 144.3582
## device_use location_parameters device_status device_notes
## 1 Wifi Device Counter NA
## 2 Wifi Device Counter Active NA
## 3 Wifi Device Counter NA
## 4 Indoor Temp Sensor NA
## 5 Indoor Temp Sensor NA
## 6 Wifi Device Counter NA
## network network_app
## 1 LoraWAN (TTN) NA
## 2 LoraWAN (TTN) NA
## 3 LoraWAN (TTN) NA
## 4 LoraWAN (TTN) NA
## 5 LoraWAN (TTN) NA
## 6 NA
- Remove the columns that have numerical columns
devices[["location"]] <- NULL
devices[["latitude"]] <- NULL
devices[["longitude"]] <- NULL
devices[["location_parameters"]] <- NULL
devices[["network_app"]] <- NULL
head(devices)
## deviceid devicetype
## 1 014D90 nCounter
## 2 014D98 nCounter
## 3 014D9A nCounter
## 4 A81758FFFE03EDBA Elsys.SE ESM5K
## 5 A81758FFFE03EDBC Elsys.SE ESM5K
## 6 civic_carpark_nth_west_corner Cisco Meraki
## name device_serial
## 1 Barwon Valley Activity Centre - Childrens Creche 014D90
## 2 Barwon Valley Activity Centre - South Car Park entrance 014D98
## 3 Barwon Valley Activity Centre - Basketball Courts 014D9A
## 4 Ryrie/Union median CCTV/wifi cabinet
## 5 Ryrie/Moorabool CCTV/wifi cabinet
## 6 City Hall
## device_use device_status device_notes network
## 1 Wifi Device Counter NA LoraWAN (TTN)
## 2 Wifi Device Counter Active NA LoraWAN (TTN)
## 3 Wifi Device Counter NA LoraWAN (TTN)
## 4 Indoor Temp Sensor NA LoraWAN (TTN)
## 5 Indoor Temp Sensor NA LoraWAN (TTN)
## 6 Wifi Device Counter NA
- Convert the other columns into categorical columns
install.packages("Matrix")
## Installing package into '/home/fatimah/R/x86_64-pc-linux-gnu-library/4.0'
## (as 'lib' is unspecified)
- Convert the data frame dataset into transactional dataset.
library(arules)
## Loading required package: Matrix
##
## Attaching package: 'arules'
## The following objects are masked from 'package:base':
##
## abbreviate, write
library(Matrix)
smartcity <- as(devices, "transactions")
## Warning: Column(s) 1, 2, 3, 4, 5, 6, 8 not logical or factor. Applying default
## discretization (see '? discretizeDF').
class(smartcity)
## [1] "transactions"
## attr(,"package")
## [1] "arules"
smartcity
## transactions in sparse format with
## 76 transactions (rows) and
## 215 items (columns)
summary(smartcity)
## transactions as itemMatrix in sparse format with
## 76 rows (elements/itemsets/transactions) and
## 215 columns (items) and a density of 0.03255814
##
## most frequent items:
## network=LoraWAN (TTN) device_status=Active
## 54 48
## device_use=Wifi Device Counter devicetype=nCounter
## 39 32
## devicetype=Turbo (Other)
## 29 330
##
## element (itemset/transaction) length distribution:
## sizes
## 7
## 76
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 7 7 7 7 7 7
##
## includes extended item information - examples:
## labels variables levels
## 1 deviceid=013A2C deviceid 013A2C
## 2 deviceid=014D90 deviceid 014D90
## 3 deviceid=014D98 deviceid 014D98
##
## includes extended transaction information - examples:
## transactionID
## 1 1
## 2 2
## 3 3
- Perform A-Priori Analysis
rules1<- apriori(smartcity,parameter = list(sup = 0.3, conf = 0.5,target="rules"));
## Apriori
##
## Parameter specification:
## confidence minval smax arem aval originalSupport maxtime support minlen
## 0.5 0.1 1 none FALSE TRUE 5 0.3 1
## maxlen target ext
## 10 rules TRUE
##
## Algorithmic control:
## filter tree heap memopt load sort verbose
## 0.1 TRUE TRUE FALSE TRUE 2 TRUE
##
## Absolute minimum support count: 22
##
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[215 item(s), 76 transaction(s)] done [0.00s].
## sorting and recoding items ... [6 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 done [0.00s].
## writing ... [23 rule(s)] done [0.00s].
## creating S4 object ... done [0.00s].
inspect(rules1)
## lhs rhs support confidence coverage lift count
## [1] {} => {device_use=Wifi Device Counter} 0.5131579 0.5131579 1.0000000 1.000000 39
## [2] {} => {device_status=Active} 0.6315789 0.6315789 1.0000000 1.000000 48
## [3] {} => {network=LoraWAN (TTN)} 0.7105263 0.7105263 1.0000000 1.000000 54
## [4] {devicetype=Turbo} => {device_use=Parking} 0.3815789 1.0000000 0.3815789 2.620690 29
## [5] {device_use=Parking} => {devicetype=Turbo} 0.3815789 1.0000000 0.3815789 2.620690 29
## [6] {devicetype=Turbo} => {device_status=Active} 0.3684211 0.9655172 0.3815789 1.528736 28
## [7] {device_status=Active} => {devicetype=Turbo} 0.3684211 0.5833333 0.6315789 1.528736 28
## [8] {device_use=Parking} => {device_status=Active} 0.3684211 0.9655172 0.3815789 1.528736 28
## [9] {device_status=Active} => {device_use=Parking} 0.3684211 0.5833333 0.6315789 1.528736 28
## [10] {devicetype=nCounter} => {device_use=Wifi Device Counter} 0.4210526 1.0000000 0.4210526 1.948718 32
## [11] {device_use=Wifi Device Counter} => {devicetype=nCounter} 0.4210526 0.8205128 0.5131579 1.948718 32
## [12] {devicetype=nCounter} => {network=LoraWAN (TTN)} 0.3552632 0.8437500 0.4210526 1.187500 27
## [13] {network=LoraWAN (TTN)} => {devicetype=nCounter} 0.3552632 0.5000000 0.7105263 1.187500 27
## [14] {device_use=Wifi Device Counter} => {network=LoraWAN (TTN)} 0.3552632 0.6923077 0.5131579 0.974359 27
## [15] {network=LoraWAN (TTN)} => {device_use=Wifi Device Counter} 0.3552632 0.5000000 0.7105263 0.974359 27
## [16] {device_status=Active} => {network=LoraWAN (TTN)} 0.4736842 0.7500000 0.6315789 1.055556 36
## [17] {network=LoraWAN (TTN)} => {device_status=Active} 0.4736842 0.6666667 0.7105263 1.055556 36
## [18] {devicetype=Turbo,
## device_use=Parking} => {device_status=Active} 0.3684211 0.9655172 0.3815789 1.528736 28
## [19] {devicetype=Turbo,
## device_status=Active} => {device_use=Parking} 0.3684211 1.0000000 0.3684211 2.620690 28
## [20] {device_use=Parking,
## device_status=Active} => {devicetype=Turbo} 0.3684211 1.0000000 0.3684211 2.620690 28
## [21] {devicetype=nCounter,
## device_use=Wifi Device Counter} => {network=LoraWAN (TTN)} 0.3552632 0.8437500 0.4210526 1.187500 27
## [22] {devicetype=nCounter,
## network=LoraWAN (TTN)} => {device_use=Wifi Device Counter} 0.3552632 1.0000000 0.3552632 1.948718 27
## [23] {device_use=Wifi Device Counter,
## network=LoraWAN (TTN)} => {devicetype=nCounter} 0.3552632 1.0000000 0.3552632 2.375000 27