We combine a limited number of accurately measured transition frequencies in hydrogen and deuterium, recent quantum electrodynamics (QED) calculations, and, as an essential additional ingredient, a generalized least-squares analysis, to obtain precise and optimal predictions for hydrogen and deuterium transition frequencies. Some of the predicted transition frequencies have relative uncertainties more than an order of magnitude smaller than that of the g factor of the electron, which was previously the most accurate prediction of QED.