0
我試圖讓R apriori算法允許我在lhs中同時指定多個屬性。關於R Apriori的lhs的多個條件
rules <- apriori(Data, parameter=list(supp = 0.0001, conf = 0.001, minlen = 2), appearance = list(lhs = c("DiagnoseTekst=Acuut hartfalen"), default="rhs"))
上面一行將篩選只是在一定DiagnoseTekst的LHS(在我的數據列是「MedicatieTekst」,「Geslacht」和「DiagnoseTekst」) 不過,我想這兩個DiagnoseTekst過濾和Geslacht。當我投入
rules <- apriori(Data, parameter=list(supp = 0.0001, conf = 0.001, minlen = 2), appearance = list(lhs = c("DiagnoseTekst=Acuut hartfalen", "Geslacht=M"), default="rhs"))
我得到了一些只有DiagnoseTekst和一些只與Geslacht規則。 (在這種情況下,大多數情況下都應該具有這兩個屬性)。有什麼方法可以篩選搜索或結果,以便能夠爲lhs列指定多個條件?
的完整代碼是明確的:輸出的
Data <- as(data, "transactions")
str(Data)
rules <- apriori(Data, parameter=list(supp = 0.0001, conf = 0.001, minlen = 2), appearance = list(lhs = c("DiagnoseTekst=Acuut hartfalen"), default="rhs"))
top.conf <- sort(rules, decreasing = TRUE, na.last = NA, by = c("confidence","lift"))
set <- inspect(head(subset(top.conf), 30))
例子:
> set <- inspect(head(subset(top.conf), 30))
lhs rhs support confidence lift count
[1] {DiagnoseTekst=Acuut hartfalen} => {Geslacht=V} 0.066477566 0.525500378 1.1539592 30561
[2] {DiagnoseTekst=Acuut hartfalen} => {Geslacht=M} 0.060025798 0.474499622 0.8712635 27595
[3] {DiagnoseTekst=Acuut hartfalen} => {MedicatieTekst=FUROSEMIDE} 0.017917467 0.141636289 2.9290550 8237
[4] {DiagnoseTekst=Acuut hartfalen} => {MedicatieTekst=METOPROLOL} 0.006279923 0.049642341 0.9877311 2887
[5] {DiagnoseTekst=Acuut hartfalen} => {MedicatieTekst=PARACETAMOL} 0.005201003 0.041113557 0.6085413 2391