As a new network architecture, Information-Centric Networks (ICN) has great advantages in content distribution and can better meet our needs. But it faced with many threats unavoidably. There are four types of attack in ICN: naming related attacks, routing related attacks, caching related attacks and miscellaneous attacks. These attacks will undermine the availability of ICN, the confidentiality and privacy of data. In addition, routers store a large amount of content for the users' request, and it is necessary to protect these intermediate nodes. Since the styles of content stored in nodes are not the same, using a unified set of intrusion detection rules simply will cause a large number of false positives and false negatives. Therefore, every node should perform intrusion detection according to its own characteristics. In this paper, we propose an intrusion detection mechanism to alert for abnormal packets. We introduce a extensive solution using machine learning for attacks in ICN. Moreover, the nodes in this scheme can adapt to the external environment and intelligently detect packets. Simulation on the machine learning algorithm involved prove that the algorithm is effective and suitable for network packets.