The perovskite rare earth nickelate (RENiO3) has attracted significant attention owing to its peculiar physical properties and promising potential for diverse applications. It is reported that introducing H or Li might change the electronic and optical properties of RENiO3. However, little is known about multi-electrons doping in RENiO3. In this study, the bandgaps, optical and electronic properties were investigated in RENiO3 with alkaline earth metal (AEM) elements (Be, Mg, Ca, Sr and Ba) doping. For the atomic configurations of doped RENiO3, the interstitial sites of RENiO3 are more likely to be occupied by Be, Mg and Ca atoms, whereas Sr and Ba atoms tend to replace RE atoms in RENiO3. The band gap of RENiO3 decreases after AEM doping. Moreover, the machine learning results found that the formation energy of the AEM, the relative atomic mass of the AEM, and the doping position significantly influence the band gap. Furthermore, the infrared light blocking capability, the visible light transmission, and the electronic conductivity are enhanced in AEM doped RENiO3. This study may contribute to the experimental modulation of the optical and electronic properties of RENiO3 through AEM doping.