Swiftly increasing population and industrial developments of urban areas has accelerated the worsening of the water quality in recent years. Groundwater samples from different locations of the Doon valley, Garhwal Himalaya were analyzed to measure concentrations of six potential toxic elements (PTEs) viz. chromium (Cr), nickel (Ni), arsenic (As), molybdenum (Mo), cadmium (Cd), and lead (Pb) using Inductively Coupled Plasma Mass Spectrometer (ICP-MS) with the aim to study the spatial distribution and associated hazards. In addition, machine learning algorithms have been used for prediction of water quality and identification of influencing PTEs. The results inferred that the mean values (in the units of µg L−1) of analyzed PTEs were observed in the order of Mo (1.066) > Ni (0.744) > Pb (0.337) > As (0.186) > Cr (0.180) > Cd (0.026). The levels and computed risks of PTEs were found below the safe limits. The radial basis function neural network (RBF-NN) algorithms showed high level of accuracy in the predictions of heavy metal pollution index (HPI), heavy metal evaluation index (HEI), non-carcinogenic (N-CR) and carcinogenic (CR) parameters with determination coefficient values ranged from 0.912 to 0.976. However, the modified heavy metal pollution index (m-HPI) and contamination index (CI) predictions showed comparatively lower coefficient values as 0.753 and 0.657, respectively. The multilayer perceptron neural network (MLP-NN) demonstrated fluctuation in precision with determination coefficient between 0.167 and 0.954 for the prediction of computed indices (HPI, HEI, CI, m-HPI). In contrast, the proficiency in forecasting of non-carcinogenic and carcinogenic hazards for both sub-groups showcased coefficient values ranged from 0.887 to 0.995. As compared to each other, the radial basis function (RBF) model indicated closer alignments between predicted and actual values for pollution indices, while multilayer perceptron (MLP) model portrayed greater precision in prediction of health risk indices.