Crime Prediction and Mapping Using Machine Learning Algorithms
One of the primary functions of government is to reduce crime. Despite the government's efforts to curb criminal activities, the security situation in many urban areas has deteriorated. This study aimed to create and test a machine learning model to predict crime categories and visualize the location where they occur using contextual features from the datasets. This was achieved by combining time, location, and contextual data with machine learning to improve crime prediction. The crime datasets were collected from various sources, including Nairobi County law enforcement agencies. They were subjected to various machine learning methods to assess their performance in predicting crime. After adjusting the parameters, the models were selected by comparing their classification accuracy using the confusion matrix. Random forest attained an accuracy of 97.0%, decision tree scored 80%, k-nearest neighbor scored 55%, naive bayes scored 90%, and support vector machine reached 86%. With a classification accuracy of 97%, the random forest approach was the best for predicting crime. The predicted crimes were analyzed using data visualization software such as Matplotlib, seaborn, and Folium API, with the latitude and longitude features tagging crime locations on a map to assist law enforcement agencies in identifying high-risk areas for resource allocation.