Here my code which is correct, but my problem is I don't know how to add a case where min.sup is greater than the as.numeric(support)
Here's my code:
a <- data.frame(A = c(0,0,1,1,1), B = c(1,0,1,0,0), C = c(0,0,1,1,0), D = c(0,0,1,1,0), E = c(0,1,1,0,1))
support <- apply(a, 2, sum)/nrow(a)
min.sup = 0.6
itemset <- subset(support, min.sup <= support)
vect <- c()
vect <- c(vect, names(itemset))
b <- a[min.sup <= support]
items2 <- c()
countI <- 1
while(countI <= ncol(b)){
for(i in countI){
countJ <- countI + 1
while(countJ <= ncol(b)){
for(j in countJ){
items2 <- c(items2, paste(colnames(b[i]), colnames(b[j]), collapse = '', sep = ""))
}
countJ <- countJ + 1
}
countI <- countI + 1
}
}
count_1 <- unlist(sapply(1:(ncol(b) - 1), function(i) sapply(ncol(b):(i+1), function(j)
sum(b[, i] + b[, j] == 2))))
names(count_1) <- items2
count_1 <- count_1[order(names(count_1))]
cond <- min.sup <= as.numeric(count_1)/nrow(a)
vect <- c(vect, ifelse(cond == TRUE, names(count_1), ""))
print(vect, quote = FALSE)
so If the condition (where min.sup > is.numeric(support)) a message will be printed as follows: print("there are no frequent itemsets - choose another minimum support")
, else it will print vect
without quotes.
Note: another simulation can be made with the following data frame:
a <- data.frame(A = c(1,1,0,1,1), B = c(0,0,1,0,1), C = c(1,0,1,1,1), D = c(1,1,1,1,1))
Aucun commentaire:
Enregistrer un commentaire