{"id":20381418,"url":"https://github.com/nouranhaitham/ml_waterquality","last_synced_at":"2026-01-05T11:05:51.842Z","repository":{"id":240270998,"uuid":"802171454","full_name":"NouranHaitham/ML_WaterQuality","owner":"NouranHaitham","description":"A notebook aimed at predicting and improving water safety by analyzing contaminants and pollution levels in water sources, enhancing public health and ensuring access to clean drinking water.","archived":false,"fork":false,"pushed_at":"2024-09-16T20:48:24.000Z","size":5045,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-15T07:36:55.092Z","etag":null,"topics":["classification-models","cleansing-data","dataprocessing","dataset","decision-trees","gridsearchcv","hyperparameter-tuning","logistic-regression","machine-learning","prediction","python","randomforestclassifier","regression-models","water-quality"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NouranHaitham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-17T16:52:52.000Z","updated_at":"2024-11-15T09:21:13.000Z","dependencies_parsed_at":"2024-08-21T17:19:49.118Z","dependency_job_id":"4d7fb0f2-67a3-490f-b929-30cde3f41a2a","html_url":"https://github.com/NouranHaitham/ML_WaterQuality","commit_stats":null,"previous_names":["niro12-coder/ml-water-quality-project","nouranhaitham/ml-water-quality-project","nouranhaitham/ml_waterquality"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NouranHaitham%2FML_WaterQuality","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NouranHaitham%2FML_WaterQuality/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NouranHaitham%2FML_WaterQuality/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NouranHaitham%2FML_WaterQuality/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NouranHaitham","download_url":"https://codeload.github.com/NouranHaitham/ML_WaterQuality/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241933109,"owners_count":20044645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classification-models","cleansing-data","dataprocessing","dataset","decision-trees","gridsearchcv","hyperparameter-tuning","logistic-regression","machine-learning","prediction","python","randomforestclassifier","regression-models","water-quality"],"created_at":"2024-11-15T02:13:46.597Z","updated_at":"2026-01-05T11:05:51.774Z","avatar_url":"https://github.com/NouranHaitham.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ML_WaterQuality 🚰\n\n## **Project Overview**\nClean, safe drinking water is super important for health and development! 🌍💧 This project is all about predicting if water samples are potable (safe to drink) or not, using various physical and chemical properties. We’re diving into different machine learning models to figure out whether your water is ready for a sip or needs some more testing. 🧪📊\n\n## **Objective**\nWe want to build a trusty classification model that can tell if water samples are safe to drink based on their features. We’ll use data preprocessing, exploratory data analysis (EDA), feature engineering, and machine learning algorithms to get the best results. 🏆💡\n\n---\n\n## **Project Structure**\n\n### 1. **Data Preprocessing** 🛠️\n   - **Handling Duplicates**: Double-checked and made sure there are no duplicate rows.\n   - **Missing Values**: Filled in missing values for `ph`, `Sulfate`, and `Trihalomethanes` with mean and median values.\n   - **Outlier Detection and Handling**: Found outliers, visualized them with box plots, and transformed those tricky features.\n   - **Feature Scaling**: Scaled features like `Conductivity`, `Solids`, and `Hardness` using `MinMaxScaler` to help the models work better.\n   - **Correlation Analysis**: Made a cool correlation heatmap to see how features relate to each other.\n\n### 2. **Class Imbalance** ⚖️\n   - Our dataset had more non-potable samples, so we used **SMOTE (Synthetic Minority Over-sampling Technique)** to balance things out. \n\n### 3. **Modeling** 🤖\n   We tried out and compared several machine learning models:\n   - **K-Nearest Neighbors (KNN)**: Tuned with `GridSearchCV` and checked accuracy, precision, recall, and F1-score.\n   - **Decision Tree**: Adjusted parameters like `min_samples_split` and `max_depth` for better results.\n   - **Random Forest**: Fine-tuned `n_estimators`, `min_samples_split`, and `max_depth` to boost accuracy.\n   - **Other Models**: Also gave Logistic Regression and SVM (Support Vector Machine) a spin.\n\n### 4. **Evaluation** 📈\n   - We checked out models based on accuracy, precision, recall, F1-score, and confusion matrices.\n   - Used **cross-validation** to make sure our models were solid and not overfitting.\n   - **Best Model**: KNN with `n_neighbors = 23` was the champ based on cross-validation and overall performance.\n\n---\n\n## **Dataset**\n\nThe dataset is publicly available and includes:\n- **pH**: pH level of the water (0 to 14).\n- **Hardness**: How hard the water is, measured in mg/L.\n- **Solids**: Total dissolved solids in ppm.\n- **Chloramines**: Amount of chloramines in ppm.\n- **Sulfate**: Amount of sulfates in mg/L.\n- **Conductivity**: Electrical conductivity in μS/cm.\n- **Organic Carbon**: Amount of organic carbon in ppm.\n- **Trihalomethanes**: Amount of Trihalomethanes in μg/L.\n- **Turbidity**: How clear the water is, measured in NTU.\n- **Potability**: Whether the water is potable (1) or not (0).\n\n---\n\n## **Installation** 🛠️\n\n1. Clone the repo:\n   ```bash\n   git clone https://github.com/yourusername/water-potability-prediction.git\n   ```\n   \n2. Navigate to the project directory:\n   ```bash\n   cd water-potability-prediction\n   ```\n   \n3. Install the required dependencies:\n   ```bash\n   pip install -r requirements.txt\n   ```\n   \n4. Download the dataset and place it in the root directory:\n\n - Water Potability Dataset\n\n\n5. Run the Project Notebooks:\nFor Exploratory Data Analysis (EDA) and Data Preprocessing, navigate to the notebooks folder and run the Jupyter notebooks:\n```bash\njupyter notebook data_analysis.ipynb\n```\n6. Run the Model Training:\nAfter preprocessing the data, you can train the models by executing the train_models.py script:\n```bash\npython train_models.py\n```\n## **Usage** 🚀\n\n1. **Exploratory Data Analysis (EDA)** 🔍:\n   Run the `data_analysis.ipynb` notebook to dive into the dataset, spot missing values, and explore how features connect to water potability.\n\n2. **Data Preprocessing** 🛠️:\n   The `preprocessing.py` script handles missing values, detects outliers, and scales features. Feel free to tweak it if you need extra steps!\n\n3. **Model Training** 🤖:\n   Use `train_models.py` to train several machine learning models, including KNN, Decision Trees, and Random Forests. You can adjust hyperparameters directly in the script.\n\n4. **Model Evaluation** 📊:\n   After training, the script will show you how each model performs with metrics like accuracy, precision, recall, F1-score, and confusion matrix. Perfect for comparing results!\n\n## **Technologies Used** 💻\n\n- **Python**: Our main coding language.\n- **Pandas**: For all your data manipulation needs.\n- **NumPy**: For numerical operations.\n- **Scikit-learn**: For machine learning magic.\n- **Matplotlib \u0026 Seaborn**: For awesome data visualizations.\n- **SMOTE**: To balance out the dataset.\n- **GridSearchCV**: For fine-tuning hyperparameters and getting the best performance.\n\n## **Results** 🌟\n\nThe star of the show is the KNN model with `n_neighbors = 23`, achieving:\n- **Accuracy**: 79.5%\n- **Precision**: 81.3%\n- **Recall**: 76.9%\n- **F1-Score**: 79.0%\n\n## **Future Improvements** 🔧\n\n- Experiment with more models like XGBoost or LightGBM.\n- Implement feature selection to streamline the model.\n- Further tune hyperparameters with RandomizedSearchCV.\n- Deploy the model as an API to make real-time water potability predictions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnouranhaitham%2Fml_waterquality","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnouranhaitham%2Fml_waterquality","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnouranhaitham%2Fml_waterquality/lists"}