Effective inventory management is crucial for businesses to minimize costs and maximize operational efficiency. This paper explored the optimization of resource allocation on the Internet of Things (IoT) for improved inventory management and developed an inventory management system using IoT and Wireless Sensor Network (WSN) to optimize the resource allocation. In this paper, the dataset that is taken into consideration is the primary dataset, which is collected from different locations with the help of WSN, temperature, humidity, and stock of mapping of the place where data is allocated. Further, preprocessing of the data is done, and then the data is split as training and testing data. Machine learning models, i.e., decision tree, random forest, regression model, and ensemble model (combination of decision tree, random forest, and regression model), are applied to classify and train the data. The novelty of the research is establishing an inventory management system employing IoT and WSN, combining machine learning and ensemble models for resource allocation optimization, and outperforming traditional approaches. The result metrics such as Root Squared Mean Error (RMSE), Mean Absolute Error (MAE), Mean Squared Error (MSE), and Accuracy are taken into consideration to evaluate the performance of the model. Experimental results are obtained the values of RMSE, MAE, and MSE are 0.25, 0.0625, and 0.625, respectively. Also, the overall accuracy of the proposed model would be obtained as 93.75%. The comparative analysis shows that the proposed model outperformed the existing conventional model in terms of accuracy.