Globally, the incidence of kidney stones (urolithiasis) has increased over time. Without better treatment, stones in the kidneys could result in blockage of the ureters, repetitive infections in the urinary tract, painful urination, and permanent deterioration of the kidneys. Hence, detecting kidney stones is crucial to improving an individual’s life. Concurrently, ML (Machine Learning) has gained extensive attention in this area due to its innate benefits in continuous enhancement, its ability to deal with multi-dimensional data, and its automated learning. Researchers have employed various ML-based approaches to better predict kidney stones. However, there is a scope for further enhancement regarding accuracy. Moreover, studies seem to be lacking in this area. This study proposes a smart toilet model in an IoT-fog (Internet of Things-fog) environment with suitable ML-based algorithms for kidney stone detection from real-time urinary data to rectify this issue. Significant features are selected using the proposed Improved MBPSO (Improved Modified Binary Particle Swarm Optimization) to attain better classification. In this case, sigmoid functions are used for better prediction with binary values. Finally, classification is performed using the proposed Improved Modified XGBoost (Modified eXtreme Gradient Boosting) to prognosticate kidney stones. In this case, the loss functions are updated to make the model learn effectively and classify accordingly. The overall proposed system is assessed by internal comparison with DT (Decision Tree) and NB (Naïve Bayes), which reveals the efficient performance of the proposed system in kidney stone prognostication.