{"id":24360399,"url":"https://github.com/dms-codes/decision-trees-drug","last_synced_at":"2025-10-06T02:16:03.775Z","repository":{"id":258017174,"uuid":"873259725","full_name":"dms-codes/decision-trees-drug","owner":"dms-codes","description":"This project implements a Decision Tree Classifier to predict the type of drug a patient should take based on their characteristics (age, sex, blood pressure, cholesterol levels, and sodium-potassium ratio). The model is trained using a dataset and evaluated based on its accuracy.","archived":false,"fork":false,"pushed_at":"2024-10-15T21:35:28.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-15T07:04:01.811Z","etag":null,"topics":["decision-trees","python","scikitlearn-machine-learning"],"latest_commit_sha":null,"homepage":"https://github.com/dms-codes/decision-trees-drug","language":"Python","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/dms-codes.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-10-15T21:33:14.000Z","updated_at":"2024-10-15T21:36:05.000Z","dependencies_parsed_at":"2024-10-18T03:35:16.203Z","dependency_job_id":null,"html_url":"https://github.com/dms-codes/decision-trees-drug","commit_stats":null,"previous_names":["dms-codes/decision-trees-drug"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dms-codes/decision-trees-drug","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-trees-drug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-trees-drug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-trees-drug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-trees-drug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dms-codes","download_url":"https://codeload.github.com/dms-codes/decision-trees-drug/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-trees-drug/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278547821,"owners_count":26004775,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["decision-trees","python","scikitlearn-machine-learning"],"created_at":"2025-01-18T21:19:39.979Z","updated_at":"2025-10-06T02:16:03.739Z","avatar_url":"https://github.com/dms-codes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Drug Classification Using Decision Tree\n\nThis project implements a Decision Tree Classifier to predict the type of drug a patient should take based on their characteristics (age, sex, blood pressure, cholesterol levels, and sodium-potassium ratio). The model is trained using a dataset and evaluated based on its accuracy.\n\n## Features\n\n- **Data Loading and Exploration**: Loads the dataset and displays basic statistics and information.\n- **Preprocessing**: Encodes categorical variables (Sex, BP, Cholesterol) into numerical values.\n- **Model Training**: A Decision Tree classifier is trained on the dataset.\n- **Prediction**: The trained model is used to predict drug type on the test data.\n- **Evaluation**: The model’s accuracy is evaluated and predictions are compared against actual values.\n\n## Project Structure\n\n```bash\n.\n├── main.py          # Main script for running the project\n├── drug.csv         # Dataset used for training and testing the model\n└── README.md        # Project documentation\n```\n\n## Prerequisites\n\nEnsure you have the following installed:\n\n- Python 3.x\n- Required Python libraries:\n  - pandas\n  - scikit-learn\n  - matplotlib\n\nYou can install the necessary dependencies using `pip`:\n\n```bash\npip install pandas scikit-learn matplotlib\n```\n\n## Dataset\n\nThe dataset `drug.csv` contains the following columns:\n\n- `Age`: Age of the patient\n- `Sex`: Gender of the patient (M/F)\n- `BP`: Blood pressure levels (LOW, NORMAL, HIGH)\n- `Cholesterol`: Cholesterol levels (NORMAL, HIGH)\n- `Na_to_K`: Sodium-Potassium ratio in the patient's blood\n- `Drug`: The type of drug to be prescribed (target label)\n\nMake sure the dataset file `drug.csv` is in the same directory as `main.py` or provide the correct path to it.\n\n## How to Run the Project\n\n1. Clone the repository or download the source code.\n2. Ensure the `drug.csv` file is available in the same directory as `main.py`.\n3. Run the main Python script:\n\n```bash\npython main.py\n```\n\nThis will:\n- Load and preprocess the data.\n- Split the data into training and testing sets.\n- Train a Decision Tree model on the training data.\n- Evaluate the model's performance on the test data.\n- Display a comparison of predicted and actual values.\n\n### Output\n\n- The script will print information about the dataset, such as the first 5 rows, statistical summary, and data shape.\n- After training the model, it will print the accuracy of the model.\n- It will also display a DataFrame comparing the predicted and actual drug values.\n\n## Example Output\n\n```bash\nDataset Information:\n\u003cclass 'pandas.core.frame.DataFrame'\u003e\n...\n\nFirst 5 Rows of the Dataset:\n   Age Sex     BP Cholesterol  Na_to_K   Drug\n0   23   F   HIGH        NORMAL    25.355  drugY\n...\n\nStatistical Summary:\n...\n\nTrain set: (140, 5) (140,)\nTest set: (60, 5) (60,)\n\nPrediction vs Actual Comparison:\n    Predicted Values Actual Values\n0             drugX         drugY\n1             drugY         drugY\n...\n\nDecision Tree's Accuracy: 0.85\n```\n\n## License\n\nThis project is licensed under the MIT License.\n\n---\n\n### Customization\n\nYou can extend this project by:\n- Tuning the Decision Tree parameters (e.g., changing the criterion or maximum depth).\n- Trying different machine learning models such as Random Forest or Logistic Regression.\n- Adding more preprocessing steps if necessary.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdms-codes%2Fdecision-trees-drug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdms-codes%2Fdecision-trees-drug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdms-codes%2Fdecision-trees-drug/lists"}