Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi,
the apriori function used with a dataset returns a very small number of rules
library(arules)
library(methods)
#specific for Your data type
SalesData <- as(dataset,"transactions")
# matrix
SalesData2=as.data.frame(as(SalesData, "matrix"))
SalesData2=cbind(id=1:nrow(SalesData2),SalesData2)
#
Temp<-apriori(SalesData2, parameter = list(support = 0.006, confidence = 0.25, minlen = 2, maxlen = 2, target = "rules"))
#
output<-inspect(sort(Temp, by = "lift")[1:6])
only 6 combinations appear instead of 700
While the same function used with a CSV file (same data & columns) returns to me 700 rules
# 'dataset'
library(Matrix)
library(arules)
library(dplyr)
#
SalesData <- read.transactions("...Data.csv", sep = ";")
SalesData<-SalesDate[-1,]
#
Temp<-apriori(SalesData, parameter = list(support = 0.006, confidence = 0.25, minlen = 2, maxlen = 2,target="rules"))
#
#output<-inspect(Temp[1:700])
output<-inspect(Temp[1:length(Temp)])
#output<-inspect(sort(Temp, by = "lift")[1:700])
I think I'm using my dataset wrong (query M)
With or without Matrix I return a very low number of lines
Thanks for your help
Christophe (France power BI "fan")
Solved! Go to Solution.
I found a workaround
library(arules)
library(methods)
# 'dataset' contient les données d'entrée pour ce script
basket_rules<-apriori(dataset, parameter = list(support = 0.006, confidence = 0.10, minlen = 2, maxlen = 2, target = "rules"))
df_basket <- as(basket_rules,"data.frame")
#View(df_basket)
This script provides all rules ...
@Bamak ,
This issue should caused by apriori() function:
apriori(data, parameter = NULL, appearance = NULL, control = NULL)
From the R documentation:
parameter: object of class '>APparameter
or named list. The default behavior is to mine rules with minimum support of 0.1, minimum confidence of 0.8, maximum of 10 items (maxlen), and a maximal time for subset checking of 5 seconds (maxtime).
So you can try changing the maxlen subparameter.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I found a workaround
library(arules)
library(methods)
# 'dataset' contient les données d'entrée pour ce script
basket_rules<-apriori(dataset, parameter = list(support = 0.006, confidence = 0.10, minlen = 2, maxlen = 2, target = "rules"))
df_basket <- as(basket_rules,"data.frame")
#View(df_basket)
This script provides all rules ...
User | Count |
---|---|
93 | |
85 | |
78 | |
68 | |
63 |
User | Count |
---|---|
113 | |
99 | |
97 | |
64 | |
59 |