The integration of IoT systems into automotive vehicles has raised concerns associated with intrusion detection within these systems. Vehicles equipped with a controller area network (CAN) control several systems within a vehicle where disruptions in function can lead to significant malfunctions, injuries, and even loss of life. Detecting disruption is a primary concern as vehicles move to higher degrees of autonomy and the possibility of self-driving is explored. Tackling cyber-security challenges within CAN is essential to improve vehicle and road safety. Standard differences between different manufacturers make the implementation of a discreet system difficult; therefore, data-driven techniques are needed to tackle the ever-evolving landscape of cyber security within the automotive field. This paper examines the possibility of using machine learning classifiers to identify cyber assaults in CAN systems. To achieve applicability, we cover two classifiers: extreme gradient boost and K-nearest neighbor algorithms. However, as their performance hinges on proper parameter selection, a modified metaheuristic optimizer is introduced as well to tackle parameter optimization. The proposed approach is tested on a publicly available dataset with the best-performing models exceeding 89% accuracy. Optimizer outcomes have undergone rigorous statistical analysis, and the best-performing models were subjected to analysis using explainable artificial intelligence techniques to determine feature impacts on the best-performing model.