Exploiting the information provided by electron energy-loss spectroscopy (EELS) requires reliable access to the low-loss region where the zero-loss peak (ZLP) often overwhelms the contributions associated to inelastic scatterings off the specimen. Here we deploy machine learning techniques developed in particle physics to realise a model-independent, multidimensional determination of the ZLP with a faithful uncertainty estimate. This novel method is then applied to subtract the ZLP for EEL spectra acquired in flower-like WS$_2$ nanostructures characterised by a 2H/3R mixed polytypism. From the resulting subtracted spectra we determine the nature and value of the bandgap of polytypic WS$_2$, finding $E_{rm BG} = 1.6_{-0.2}^{+0.3},{rm eV}$ with a clear preference for an indirect bandgap. Further, we demonstrate how this method enables us to robustly identify excitonic transitions down to very small energy losses. Our approach has been implemented and made available in an open source Python package dubbed EELSfitter.