Role of Confusion matrix in cyber crime cases
Published: 2021-06-06 08:39:55

**What is confusion matrix?**

A confusion matrix is a table that displays and compares actual values with the model’s predicted values. Within the context of machine learning, a confusion matrix is utilized as a metric to analyze how a machine learning classifier performed on a dataset. A confusion matrix generates a visualization of metrics like precision, accuracy, specificity, and recall.
The reason that the confusion matrix is particularly useful is because the confusion matrix generates a more complete picture of how a model performed. Only using a metric like accuracy can lead to a situation where the model is completely and consistently misidentifying one class, but it goes unnoticed because on average performance is good. Meanwhile, the confusion matrix gives a comparison of different values like False Negatives, True Negatives, False Positives, and True Positives.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xhunipn09iv8r5uiqdaa.png)
 
The Positive/Negative label refers to the predicted outcome of an experiment, while the True/False refers to the actual outcome.
Now let’s understand each term :

**True Positive (TP)**

The predicted value matches the actual value
The actual value was positive and the model predicted a positive value

**True Negative (TN)** 

The predicted value matches the actual value
The actual value was negative and the model predicted a negative value

**False Positive (FP) – Type 1 error**

The predicted value was falsely predicted
The actual value was negative but the model predicted a positive value
Also known as the Type 1 error

**False Negative (FN) – Type 2 error**

The predicted value was falsely predicted
The actual value was positive but the model predicted a negative value
Also known as the Type 2 error

**Cyber Crime Analysis using Enhanced Random Forest**
The purpose is to predict cyber crime patterns over selected areas across India more efficiently by utilizing data mining techniques and to propose a Knowledge Based System for cyber crime data analysis. For this intention, cyber crime datasets had been collected over 11 states of India for duration of 11 years and had been stored in cyber crime database. The development of the proposed model had been performed as follows:

**Develop Enhanced Random Forest classifier Component**
1: Pre-processing by Attribute Greedy Stepwise selection method.
2: Clustering by TwoLogMean clustering algorithm.
3: To improve the efficiency of the classifier, clustered cyber crime datasets were executed in Enhanced Random Forest classifier.


With the number of trees, Random Forest creates a forest that can be utilized for classification, regression and other data mining tasks. During training phase, the Random Forest classifier crafts multiple decision trees. The variables can be ranked based on their priority by utilizing Random Forest. The reputation of decision tree replica in data mining had begun from their ease of exploit, flexibility in terms of managing diverse data element types, and interpretability. Conversely, single decision tree models were rickety and excessively susceptible to specific training data. Ensemble techniques in Random Forest try to solve this issue by crafting a set of models and summating their prophecy in deceiving the class label for a data point. Ensembles execute fine when individual elements are contradictory, and random forests attain deviation among individual trees by utilizing two foundations for randomness: Initially, every tree is constructed on separate bootstrapped models of the training data; then only an arbitrarily selected subset of data aspects are measured at each node in the construction of the individual trees.

Step 1: Process Enhanced Random Forest
Input: clustered cybercrime dataset
Output: decision rule for Knowledge Based System
Step 2: Load the attribute selected cyber crime dataset and assign data to clustered dataset from TwoLogMean cluster algorithm
Step 3: Interpret the datafile and assign validation to null Step 4: Perform Ten split cross validation
Step 5: Separate the total number of instances in to training and testing arrays
Step 6: Execute the clustered cyber crime dataset in classifier
Step 7: For every training-testing split pair, train and test the classifier
Step 8: Compute the overall accuracy of classifier on all splits
Step 9: Display the classifier name, accuracy, confusion matrix and generate ROC curve
Step 10: Stop Process

Model evaluation compared to Naive bayes:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80gkuefao4ti4dstb4mu.png)

So comparing the values obtained in the confusion matrix :
**True Positive** — For Enhanced Random Forest is higher which is good meaning the number of cases which were predicted right are high.
**False Negative** — For Enhanced Random Forest is zero which is really good meaning the number of cases which were predicted wrong are low.