There is no definite conclusion about what the main variables that play a fundamental role in road safety are. Therefore, the identification of significant factors in road accidents has been a primary concern of the transportation safety research community for many years. Every accident is influenced by multiple variables that, in a given time interval, concur to cause a crash scenario. Information coming from crash reports is very useful in traffic safety research, and several reported crash variables can be analyzed with modern statistical methods to establish whether a classification or clustering of different crash variables is possible. Hence, this study aims to use stochastic techniques for evaluating the role of some variables in accidents with a clustering analysis. The variables that are considered in this paper are light conditions, weekday, average speed, annual average daily traffic, number of vehicles, and type of accident. For this purpose, a combination of particle swarm optimization (PSO) and the genetic algorithm (GA) with the k-means algorithm was used as the machine-learning technique to cluster and evaluate road safety data. According to a multiscale approach, based on a set of data from two years of crash records collected from rural and urban roads in the province of Cosenza, 154 accident cases were accurately investigated and selected for three categories of accident places, including straight, intersection, and other, in each urban and rural network. PSO had a superior performance, with 0.87% accuracy on urban and rural roads in comparison with GA, although the results of GA had an acceptable degree of accuracy. In addition, the results show that, on urban roads, social cost and type of accident had the most and least influence for all accident places, while, on rural roads, although the social cost was the most notable factor for all accident places, the type of accident had the least effect on the straight sections and curves, and the number of vehicles had the least influence at intersections.