The LesMiserables network dataset is provided as a gml file, containing 77 nodes and 254 edges.
# Start the timer
t1 <- system.time({
dataset_path <- system.file("extdata", "lesmiserables.gml", package = "arlclustering")
if (dataset_path == "") {
stop("lesmiserables.gml file not found")
}
g <- arlc_get_network_dataset(dataset_path, "LesMiserables")
g$graphLabel
g$totalEdges
g$totalNodes
g$averageDegree
})
# Display the total processing time
message("Graph loading Processing Time: ", t1["elapsed"], " seconds\n")
#> Graph loading Processing Time: 0.0140000000000029 seconds
Next, we generate transactions from the graph, with a total rows of 59
We obtain the apriori thresholds for the generated transactions. The following are the thresholds for the apriori execution: - The Minimum Support : 0.04 - The Minimum Confidence : 0.5 - The Lift : 19.66667 - The Gross Rules length : 51764 - The selection Ratio : 877
# Start the timer
t3 <- system.time({
params <- arlc_get_apriori_thresholds(transactions,
supportRange = seq(0.04, 0.06, by = 0.01),
Conf = 0.5)
params$minSupp
params$minConf
params$bestLift
params$lenRules
params$ratio
})
# Display the total processing time
message("Graph loading Processing Time: ", t3["elapsed"], " seconds\n")
#> Graph loading Processing Time: 0.141999999999999 seconds
We use the obtained parameters to generate gross rules, where we obtain 51774 rules.
# Start the timer
t4 <- system.time({
minLenRules <- 1
maxLenRules <- params$lenRules
if (!is.finite(maxLenRules) || maxLenRules > 5*length(transactions)) {
maxLenRules <- 5*length(transactions)
}
grossRules <- arlc_gen_gross_rules(transactions,
minSupp = params$minSupp,
minConf = params$minConf,
minLenRules = minLenRules+1,
maxLenRules = maxLenRules)
grossRules$TotalRulesWithLengthFilter
})
#> Apriori
#>
#> Parameter specification:
#> confidence minval smax arem aval originalSupport maxtime support minlen
#> 0.5 0.1 1 none FALSE TRUE 5 0.04 2
#> maxlen target ext
#> 295 rules TRUE
#>
#> Algorithmic control:
#> filter tree heap memopt load sort verbose
#> 0.1 TRUE TRUE FALSE TRUE 2 TRUE
#>
#> Absolute minimum support count: 2
#>
#> set item appearances ...[0 item(s)] done [0.00s].
#> set transactions ...[77 item(s), 59 transaction(s)] done [0.00s].
#> sorting and recoding items ... [50 item(s)] done [0.00s].
#> creating transaction tree ... done [0.00s].
#> checking subsets of size 1 2 3 4 5 6 7 8 9 10 11 done [0.00s].
#> writing ... [51774 rule(s)] done [0.01s].
#> creating S4 object ... done [0.01s].
We filter out redundant rules from the generated gross rules. Next, we filter out non-significant rules from the non-redundant rules, and we obtain the 1625 rule items.
t5 <- system.time({
NonRedRules <- arlc_get_NonR_rules(grossRules$GrossRules)
NonRSigRules <- arlc_get_significant_rules(transactions,
NonRedRules$FiltredRules)
#NonRSigRules$TotFiltredRules
})
# Display the total number of clusters and the total processing time
message("\nClearing rules Processing Time: ", t5["elapsed"], " seconds\n")
#>
#> Clearing rules Processing Time: 0.330000000000002 seconds
We clean the final set of rules to prepare for clustering. Then, we generate clusters based on the cleaned rules. The total identified clusters is 7 clusters.
t6 <- system.time({
cleanedRules <- arlc_clean_final_rules(NonRSigRules$FiltredRules)
clusters <- arlc_generate_clusters(cleanedRules)
#clusters$TotClusters
})
# Display the total number of clusters and the total processing time
message("Cleaning final rules Processing Time: ", t6["elapsed"], " seconds\n")
#> Cleaning final rules Processing Time: 0.0990000000000002 seconds
Finally, we visualize the identified clusters.
arlc_clusters_plot(g$graph,
g$graphLabel,
clusters$Clusters)
#>
#> Total Identified Clusters: 7
#> =========================
#> Community 01:12 17 24 25 26 27 28 30 35 36 37 38 39 42 49 50 52 55 56 58 59 60 61 62 63 64 65 66 67 69 70 71 72 76 77
#> Community 02:17 18 19 20 21 22 23 24
#> Community 03:24 25 26 27 28 32 49 56 69 70 71 72
#> Community 04:25 26 27 28 30 32 42 44 49 56 59 69 70 71 72 73 76
#> Community 05:26 27 28 30 32 42 44 49 50 52 56 58 59 63 65 69 70 71 72 73 76
#> Community 06:30 32 35 36 37 38 39
#> Community 07:43 69 70 71
#> =========================