# Construction and Completion of the Knowledge Graph for Cow Estrus with the Association Rule Mining
## 4 Association Rule Mining
### Comparison of Association Rule Algorithms  
There are several mining algorithms for association rules. The most popular algorithm is Apriori, which is used to obtain association rules from large databases and for discovering knowledge [26]. The Apriori algorithm is based on the a priori nature of frequent itemsets, and adopts a bottom-up approach, i.e., starting from a single itemset and gradually increasing the size of the itemset until all frequent itemsets satisfying the minimum support threshold have been found. Starting from 1-frequent itemset, rule mining is performed by iterating through a layer-by-layer search to gradually find the higher-order frequent sets, and the flow of this algorithm is shown in Figure 4.  
Figure 4 shows the flow of the Apriori algorithm for the characteristics of cow estrus. This algorithm calculates the support of each feature to form a frequent feature set with those exceeding min_support. Then, it assesses the subset confidence; those meeting the min_confidence become strong rules for estrus detection. However, the downside of the Apriori algorithm is its high cost, due to many candidate sets and database scans. To address this, the FP-Growth algorithm, using the FP-tree structure, was used to efficiently mine complete frequency patterns [27]. FP-tree is an extended prefix tree structure for storing significant and quantitative information related to frequency patterns, avoiding the drawbacks of Apriori-based approaches. It is based on a prefix tree representation of a given transaction database (called an FP-tree), which saves a lot of memory when storing transactions [28]. Figure 4: Flowchart of Apriori algorithm based on cow estrus. As shown in Figure 5, the first step was to go through the gathered data of cows in estrus and analyze each document to extract all the items in it (e.g., behavioral changes, appearance changes, physiological changes, etc.). A dataset D was created which contained a list of all the items of cows in estrus. The second step traversed the cow dataset D and calculated the number of occurrences of each item. According to the set minimum support threshold, the items with occurrence number greater than or equal to this threshold were retained, which constituted the frequent item set. The third step traversed the dataset D again, this time scanning each document according to the order of the frequent itemsets and constructing an FP-tree, which is a compact data structure for storing information about frequent itemsets. During the construction process, the items of each document were inserted into the FP-tree in the order of the most frequent itemsets. In this study, we analyzed the performance of Apriori algorithm and FP-Growth algorithm in depth by comparing their ability to mine association rules at different support levels. The number of association rules mined by the two algorithms with different support levels is shown in Figure 6.  
Figure 5: Flowchart of the FP-Growth algorithm applied for predicting cow estrus. The experimental results revealed that at a support level of 0.02, the Apriori algorithm successfully mined 66 strong association rules, whereas the FP-Growth algorithm identified 53. As the support threshold was increased to 0.03, the number of rules mined by Apriori decreased to 22, and FP-Growth to 18. Further raising the support to 0.05 resulted in both algorithms extracting only six rules. This trend demonstrates that the number of rules mined by both algorithms diminished as the support threshold increased. Notably, FP-Growth demonstrated superior performance at lower support levels, while both algorithms exhibited comparable efficiency at higher support levels. Given insights from veterinary expertise and the correlation with estrus behavior in cows, we chose to focus on a median support value for our analysis. As shown in Table 4, when the support was set to 0.03, the two association algorithms yielded a moderate number of strong association rules, which we believe offered a balanced perspective for our discussion.