This paper proposes a relay protection scheme based on random forest algorithm, combined with IoT technology for real-time data collection and processing, to improve the sensitivity and accuracy of relay protection. By constructing a simulation model of a distributed power generation system, we compared and analyzed the performance of traditional fixed threshold. Distribution system operators (DSOs) must ensure a delicate balance between maintaining system stability and accommodating the diverse interests of stakeholders, including independent power producers (IPPs) and end consumers, who demand an uninterrupted power supply with high-quality parameters.