The production of a Higgs boson in association with a top quark pair () is measured in final states with electrons, muons and hadronically decaying leptons. Events are selected from a sample of proton-proton collisions at a \sqrt{s} = 13~\mathrm{TeV} center-of-mass energy, recorded by the CMS experiment in 2017 and corresponding to an integrated luminosity of 41.5~\mathrm{fb}^{-1}. Machine learning and matrix element methods are used to optimize the analysis sensitivity. The observed (expected) production rate is () times the expected rate in the standard model, which corresponds to an observed (expected) significance of (). In addition, these results are combined with those previously obtained from the data set collected in 2016 and corresponding to an integrated luminosity of 35.9~\mathrm{fb}^{-1}. The observed (expected) signal rate for the combined fit is () times the expected rate in the standard model, which corresponds to an observed (expected) significance of ().