Submitted:
16 July 2025
Posted:
17 July 2025
You are already at the latest version
Abstract
Keywords:
1. Introduction
- Develop and implement classical and ensemble machine learning models to predict thyroid cancer risk based on clinical, demographic, and biochemical datasets.
- Apply Pearson correlation analysis to identify and select the most relevant features for model training.
- Optimize model performance through hyperparameter tuning and cross-validation strategies.
- Evaluate the models using standard classification metrics accuracy, precision, recall, and F1 score across two independent datasets to assess generalizability.
2. Literature Review
3. Methodology
3.1. Dataset Description and Preprocessing
| Column | Non-Null Count | Data Type |
|---|---|---|
| Age | 383 | int64 |
| Gender | 383 | object |
| Smoking | 383 | object |
| Hx Smoking | 383 | object |
| Hx Radiothreapy | 383 | object |
| Thyroid Function | 383 | object |
| Physical Examination | 383 | object |
| Adenopathy | 383 | object |
| Pathology | 383 | object |
| Focality | 383 | object |
| Risk | 383 | object |
| T | 383 | object |
| N | 383 | object |
| M | 383 | object |
| Stage | 383 | object |
| Response | 383 | object |
| Recurred | 383 | object |
| Column | Non-Null Count | Data Type |
|---|---|---|
| Patient_ID | 212,691 | int64 |
| Age | 212,691 | int64 |
| Gender | 212,691 | object |
| Country | 212,691 | object |
| Ethnicity | 212,691 | object |
| Family_History | 212,691 | object |
| Radiation_Exposure | 212,691 | object |
| Iodine_Deficiency | 212,691 | object |
| Smoking | 212,691 | object |
| Obesity | 212,691 | object |
| Diabetes | 212,691 | object |
| TSH_Level | 212,691 | float64 |
| T3_Level | 212,691 | float64 |
| T4_Level | 212,691 | float64 |
| Nodule_Size | 212,691 | float64 |
| Thyroid_Cancer_Risk | 212,691 | object |
| Diagnosis | 212,691 | object |
3.2. Exploratory Data Analysis (EDA)


3.3. Feature Selection
3.4. Model Development
- Logistic Regression: A linear model for binary classification that estimates the log-odds of the positive class (i.e., high cancer risk) as a linear combination of input features. The logistic (sigmoid) function then transforms the result into a probability. Logistic regression was included as a baseline due to its simplicity and strong interpretability in clinical settings.
- k-Nearest Neighbors (KNN): A nonparametric, instance-based classifier that assigns labels based on the majority vote among the k most similar training instances in the feature space. We used Euclidean distance as the similarity metric, with all features normalized beforehand. Since KNN relies on distance calculations, its performance can benefit significantly from feature scaling.
- Gaussian Naïve Bayes: A probabilistic classifier based on Bayes’ theorem and the assumption that features are conditionally independent given the class label. It models the likelihood of continuous features using a Gaussian distribution for each class. Despite the independence assumption, Gaussian Naïve Bayes is computationally efficient and often performs well in high-dimensional data settings.
- Random Forest: An ensemble method that constructs multiple decision trees using the bagging technique (bootstrap aggregation). Each tree is trained on a random subset of the training data, and the final prediction is obtained by averaging the individual tree predictions. Random forests are capable of modeling non-linear interactions and are robust enough to overfit. We used a sufficiently large number of estimators to ensure performance stability.
- AdaBoost (Adaptive Boosting): A boosting ensemble that sequentially trains weak classifiers, where each subsequent model focuses more on the instances misclassified by its predecessors. The final prediction is a weighted vote across all weak learners. We used decision stumps (simple trees) as base classifiers. AdaBoost was included for its ability to improve predictive performance by emphasizing difficult cases.
-
Gradient Boosting Machines (GBM): A family of boosting techniques where each new tree is trained to correct the residual errors made by the previous ensemble. We implemented GBM using multiple frameworks:
- –
- GradientBoostingClassifier from scikit-learn
- –
- XGBoost (Extreme Gradient Boosting): Efficient, regularized boosting algorithm often used in competitions [13].
- –
- LightGBM (Light Gradient Boosting Machine): Optimized for speed and memory usage using techniques like Gradient-based One-Side Sampling (GOSS) and Exclusive Feature Bundling (EFB) [14].
- –
- CatBoost: Tailored for categorical data, it applies ordered boosting to reduce overfitting and often achieves high accuracy [15].
3.5. Hyperparameter Tuning and Optimization

4. Result


4.1. Performance on Dataset 2
4.2. Performance on Dataset 2
4.3. Comparative Insights
5. Conclusion
Code and Datasets
- Thyroid Cancer Risk Dataset: This dataset provides clinical and demographic attributes relevant to assessing thyroid cancer risk. It is available at: https://www.kaggle.com/datasets/mzohaibzeeshan/thyroid-cancer-risk-dataset.
- Thyroid Disease Dataset: This dataset contains diagnostic records for multiple thyroid disease categories and serves as a benchmark for classification tasks. It can be accessed at: https://www.kaggle.com/datasets/jainaru/thyroid-disease-data/data.
References
- Islam, S.S.; Haque, M.S.; Miah, M.S.U.; Sarwar, T.B.; Nugraha, R. Application of machine learning algorithms to predict the thyroid disease risk: an experimental comparative study. PeerJ Computer Science 2022, 8, e898. [Google Scholar] [CrossRef] [PubMed]
- Sharma, R.; Mahanti, G.K.; Chakraborty, C.; Panda, G.; Rath, A. An IoT and deep learning-based smart healthcare framework for thyroid cancer detection. ACM Transactions on Internet Technology 2023. [Google Scholar] [CrossRef]
- Bhende, D.; Sakarkar, G.; Chaurasia, S.; Amlanc, N.; Deshpande, S.; Samarth, P.; Yasmeen, Z. Machine learning-based classification of thyroid disease: a comprehensive study on early detection and risk factor analysis. In Proceedings of the 2024 IEEE International Students’ Conference on Electrical, Electronics and Computer Science (SCEECS). IEEE, 2024, pp. 1–6.
- Wu, Y.; Rao, K.; Liu, J.; Han, C.; Gong, L.; Chong, Y.; Liu, Z.; Xu, X. Machine learning algorithms for the prediction of central lymph node metastasis in patients with papillary thyroid cancer. Frontiers in endocrinology 2020, 11, 577537. [Google Scholar] [CrossRef] [PubMed]
- Wang, H.; Zhang, C.; Li, Q.; Tian, T.; Huang, R.; Qiu, J.; Tian, R. Development and validation of prediction models for papillary thyroid cancer structural recurrence using machine learning approaches. BMC cancer 2024, 24, 427. [Google Scholar] [CrossRef] [PubMed]
- Mourad, M.; Moubayed, S.; Dezube, A.; Mourad, Y.; Park, K.; Torreblanca-Zanca, A.; Torrecilla, J.S.; Cancilla, J.C.; Wang, J. Machine learning and feature selection applied to SEER data to reliably assess thyroid cancer prognosis. Scientific reports 2020, 10, 5176. [Google Scholar] [CrossRef] [PubMed]
- Prasad, V.; Rao, T.S.; Babu, M.S.P. Thyroid disease diagnosis via hybrid architecture composing rough data sets theory and machine learning algorithms. Soft Computing 2016, 20, 1179–1189. [Google Scholar] [CrossRef]
- Rao, A.R.; Renuka, B. A machine learning approach to predict thyroid disease at early stages of diagnosis. In Proceedings of the 2020 IEEE international conference for innovation in technology (INOCON). IEEE, 2020, pp. 1–4.
- Alhashmi, S.M.; Polash, M.S.I.; Haque, A.; Rabbe, F.; Hossen, S.; Faruqui, N.; Hashema, I.A.; Abubacker, N.F. Survival Analysis of Thyroid Cancer Patients Using Machine Learning Algorithms. IEEE Access 2024. [Google Scholar] [CrossRef]
- Borzooei, S.; Briganti, G.; Golparian, M.; Lechien, J.R.; Tarokhian, A. Machine learning for risk stratification of thyroid cancer patients: a 15-year cohort study. European Archives of Oto-Rhino-Laryngology 2024, 281, 2095–2104. [Google Scholar] [CrossRef] [PubMed]
- Lee, K.S.; Park, H. Machine learning on thyroid disease: a review. Frontiers in Bioscience-Landmark 2022, 27, 101. [Google Scholar] [CrossRef] [PubMed]
- Xi, N.M.; Wang, L.; Yang, C. Improving the diagnosis of thyroid cancer by machine learning and clinical data. Scientific reports 2022, 12, 11143. [Google Scholar] [CrossRef] [PubMed]
- Chen, T.; Guestrin, C. Xgboost: A scalable tree boosting system. In Proceedings of the Proceedings of the 22nd acm sigkdd international conference on knowledge discovery and data mining, 2016, pp. 785–794.
- Ke, G.; Meng, Q.; Finley, T.; Wang, T.; Chen, W.; Ma, W.; Ye, Q.; Liu, T.Y. Lightgbm: A highly efficient gradient boosting decision tree. Advances in neural information processing systems 2017, 30. [Google Scholar]
- Prokhorenkova, L.; Gusev, G.; Vorobev, A.; Dorogush, A.V.; Gulin, A. CatBoost: unbiased boosting with categorical features. Advances in neural information processing systems 2018, 31. [Google Scholar]
| Model | Acc(D1) | Acc(D2) | Prec(D1) | Prec(D2) | Rec(D1) | Rec(D2) | F1(D1) | F1(D2) |
|---|---|---|---|---|---|---|---|---|
| Logistic Regression | 0.8251 | 0.9740 | 0.81 | 0.97 | 0.83 | 0.97 | 0.81 | 0.97 |
| Ridge Classifier | 0.8251 | 0.9610 | 0.81 | 0.96 | 0.83 | 0.96 | 0.81 | 0.96 |
| SGD | 0.7667 | 0.9740 | 0.59 | 0.97 | 0.77 | 0.97 | 0.67 | 0.97 |
| Passive Aggressive | 0.7236 | 0.9610 | 0.70 | 0.96 | 0.72 | 0.96 | 0.71 | 0.96 |
| Perceptron | 0.7002 | 0.9740 | 0.71 | 0.97 | 0.70 | 0.97 | 0.70 | 0.97 |
| KNN | 0.8095 | 0.9091 | 0.79 | 0.91 | 0.81 | 0.91 | 0.79 | 0.91 |
| Decision Tree | 0.8251 | 0.9610 | 0.81 | 0.96 | 0.83 | 0.96 | 0.81 | 0.96 |
| Random Forest | 0.8251 | 0.9740 | 0.81 | 0.97 | 0.83 | 0.97 | 0.81 | 0.97 |
| Extra Trees | 0.8251 | 0.9740 | 0.81 | 0.97 | 0.83 | 0.97 | 0.81 | 0.97 |
| Bagging (RF) | 0.8251 | 0.9870 | 0.81 | 0.99 | 0.83 | 0.99 | 0.81 | 0.99 |
| Naive Bayes | 0.8120 | 0.8961 | 0.80 | 0.90 | 0.81 | 0.90 | 0.80 | 0.89 |
| LDA | 0.8251 | 0.9610 | 0.81 | 0.96 | 0.83 | 0.96 | 0.81 | 0.96 |
| QDA | 0.8251 | 0.8571 | 0.81 | 0.86 | 0.83 | 0.86 | 0.81 | 0.84 |
| Grad. Boosting | 0.8251 | 0.9740 | 0.81 | 0.97 | 0.83 | 0.97 | 0.81 | 0.97 |
| AdaBoost | 0.8251 | 0.9610 | 0.81 | 0.96 | 0.83 | 0.96 | 0.81 | 0.96 |
| HistGB | 0.8251 | 0.9610 | 0.81 | 0.96 | 0.83 | 0.96 | 0.81 | 0.96 |
| XGBoost | 0.8251 | 0.9740 | 0.81 | 0.97 | 0.83 | 0.97 | 0.81 | 0.97 |
| LightGBM | 0.8251 | 0.9481 | 0.81 | 0.95 | 0.83 | 0.95 | 0.81 | 0.95 |
| CatBoost | 0.8251 | 0.9870 | 0.81 | 0.99 | 0.83 | 0.99 | 0.81 | 0.99 |
| SVM | 0.8251 | 0.9740 | 0.81 | 0.97 | 0.83 | 0.97 | 0.81 | 0.97 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).