Original link:tecdat.cn/?p=22732
Original source:Tuo End number according to the tribe public number
Association rule mining is an unsupervised learning method that mines rules from transaction data. It helps to find relationships in the data set and items that appear together. In this article, I’ll explain how to extract association rules in R. The association rule model applies to transaction data. An example of transaction data could be a customer’s shopping history.
The first thing in data analysis is to understand the target data structure and content. For learning purposes, I think it’s better to use a simple data set. Once we know this model, we can easily apply it to more complex data sets. In this case, we use transaction data from grocery stores. First, we create a data box and convert it to the transaction type.
Read the data
N =500 # trans < -data.frame () # data frame to collect dataCopy the code
Create data and collect it into the transaction data box.
For (I in 1:n) {count < -sample (1:3, 1) # count from 1 to 3 if(I %% 2 == 1) {if(! add_product %in% selected) { tran <- data.frame(items = add_product, tid = i)Copy the code
Check the data in the transaction data box.
Next, we need to convert the generated data box to the transaction data type.
as(split([, "items"], [, "tid"]), "transa")
Copy the code
To examine the contents of the transaction data, we use the inspect() command.
Mining rules
sort(rules_1, dby = "confidence")
Copy the code
.
We take the first RHS item (rule after item) from the list above to check the rule for that item. But if you know the target item, you can just write RHS =”melon” in the argument.
inspect(rules_1@rhs[1])
Copy the code
> rhs_item <- gsub("\\}","", rhs)
Copy the code
We establish rules for our RHS_item
Sort by “confidence” and check the rules
sort(rules_2, "confidence")
Copy the code
Result visualization
Finally, we plot the first five rules from rule set _2.
> plot(rules_2[1:5])
Copy the code
Draw all rules
Interactive visualization
Draw the first five rules
precision = 3
igraphLayout = layout_nicely
list(nodes = nodes, edges = edges, nodesToDataframe = nodesToDataframe,
edgesToDataframe = edgesToDataframe,
x$legend <- legend
htmlwidgets::createWidget( x, width = width,
height = height)
Copy the code
Draw all rules
Most welcome insight
1. All acupoints were analyzed by WEB complex network of SPS-Modeler
2. Community detection in social networks using R language and Python
3.R language text mining NASA data Network analysis, TF-IDF and topic modeling
4. Epidemic modeling using airline complex networks in R language
5. Python membership graph model Detection of dense overlapping communities in model-based networks
6. Analyze social networks using Python and SAS Viya
7. Association network analysis: Data portraits of migrants who have moved out of Beijing
8. Emotional Semantic network: Travel data perception of tourist destination image
9. Use association rule data mining to explore the rules of drug compatibility