Privacy and security in the medical field are major aspects to consider in the current era. This is due to the huge necessity for data among providers, payers and patients, respectively. Recently, more researchers are making their contributions in this field under different aspects. But, there need more enhancements concerning security. In this circumstance, this paper intends to propose a new IoT-dependent health care privacy preservation model with the impact of the machine learning algorithm. Here, the information or data from IoT devices is subjected to the proposed sanitization process via generating the optimal key. In this work, the utility of the machine learning model is the greatest gateway to generating optimal keys as it is already trained with the neural network. Moreover, identifying the optimal key is the greatest crisis, which is done by a new Improved Dragonfly Algorithm algorithm. Thereby, the sanitization process works, and finally, the sanitized data are uploaded to IoT. The data restoration is the inverse process of sanitization, which gives the original data. Finally, the performance of the proposed work is validated over state-of-the-art models in terms of sanitization and restoration analysis.