Some security protocols or mechanisms have been designed for wireless sensor networks (WSNs). However, an intrusion detection system (IDS) should always be deployed on security critical applications to defense in depth. Due to the resource constraints, the intrusion detection system for traditional network cannot be used directly in WSNs. Several schemes have been proposed to detect intrusions in wireless sensor networks. But most of them aim on some specific attacks (e.g. selective forwarding) or attacks on particular layers, such as media access layer or routing layer. In this paper, we present a framework of machine learning based intrusion detection system for wireless sensor networks. Our system will not be limited on particular attacks, while machine learning algorithm helps to build detection model from training data automatically, which will save human labor from writing signature of attacks or specifying the normal behavior of a sensor node.