The Interface Region Imaging Spectrograph (IRIS) performs solar observations over a large range of atmospheric heights, including the chromosphere where the majority of flare energy is dissipated. The strong Mg II h&k spectral lines are capable of providing excellent atmospheric diagnostics, but have not been fully utilized for flaring atmospheres. We aim to investigate whether the physics of the chromosphere is identical for all flare observations by analyzing if there are certain spectra that occur in all flares. To achieve this, we automatically analyze hundreds of thousands of Mg II h&k-line profiles from a set of 33 flares and use a machine learning technique, which we call supervised hierarchical k-means, to cluster all profile shapes. We identify a single peaked Mg II profile, in contrast to the double-peaked quiet Sun profiles, appearing in every flare. Additionally, we find extremely broad profiles with characteristic blueshifted central reversals appearing at the front of fast-moving flare ribbons. These profiles occur during the impulsive phase of the flare, and we present results of their temporal and spatial correlation with non-thermal hard X-ray signatures, suggesting that flare-accelerated electrons play an important role in the formation of these profiles. The ratio of the integrated Mg II h&k lines can also serve as an opacity diagnostic, and we find higher opacities during each flare maximum. Our study shows that machine learning is a powerful tool for large scale statistical solar analyses.