Among the most crucial components of a cyber physical system is a network of nodes via which a large number of autonomous, mobile or stationary sensors can communicate with one another. This network is known as a wireless sensor network (WSN). The network's nodes work together to sense the world around them, collect data on the items they detect, process that data, and then communicate it on to the network's owner since WSN has many potentials uses across many disciplines but little available resources, it is often coupled with IOT, making the network accessible to the outside world and susceptible to cyberattacks. Blackhole, grayhole, flooding, and scheduling attacks are some examples of common attacks in WSN that can do significant damage rapidly. Intrusion detection approaches for WSN suffer from issues like a low detection rate, a large calculation overhead, and a high false alarm rate because of the network's redundant and highly correlated data and the constraints imposed by sensor nodes' limited resources which is the research problem. This research proposes a solution, dubbed IDS-ML, that makes use of three different machine learning techniques-stochastic gradient descent (SGD), ridge regression (RR), and gaussian naive bayesto solve the problem of intrusion detection in wireless sensor networks (GNB). In order to reduce the computational burden of the technique, principal component analysis (PCA) and singular value decomposition (SVD) are applied to the original traffic data to lower the feature space dimension. Once network threats have been identified, an IDS-ML model is utilized to categorize them. Based on the experiments with two datasets WSN-DS and UNSW-NB15, the proposed IDS-ML achieves significantly higher accuracy rate of 99% than state-of-the-art detection algorithms for WSN-DS and UNSW-NB15 dataset. As the achieved higher accuracy rate against normal, blackhole, grayhole, flooding, and TDMA attacks are 99%, 100%, 72%, 100%, and 78% respectively.