Loading repository dataβ¦
Loading repository dataβ¦
NhanPhamThanh-IT / repository
π« A machine learning project using logistic regression to predict heart disease risk from clinical data. Built with Python, scikit-learn, and Jupyter notebooks. Achieves 85%+ accuracy on 303-patient dataset with 13 medical features. Complete ML pipeline from data exploration to model evaluation.
A comprehensive machine learning project using logistic regression to predict heart disease based on clinical and demographic features
Heart disease is one of the leading causes of death worldwide, making early detection and prediction crucial for preventive healthcare. This project implements a machine learning solution using Logistic Regression to predict the likelihood of heart disease in patients based on various clinical and demographic parameters.
| Attribute | Value |
|---|---|
| Total Records | 303 patients |
| Features | 13 clinical/demographic variables |
| Target Classes | 2 (Heart Disease: Yes/No) |
| Missing Values | None (Complete dataset) |
| File Format | CSV |
| Data Quality | High-quality medical data |
| Feature | Type | Description | Clinical Significance |
|---|---|---|---|
| age | Numerical | Patient age (29-77 years) | Risk increases with age |
| sex | Binary | Gender (1=Male, 0=Female) | Different risk patterns by gender |
| cp | Categorical | Chest pain type (0-3) | Key symptom indicator |
| trestbps | Numerical | Resting blood pressure (mm Hg) | Major cardiovascular risk factor |
| chol | Numerical | Serum cholesterol (mg/dl) | High levels increase risk |
| fbs | Binary | Fasting blood sugar >120 mg/dl | Diabetes indicator |
| restecg | Categorical | Resting ECG results (0-2) | Heart electrical activity |
| thalach | Numerical | Maximum heart rate achieved | Exercise capacity indicator |
| exang | Binary | Exercise induced angina | Stress test result |
| oldpeak | Numerical | ST depression induced by exercise | ECG stress test measure |
| slope | Categorical | Slope of peak exercise ST segment | Exercise test parameter |
| ca | Numerical | Number of major vessels colored (0-3) | Coronary angiography result |
| thal | Categorical | Thalassemia type (1-3) | Blood disorder indicator |
| Technology | Purpose | Version |
|---|---|---|
| Python | Primary programming language | 3.7+ |
| Pandas | Data manipulation and analysis | Latest |
| NumPy | Numerical computing | Latest |
| Scikit-learn | Machine learning library | Latest |
| Matplotlib | Data visualization | Latest |
| Seaborn | Statistical visualization | Latest |
| Jupyter Notebook | Interactive development | Latest |
numpy>=1.19.0
pandas>=1.2.0
scikit-learn>=0.24.0
matplotlib>=3.3.0
seaborn>=0.11.0
jupyter>=1.0.0
| Metric | Training Data | Testing Data |
|---|---|---|
| Accuracy | ~85-90% | ~85%+ |
| Precision | High | Consistent |
| Recall | High | Consistent |
| F1-Score | Balanced | Stable |
Logistic-Heart-Disease-Prediction/
βββ π heart_disease_data.csv # Dataset file
βββ π Logistic-Heart-Disease-Prediction.ipynb # Main notebook
βββ π README.md # This file
βββ π LICENSE # License information
βββ π docs/ # Documentation
βββ π dataset.md # Dataset documentation
βββ π€ logistic-regression-model.md # Model documentation
heart_disease_data.csv: Complete dataset with 303 patient recordsLogistic-Heart-Disease-Prediction.ipynb: Main Jupyter notebook with complete analysisdocs/dataset.md: Detailed dataset documentation and feature descriptionsdocs/logistic-regression-model.md: Comprehensive model documentationREADME.md: Project overview and instructionsLICENSE: License terms and conditionsClone the Repository
git clone https://github.com/NhanPhamThanh-IT/Logistic-Heart-Disease-Prediction.git
cd Logistic-Heart-Disease-Prediction
Create Virtual Environment (Recommended)
# Windows
python -m venv venv
venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activate
Install Dependencies
pip install numpy pandas scikit-learn matplotlib seaborn jupyter
Launch Jupyter Notebook
jupyter notebook
Open the Main Notebook
Logistic-Heart-Disease-Prediction.ipynbOpen the Jupyter Notebook
jupyter notebook Logistic-Heart-Disease-Prediction.ipynb
Run the Complete Analysis
Make Predictions
# Example prediction for a new patient
input_data = (62, 0, 0, 140, 268, 0, 0, 160, 0, 3.6, 0, 2, 2)
prediction = model.predict([input_data])
if prediction[0] == 0:
print('No Heart Disease Detected')
else:
print('Heart Disease Risk Detected')
To predict heart disease for a new patient, provide the following 13 features in order:
# Feature order: age, sex, cp, trestbps, chol, fbs, restecg,
# thalach, exang, oldpeak, slope, ca, thal
# Example: 62-year-old female with specific medical parameters
patient_data = (62, 0, 0, 140, 268, 0, 0, 160, 0, 3.6, 0, 2, 2)
risk_prediction = model.predict([patient_data])
confidence_score = model.predict_proba([patient_data])
π₯ Data Loading
π Exploratory Data Analysis
βοΈ Data Preprocessing
π€ Model Training
π Model Evaluation
π― Prediction System
# Model Parameters
model = LogisticRegression(
random_state=42, # Reproducibility
max_iter=1000, # Convergence assurance
solver='liblinear' # Optimal for small datasets
)
# Train-Test Split Configuration
X_train, X_test, Y_train, Y_test = train_test_split(
X, Y,
test_size=0.2, # 20% for testing
stratify=Y, # Maintain class balance
random_state=2 # Reproducible splits
)