- Project Aim
- Overview
- Dataset
- Installation
- Usage
- Methodology
- Results
- Visualizations
- Feature Importance
- Submission
- Contributing
- License
- Contact
The primary objective of this project is to develop an accurate machine learning model that predicts an individual's smoking status based on a comprehensive set of health and physiological features. By leveraging the strengths of the Random Forest Classifier and optimizing its hyperparameters using Optuna, the project aims to provide valuable insights that can aid in health assessments and targeted interventions to reduce smoking-related health risks.
Smoking remains a leading cause of preventable diseases and mortality worldwide. Early identification of individuals at risk can facilitate timely interventions and reduce the prevalence of smoking-related health issues. This project employs a data-driven approach to predict smoking status using various health metrics, enabling healthcare professionals to identify and assist high-risk individuals effectively.
Key components of the project include:
- Data Preprocessing: Cleaning and transforming the dataset to ensure optimal model performance.
- Handling Class Imbalance: Addressing any imbalance in the target classes to improve prediction accuracy.
- Model Building: Utilizing a Random Forest Classifier to capture complex patterns in the data.
- Hyperparameter Optimization: Employing Optuna to fine-tune model parameters for enhanced performance.
- Evaluation: Assessing the model using multiple performance metrics and visualizations.
- Feature Importance Analysis: Identifying the most influential features contributing to the prediction.
The dataset comprises health-related information collected from individuals, encompassing various physiological and biochemical measurements. The goal is to predict the smoking status of each individual based on these features.
| Feature | Description |
|---|---|
id |
Unique identifier for each individual |
age |
Age of the individual (in years) |
height(cm) |
Height of the individual (in centimeters) |
weight(kg) |
Weight of the individual (in kilograms) |
waist(cm) |
Waist circumference (in centimeters) |
eyesight(left) |
Eyesight measurement for the left eye |
eyesight(right) |
Eyesight measurement for the right eye |
hearing(left) |
Hearing ability measurement for the left ear |
hearing(right) |
Hearing ability measurement for the right ear |
systolic |
Systolic blood pressure |
relaxation |
Diastolic blood pressure (relaxation phase) |
fasting blood sugar |
Fasting blood sugar level |
Cholesterol |
Cholesterol level |
triglyceride |
Triglyceride level |
HDL |
High-density lipoprotein level |
LDL |
Low-density lipoprotein level |
hemoglobin |
Hemoglobin concentration |
Urine protein |
Protein level in urine |
serum creatinine |
Serum creatinine level |
AST |
Aspartate aminotransferase level |
ALT |
Alanine aminotransferase level |
Gtp |
Gamma-glutamyl transferase level |
dental caries |
Presence of dental caries |
Note: Ensure that the
train.csvandtest.csvfiles containing these features are available in your project directory.
To set up the project environment, follow these steps:
-
Clone the Repository:
git clone https://github.com/yourusername/smoking-prediction.git cd smoking-prediction -
Create a Virtual Environment:
It's recommended to use a virtual environment to manage dependencies.
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
Install the required Python packages using
pip:pip install -r requirements.txt
If a
requirements.txtfile is not provided, install the following packages:pip install pandas numpy seaborn matplotlib scikit-learn optuna
-
Prepare the Data:
Ensure that the
train.csvandtest.csvfiles are placed in the project directory. These files should contain the features listed above. -
Run the Jupyter Notebook:
Launch Jupyter Notebook:
jupyter notebook
Open the
Smoking_Prediction.ipynbnotebook and execute the cells sequentially. -
Generate Submission:
After running the notebook, a submission file named
submission_smoking_random_forest_optuna11.csvwill be created in the project directory, containing the predicted smoking probabilities for the test dataset.
The project follows a systematic machine learning pipeline:
-
Data Loading:
- Load training and testing datasets using Pandas.
-
Exploratory Data Analysis (EDA):
- Understand data distribution.
- Identify and visualize missing values.
-
Defining Features and Target Variable:
- Separate the dataset into features (
X) and target variable (y).
- Separate the dataset into features (
-
Identifying Numerical and Categorical Columns:
- Determine which features are numerical and which are categorical.
-
Data Preprocessing:
- Numerical Features:
- Impute missing values using the median.
- Scale features using StandardScaler.
- Categorical Features:
- Impute missing values using the most frequent value.
- Apply One-Hot Encoding to convert categorical variables into numerical format.
- Combine preprocessing steps using ColumnTransformer and Pipeline.
- Numerical Features:
-
Handling Class Imbalance:
- Analyze the distribution of the target classes.
- Compute
scale_pos_weightto address any imbalance.
-
Splitting the Data:
- Split the training data into training and validation sets using StratifiedKFold to maintain class distribution.
-
Hyperparameter Optimization with Optuna:
- Define an objective function to optimize the hyperparameters of the Random Forest Classifier.
- Utilize Optuna's TPE sampler for efficient hyperparameter search.
- Model Training:
- Train the final model with the best hyperparameters on the entire training dataset.
- Model Evaluation:
- Predict on the validation set.
- Calculate performance metrics: ROC-AUC, Accuracy, Precision, F1-Score.
- Visualize ROC Curve, Confusion Matrix, and Learning Curves.
-
Feature Importance Analysis:
- Identify and visualize the top 20 features contributing to the model's predictions.
-
Prediction and Submission:
- Make predictions on the test dataset.
- Apply custom rounding rules (optional).
- Prepare and save the submission file.
After optimizing and training the model, the following performance metrics were obtained on the validation set:
- ROC-AUC: 0.894
- Accuracy: 0.807
- Precision: 0.78
- F1-Score: 0.79
Note: Replace these values with your actual results after running the notebook.
The project includes several visualizations to interpret model performance and feature importance:
-
ROC Curve:
- Illustrates the trade-off between the true positive rate and false positive rate.
-
Confusion Matrix:
- Shows the distribution of true positives, true negatives, false positives, and false negatives.
-
Learning Curves:
- Depicts how the model's performance improves with more training data.
-
Optuna Optimization Plots:
- Optimization History: Shows the progression of the objective value over trials.
- Hyperparameter Importance: Displays which hyperparameters are most influential in the optimization.
-
Feature Importances:
- Visualizes the top 20 features contributing to the model's decisions.
Ensure that these plots are generated when you run the notebook.
Understanding which features contribute most to the model's predictions provides valuable insights. The top 20 features based on importance are as follows:
- Feature A
- Feature B
- Feature C
- Feature D
- Feature E
- Feature F
- Feature G
- Feature H
- Feature I
- Feature J
- Feature K
- Feature L
- Feature M
- Feature N
- Feature O
- Feature P
- Feature Q
- Feature R
- Feature S
- Feature T
Replace these placeholder feature names with actual feature names and importance values obtained from your model.
To submit your predictions:
-
Ensure Submission Format:
- The submission file should contain two columns:
idandsmoking. id: Unique identifier for each individual from the test dataset.smoking: Predicted probability of being a smoker (rounded as per custom rules if applied).
- The submission file should contain two columns:
-
Save the Submission File:
The notebook generates a submission file named
submission_smoking_random_forest_optuna11.csv. Ensure this file is correctly formatted and free of missing values. -
Submit:
Upload the
submission_smoking_random_forest_optuna11.csvfile to the designated platform or competition page.
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
-
Fork the Repository:
Click the "Fork" button at the top-right corner of the repository page.
-
Create a New Branch:
git checkout -b feature/Smoking
-
Make Changes and Commit:
git commit -m "Add some feature" -
Push to the Branch:
git push origin feature/YourFeatureName
-
Create a Pull Request:
Go to the repository on GitHub and click "Compare & pull request."
This project is licensed under the MIT License.
For any inquiries or questions, please contact [jahongiracca997@gmail.com].
- Reproducibility: Setting random states ensures that results are reproducible.
- Scalability: Pipelines and transformers make the workflow scalable and maintainable.
- Visualization: Always visualize results to interpret and validate your models effectively.
Feel free to customize and extend this README based on your specific requirements and datasets. Happy modeling!
-
Create a
README.mdFile:In the root directory of your project, create a file named
README.md. -
Copy and Paste the Content:
Copy the entire content provided above and paste it into the
README.mdfile. -
Customize the README:
- Replace Placeholder Text:
- Update the repository URL in the Installation section.
- Replace
[jahongiracca997@gmail.com]with your actual contact email. - Update the Results and Feature Importance sections with your actual model performance metrics and feature names.
- Add License File:
- If you choose to use the MIT License, create a
LICENSEfile in your repository and paste the MIT License text into it.
- If you choose to use the MIT License, create a
- Ensure Dataset Availability:
- Make sure the
train.csvandtest.csvfiles are included in your repository or provide instructions on how to obtain them.
- Make sure the
- Replace Placeholder Text:
-
Commit and Push:
Save the
README.mdfile, commit it to your repository, and push the changes.git add README.md git commit -m "Add comprehensive README" git push origin main
By following these steps, you'll have a well-structured and informative README file that effectively communicates the purpose, methodology, and usage of your Smoking Status Prediction project. This will not only help others understand your work but also make it easier for collaborators to contribute.






