  We report the computational investigation of a series of ternary X$_4$Y$_2$Z
and X$_5$Y$_2$Z$_2$ compounds with X={Mg, Ca, Sr, Ba}, Y={P, As, Sb, Bi}, and
Z={S, Se, Te}. The compositions for these materials were predicted through a
search guided by machine learning, while the structures were resolved using the
minima hopping crystal structure prediction method. Based on $\textit{ab
initio}$ calculations, we predict that many of these compounds are
thermodynamically stable. In particular, 21 of the X$_4$Y$_2$Z compounds
crystallize in a tetragonal structure with $\textit{I-42d}$ symmetry, and
exhibit band gaps in the range of 0.3 and 1.8 eV, well suited for various
energy applications. We show that several candidate compounds (in particular
X$_4$Y$_2$Te and X$_4$Sb$_2$Se) exhibit good photo absorption in the visible
range, while others (e.g., Ba$_4$Sb$_2$Se) show excellent thermoelectric
performance due to a high power factor and extremely low lattice thermal
conductivities.
