On-the-fly machine learning for parametrization of the effective Hamiltonian