2

I've successfully imported my data into R as transactions, but when I try targeting a specific website, I get this error:

Error in asMethod(object) : FACEBOOK.COM is an unknown item label

Is there any reason why this could be happening? Here is a snippet of code:

target.conf80 = apriori(trans,
parameter = list(supp=.002,conf=.8),
appearance = list(default="lhs",rhs = "FACEBOOK.COM"),
control = list(verbose = F))
target.conf80 = sort(target.conf80,decreasing=TRUE,by="confidence")
inspect(target.conf80[1:10])

Thanks!

Here is what the transactions look like:

1 {V1=Google,                                  
   V2=Google Web Search,                       
   V3=FACEBOOK.COM}                           1
2 {V1=FACEBOOK.COM,                            
   V2=MCAFEE.COM,                              
   V3=7EER.NET,                                
   V4=Google}                                 2
3 {V1=MCAFEE.COM,                              
IRI_Tyler
  • 29
  • 2

2 Answers2

0

The problem is the way you read/convert the data to transactions. The transactions should look like:

1 {Google,                                  
   Google Web Search,                       
   FACEBOOK.COM}                           1
2 {FACEBOOK.COM,                            
   MCAFEE.COM,                              
   7EER.NET,                                
   Google}                                 2
 3 {MCAFEE.COM,
    ...

Without the V1, V2, etc. In your transactions V1=Google and V4=Google are different items.

Michael Hahsler
  • 2,965
  • 1
  • 12
  • 16
  • How can you get rid of `V1, V2, V3, ...`? You get that when you run this code... `data <- as(data, 'transactions')` and your data is a dataframe. – redeemefy Nov 04 '16 at 18:31
0

Error as(data, 'transactions') From Data Frames

I'm assuming that the dataset was transformed as follow...data <- as(data, 'transactions'). If you run that code without performing some manipulations with your data you will get those V1, V2, ....

Cleaning Data Before Transactions

I want to include how to manipulate the data to be ready for read.transctions(). After importing your data into R you want to convert your dataframe to a matrix like so... d.matrix <- as.matrix(df), the you want to eliminate any headers if happened that you do have headers; colnames(d.matrix) <- NULL. Now you don't have headers. After that you want to....

write.table(x = d.matrix, 
      file = 'clean_data.csv',
      sep = ',',
      col.names = FALSE, 
      row.names = FALSE)

Finally, you want to import the data as transaction like so...

data <- read.transactions('clean_data.csv',
                           format = 'basket',
                           sep = ',',
                           rm.duplicates = TRUE)

Now you have a dataset with no V1, V2, V3, ... and no row ID's

Community
  • 1
  • 1
redeemefy
  • 4,521
  • 6
  • 36
  • 51