2016-12-05 87 views
-1

我有一個來自excel csv文件的1-0矩陣數據,用於購物籃分析以應用關聯規則。但是,程序找不到任何規則。可能它讀取0和1作爲字符串。當我將它們轉換爲數字時,程序會給出錯誤,並且不能再次生成任何規則。如何將1-0 excel csv文件轉換爲R作爲二進制矩陣?

如何將它轉換爲二進制變量才能用於關聯規則查找?

> y <- read.transactions("C:/Users/toshıba pc/Desktop/2009.csv") 
    Warning message: 
    In asMethod(object) : removing duplicated items in transactions 
    > rules <- apriori(y, parameter=list(supp=0.1, conf=0.8)) 
    Apriori 

    Parameter specification: 
    confidence minval smax arem aval originalSupport maxtime support minlen maxlen target ext 
      0.8 0.1 1 none FALSE   TRUE  5  0.1  1  10 rules FALSE 

    Algorithmic control: 
    filter tree heap memopt load sort verbose 
     0.1 TRUE TRUE FALSE TRUE 2 TRUE 

    Absolute minimum support count: 52 

    set item appearances ...[0 item(s)] done [0.00s]. 
    set transactions ...[553 item(s), 521 transaction(s)] done [0.00s]. 
    sorting and recoding items ... [0 item(s)] done [0.00s]. 
    creating transaction tree ... done [0.00s]. 
    checking subsets of size 1 done [0.00s]. 
    writing ... [0 rule(s)] done [0.00s]. 
    creating S4 object ... done [0.00s]. 

> rules <- apriori(y, parameter=list(supp=0.01, conf=0.8)) 
Apriori 

Parameter specification: 
confidence minval smax arem aval originalSupport maxtime support minlen maxlen target ext 
     0.8 0.1 1 none FALSE   TRUE  5 0.01  1  10 rules FALSE 

Algorithmic control: 
filter tree heap memopt load sort verbose 
    0.1 TRUE TRUE FALSE TRUE 2 TRUE 

Absolute minimum support count: 5 

set item appearances ...[0 item(s)] done [0.00s]. 
set transactions ...[553 item(s), 521 transaction(s)] done [0.00s]. 
sorting and recoding items ... [0 item(s)] done [0.00s]. 
creating transaction tree ... done [0.00s]. 
checking subsets of size 1 done [0.00s]. 
writing ... [0 rule(s)] done [0.00s]. 
creating S4 object ... done [0.00s]. 
> enter image description here 
+0

你能提供給你的'y'變量的詳細信息。例如'str(y)'。 –

+0

我編輯了代碼。順便一提;在其他代碼中;我試圖通過使用「as.matrix(y)」和「as.numeric(y)」來製作「y」矩陣。當這兩個應用時;規則算法甚至不起作用。 @PetrMatousu 如果你看看我編輯的代碼;當我改變支持價值;最小支持計數會減少,但仍無法找到任何規則。 – Annabella

+0

也許你的'csv'文件的代碼片段也會有幫助。 –

回答

0

作爲一般的建議,我建議在read.transactions指定更多的參數,以反映給csv文件分離器,COLS等可能需要一些csv文件處理,以反映預期read.transactions的細節。

> args(read.transactions) 
function (file, format = c("basket", "single"), sep = "", cols = NULL, 
    rm.duplicates = FALSE, quote = "\"'", skip = 0, encoding = "unknown") 
NULL 

功能文檔:

> ?read.transactions