This study proposes a machine learning-based inventory forecasting strategy using random forest classifiers to improve demand prediction and anomaly detection in retail sales. It aims to address the limitations of traditional inventory management by capturing nonlinear demand dynamics and interdependencies. The model is developed and validated using real-world inventory data, with the United Kingdom as the primary market. Data preprocessing includes handling 135,080 missing CustomerID fields, 1,454 missing Description fields, and correcting anomalies in Quantity and Unit Price. The random forest classifier is employed to identify complex sales patterns and enhance demand forecasting accuracy. Experimental findings demonstrate a significant improvement in prediction accuracy and inventory optimization over traditional methods. The model effectively captures regional sales variations and adapts to changing demand trends, enabling more precise inventory decisions. The proposed framework contributes to the development of intelligent and adaptive inventory management systems, allowing businesses to make data-driven decisions, optimize stock levels, and reduce inventory risks, and provides valuable insights for businesses aiming to enhance inventory forecasting. It highlights the importance of machine learning in improving demand prediction, minimizing errors, and adapting to evolving market conditions.