Environmental regulation is pivotal in mitigating environmental risks and promoting sustainable development, yet regulators frequently encounter resource constraints when inspecting enterprises. To address this limitation, we employed four sliding window-based machine learning techniques to enhance effective environmental inspections. Utilizing feature-engineered time-series data of characteristic and compliance records from 16,777 chemical enterprises in Jiangsu between 2010 and 2021, the four models were used to establish the predictive models that link enterprise characteristics to the likelihood of inspection failure. The results indicated that the models were comparable with the widely utilized deep learning sequence model, the Long Short-Term Memory model, achieving areas under the ROC (receiver operating characteristic) curves exceeding 0.83. Past violation significantly influences future violations, with a more recent violation history exerting stronger impacts. Besides, using predicted failure rates, we proposed seven resource allocation scenarios, considering different regulation intensities to target high-risk enterprises. Notably, the provincial-level risk-based method yielded a significant inspection failure rate increase (detecting violation), surpassing 8-fold the baseline. Overall, our study offers regulators an optimized inspection resource allocation method, thereby enhancing the regulatory effectiveness. Moreover, this study demonstrates the potential of window-based machine learning techniques in environmental regulation and highlights the importance of data-driven decision-making for promoting sustainable development.