# Risk and Pattern Analysis of Pakistani Crime Data Using Unsupervised Learning Techniques
## 3 Methodology and Experimental Investigation
### Unsupervised Data Analysis
#### 3.4.2 Association Rule Mining  
Association rule mining is a well-known data mining technique to extract frequent and interesting patterns in a dataset. The Apriori algorithm follows the association rule mining methodology for the generation of frequent item sets [33].Those item sets are considered frequent whose support is higher than the threshold value or specified minimum support. The Apriori algorithm follows the following steps:  
1. Define the support for an item set in the transactional database and choose the minimum support and confidence level;
2. Take all supports in the transaction that have a greater support value than the minimum or specified support value;
3. Discover all of the rules in these subsets with a greater confidence value than the specified threshold;
4. Arrange the rules in decreasing order of lift.  
In this research work, the Apriori algorithm is applied in the R language to obtain frequent patterns of criminal activities based on the factors mentioned in Table 3. To verify the frequent patterns mined, support, lift, and confidence values of each rule are computed for the association rule \(x\to y\).  
For rule \(x\to y\), the support of the rule is indicated as \(\sup(x\to y)\). The support value shows the frequent occurrence of x and y in the dataset together. According to Equation (1), the relative support is defined as the transaction frequency \(X\ U\ Y\) that appears in the database divided by the total number of transactions [22].  
\[Support=\frac{(X\ U\ Y)}{N} \tag{1}\]  
Based on the support-based downward closure property of itemsets, the Apriori method constructs frequent itemsets in a reasonable time. An item-set is frequent if its support value is equivalent to or above the pre-defined minimum support. An item-set Z of length 1 is frequent if and only if all the subsets of Z with length l-1 are frequent. This property allows the search space to be pruned substantially. Confidence indicates theaccuracy of the rule. The rules are ranked based on their confidence value. Confidence is computed using the Equation (2) formula [22].  
\[Confidence(x\to y)=\frac{XUY}{X} \tag{2}\]  
Thus, confidence is described as the number of transactions where XUY appears divided by the number of transactions where X appears. If multiple rules have identical confidence values then they are arranged based on their support value. To find the interestingness of an association rule generated, a lift measure is used. Lift is computed based on support values computed collectively as well as individually of each frequent item in the item-set as shown in Equation (3) [22].  
\[Lift=\frac{Support(XUY)}{Support(X)*Support(Y)} \tag{3}\]  
Support (_XUY_) is the relative count of transactions, Support(X) is the number of transactions containing X, and Support (Y) is the number of transactions containing Y. The greater the value of the lift, the higher the interestingness of that rule. The Apriori algorithm is applied to different levels of Crime Type to get the desired results as shown in Figure 2.  
With the help of association rule mining, risk factors related to crime are identified by analysing the crime patterns and possible crimes that happened at different times and days. For example, if 'Theft' _Crime Type_ had happened at _Crime Time_ 'Evening' and _Day Type_'Weekend', then other types of criminal activities can be expected to happen on the same day and time. The patterns obtained from the Apriori algorithm are considered for the identification of possible types of crimes (_Crime Type_) that happened on a particular time (_Crime Time_) and day (_Day Type_) based on the attributes _Crime Time_, _Day Type_, _Distance of Crime Event from Police Station_ and _Direction of Crime Event from Police Station_.  
Frequent patterns of length two to length five are generated by taking into consideration the crime dataset. The results of the Apriori algorithm are presented in the Section 4.