As the security issues of Internet of Things (IoTs) are rapidly evolving, machine learning techniques are increasingly adopted for detecting and preventing cyber threats. Recent machine learning based approaches (e.g., anomaly detection, intrusion detection, and predictive analytics) are being utilized in IoTs security. With the proliferation of IoTs devices, it is crucial to develop scalable and effective security solutions to keep pace with the changing threat landscape. This paper proposes a novel NSM (Network Sparsification Modeling) approach for identifying and categorizing cybersecurity threats in the cloud and IoTs environment. The proposed NSM algorithm is to optimize the Kullback-Leilber divergence based on higher-order spanning k-tree modeling process. The NSM model is capable of detecting cybersecurity threats in the cloud and IoTs setting by converting raw data into a meaningful format. The performance of the NSM model was evaluated using CICIDS 2017 dataset. The testing results prove that NSM model is state-of-the-art by outperforming others. Future deep-learning approaches are capable to integrate in the ML-based NSM model for further enhancement.