The ultra-dense network (UDN) is one of the key technologies in fifth generation (5G) networks. It is used to enhance the system capacity issue by deploying small cells at high density. In 5G UDNs, the cell selection process requires high computational complexity, so it is considered to be an open NP-hard problem. Internet of Vehicles (IoV) technology has become a new trend that aims to connect vehicles, people, infrastructure and networks to improve a transportation system. In this paper, we propose a machine-learning and IoV-based cell selection scheme called Artificial Neural Network Cell Selection (ANN-CS). It aims to select the small cell that has the longest dwell time. A feed-forward back-propagation ANN (FFBP-ANN) was trained to perform the selection task, based on moving vehicle information. Real datasets of vehicles and base stations (BSs), collected in Los Angeles, were used for training and evaluation purposes. Simulation results show that the trained ANN model has high accuracy, with a very low percentage of errors. In addition, the proposed ANN-CS decreases the handover rate by up to 33.33% and increases the dwell time by up to 15.47%, thereby minimizing the number of unsuccessful and unnecessary handovers (HOs). Furthermore, it led to an enhancement in terms of the downlink throughput achieved by vehicles.