There are many kinds of terminals in the smart grid system, which have different functions and risks in the system. Different security policies are needed to protect the terminals. At the same time, the terminals will be subject to various attacks in operation. These attacks will change the security protection performance of terminals. Therefore, it is necessary to adjust the security policies in their operation. This paper proposes a real-time implementation method of terminal security policy selection under the edge computing based on the machine learning methods, which makes full use of the computing power of edge devices, adopts offline training and online judgment. The training of machine learning parameters can be completed in the edge side or in the cloud while the security strategies selection continues going on the edge computing side. By this way, the real-time training update and real-time selection of security policy in edge computing system are realized.