Interactive Machine Learning Platform for Lung Cancer Risk Assessment
Empowering healthcare professionals with AI-driven insights for early detection and prevention.
🌐 Live Demo · 🐛 Report Bug · 💡 Request Feature
- Overview
- Dataset Description
- Technical Challenges
- Exploratory Data Analysis
- Key Findings
- Dashboard Features
- Installation
- Project Structure
- Technologies
- Future Enhancements
- Contributing
- License
- Contact
This project delivers a full data science pipeline for lung cancer risk prediction, integrating statistical analysis, machine learning, and interactive dashboards built with Streamlit.
Healthcare professionals can analyze clinical risk factors, visualize data patterns, and evaluate model predictions through a user-friendly web interface.
- 🔍 Identify significant behavioral and clinical risk factors
- 📊 Develop and validate robust machine learning models
- 🎨 Build an interactive platform for data exploration
- 📈 Generate actionable insights for early detection
Source: Clinical survey (survey lung cancer.csv)
Samples: 309
Features: 16 (15 predictors + 1 target)
Missing Values: None
Class Imbalance: 87% cancer, 13% healthy
| Category | Variables | Type | Description |
|---|---|---|---|
| Demographic | AGE, GENDER | Continuous, Binary | Age (21–87), sex |
| Behavioral | SMOKING, ALCOHOL_CONSUMING, PEER_PRESSURE | Binary | Lifestyle & exposure |
| Symptoms | YELLOW_FINGERS, ANXIETY, FATIGUE, ALLERGY, WHEEZING, COUGHING, SHORTNESS_OF_BREATH, SWALLOWING_DIFFICULTY, CHEST_PAIN | Binary | Clinical symptoms |
| Comorbidities | CHRONIC_DISEASE | Binary | Pre-existing conditions |
| Target | LUNG_CANCER | Binary | Diagnosis (YES/NO) |
Encoding: 1 → NO, 2 → YES
Non-standard binary encoding required conversion:
binary_cols = [...]
df[binary_cols] = df[binary_cols].replace({1: 0, 2: 1}).astype('uint8')✅ Result: Uniform encoding and reduced memory footprint.
Problem: 87:13 imbalance → biased predictions.
from sklearn.preprocessing import StandardScaler
df['age_scaled'] = StandardScaler().fit_transform(df[['age']])✅ Result: Improved convergence for distance-based models (SVM, Logistic Regression).
- Cancer: 62.95 ± 7.97
- Healthy: 60.74 ± 9.63
- t-test: p > 0.05 → Age is not a significant predictor
| Symptom | Healthy (%) | Cancer (%) | Odds Ratio | p-value |
|---|---|---|---|---|
| Allergy | 12.8 | 61.9 | 11.03 | < 0.001 |
| Alcohol consume | 17.9 | 61.1 | 7.18 | < 0.001 |
| Swallowing difficulty | 12.8 | 51.9 | 7.32 | < 0.001 |
| Wheezing | 23.1 | 60.4 | 5.06 | < 0.001 |
| Coughing | 25.6 | 62.6 | 4.85 | < 0.001 |
- Anxiety ↔ Yellow Fingers: r = 0.56
- Anxiety ↔ swallowing_difficulty: r = 0.48
- Gender ↔ Alcohol consume: r = 0.45
Unsupervised K-Means (k=3) revealed distinct patient profiles:
- Cluster 0: Smoking men with yellow fingers and fatigue, but no alcohol consumption
- Cluster 1: Wpmen with respiratory symptoms and alcohol consumption.
- Cluster 2: Men and women with yellow fingers and difficulty swallowing.
- 10 binary symptoms significantly associated (p < 0.05)
- Top Model: Gradient Boosting
| Metric | Score | Interpretation |
|---|---|---|
| ROC-AUC | 0.959 | Excellent discrimination |
| Accuracy | 91% | High correctness |
| Precision | 96.9% | Few false positives |
| Recall | 92.6% | Few missed cases |
| F1-Score | 0.947 | Balanced performance |
| Page | Description |
|---|---|
| 🏠 Home | Summary KPIs & dataset overview |
| 📊 Distribution | Histograms, boxplots, descriptive stats |
| 🔄 Correlations | Heatmaps and pairwise associations |
| 📈 Statistical Tests | t-tests, Chi-square, Mann-Whitney U |
| 🎯 Clusters | 3D PCA + radar charts |
| 🧬 Prediction | ML-based risk calculator |
| 🎓 Model Performance | ROC curves, calibration, confusion matrix |
- 3D PCA plots
- Feature importance bars
- Radar charts
- Calibration curves
# 1. Clone repository
git clone https://github.com/aespinosa95/lung_cancer.git
cd lung_cancer
# 2. Create virtual environment
python -m venv lungcancer
source lungcancer/bin/activate # On Windows: lungcancer\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Launch the Streamlit dashboard
streamlit run src/Home.pylung_cancer/
├── data/
│ ├── survey lung cancer.csv
│ └── survey lung cancer_clean.csv
├── notebooks/
│ └── preprocess.ipynb
│ └── EDA.ipynb
├── src/
│ ├── Home.py
│ ├── pages/
│ └── utils/
├── requirements.txt
├── README.md
└── LICENSE
| Tool | Purpose |
|---|---|
| Python 3.12+ | Core language |
| Streamlit | Dashboard framework |
| Pandas / NumPy | Data handling |
| Scikit-learn | ML algorithms |
| Plotly / Matplotlib / Seaborn | Visualization |
| SciPy | Statistical testing |
- 🧠 ML model improvements
- 📊 New visualizations
- 🧩 Code optimization
- 🧾 Documentation enhancement
Distributed under the MIT License.
See the LICENSE file for details.
- 🐙 GitHub: @aespinosa95
- 💼 LinkedIn: Asunción Espinosa Sánchez
- 🌐 Portfolio: asuncionespinosa
- 📁 Project Link: lung_cancer repo
⚕️ Disclaimer:
This platform is for research and educational purposes only.
Predictions should be interpreted by qualified healthcare professionals.
Made with using Streamlit and Python.