data("iris")
# discretize and convert to transactions
iris.trans <- prepareTransactions(Species ~ ., iris)
# mine CARs with items for "Species" in the RHS.
# Note: mineCars uses a default a minimum coverage (lhs support) of 0.1, a
# minimum confidence of .5 and maxlen of 5
cars <- mineCARs(Species ~ ., iris.trans)
inspect(head(cars))
# specify minimum support and confidence
cars <- mineCARs(Species ~ ., iris.trans,
parameter = list(support = 0.3, confidence = 0.9, maxlen = 3))
inspect(head(cars))
# for convenience this can also be written without a list for parameter using ...
cars <- mineCARs(Species ~ ., iris.trans, support = 0.3, confidence = 0.9, maxlen = 3)
# restrict the predictors to items starting with "Sepal"
cars <- mineCARs(Species ~ Sepal.Length + Sepal.Width, iris.trans)
inspect(cars)
# using different support for each class
cars <- mineCARs(Species ~ ., iris.trans, balanceSupport = c(
"Species=setosa" = 0.1,
"Species=versicolor" = 0.5,
"Species=virginica" = 0.01), confidence = 0.9)
cars
# balance support for class imbalance
data("Lymphography")
Lymphography_trans <- as(Lymphography, "transactions")
classFrequency(class ~ ., Lymphography_trans)
# mining does not produce CARs for the minority classes
cars <- mineCARs(class ~ ., Lymphography_trans, support = .3, maxlen = 3)
classFrequency(class ~ ., cars, type = "absolute")
# Balance support by reducing the minimum support for minority classes
cars <- mineCARs(class ~ ., Lymphography_trans, support = .3, maxlen = 3,
balanceSupport = TRUE)
classFrequency(class ~ ., cars, type = "absolute")
# Mine CARs from regular transactions (a negative class item is automatically added)
data(Groceries)
cars <- mineCARs(`whole milk` ~ ., Groceries,
balanceSupport = TRUE, support = 0.01, confidence = 0.8)
inspect(sort(cars, by = "lift"))
Run the code above in your browser using DataLab