{"id":24360397,"url":"https://github.com/dms-codes/decision-tree-drugs","last_synced_at":"2026-04-24T10:33:39.897Z","repository":{"id":267078326,"uuid":"900206950","full_name":"dms-codes/decision-tree-drugs","owner":"dms-codes","description":"Decision Tree Classifier with Grid Search and Visualization","archived":false,"fork":false,"pushed_at":"2024-12-08T06:50:03.000Z","size":121,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-26T21:52:54.483Z","etag":null,"topics":["decison-trees","machine-learning","python"],"latest_commit_sha":null,"homepage":"https://github.com/dms-codes/decision-tree-drugs","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-12-08T06:36:14.000Z","updated_at":"2024-12-08T07:06:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"8f4d37eb-7f20-4f88-ae9e-d375600c9eeb","html_url":"https://github.com/dms-codes/decision-tree-drugs","commit_stats":null,"previous_names":["dms-codes/decisiion-tree-drugs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dms-codes/decision-tree-drugs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-tree-drugs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-tree-drugs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-tree-drugs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-tree-drugs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dms-codes","download_url":"https://codeload.github.com/dms-codes/decision-tree-drugs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dms-codes%2Fdecision-tree-drugs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32219123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T10:26:35.452Z","status":"ssl_error","status_checked_at":"2026-04-24T10:25:27.643Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["decison-trees","machine-learning","python"],"created_at":"2025-01-18T21:19:39.788Z","updated_at":"2026-04-24T10:33:39.891Z","avatar_url":"https://github.com/dms-codes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Decision Tree Classifier with Grid Search and Visualization\n\nThis project demonstrates how to build, train, and evaluate a **Decision Tree Classifier** using **GridSearchCV** for hyperparameter tuning. The dataset used is the `drug200.csv`, which contains information about drug prescriptions based on patient data. The code includes data preprocessing, model training, evaluation, and decision tree visualization.\n\n---\n\n## Features\n\n- **Data Loading and Cleaning**: Reads data from a CSV file and handles missing values.\n- **Preprocessing**:\n  - Encodes categorical variables.\n  - Scales numerical features for optimal performance.\n- **Model Training**:\n  - Uses `DecisionTreeClassifier` with hyperparameter tuning via `GridSearchCV`.\n- **Evaluation**:\n  - Calculates accuracy, classification report, and confusion matrix.\n- **Visualization**:\n  - Visualizes the decision tree using `matplotlib` and `plot_tree`.\n\n---\n\n## Requirements\n\nTo run this code, you need the following Python packages installed:\n\n- `pandas`\n- `numpy`\n- `scikit-learn`\n- `matplotlib`\n\nYou can install the required packages using:\n\n```bash\npip install pandas numpy scikit-learn matplotlib\n```\n\n---\n\n## File Structure\n\n```plaintext\n.\n├── data/\n│   └── drug200.csv       # Dataset file\n├── decision_tree.py      # Main script containing the code\n└── README.md             # Documentation\n```\n\n---\n\n## Usage\n\n### 1. Dataset\n\nEnsure the `drug200.csv` file is located in the `data/` directory. The dataset should include the following columns:\n\n- **Features**: Various patient-related data.\n- **Target Column (`Drug`)**: The drug prescribed (e.g., `drugA`, `drugB`, `drugC`, `drugX`, `drugY`).\n\n---\n\n### 2. Running the Code\n\n1. Clone this repository or download the code.\n2. Navigate to the directory containing the script.\n3. Run the script using:\n\n   ```bash\n   python decision_tree.py\n   ```\n\n---\n\n## Output\n\n### 1. Console Outputs:\n- **Best Hyperparameters**: Displays the best hyperparameter combination found by `GridSearchCV`.\n- **Evaluation Metrics**:\n  - Accuracy\n  - Classification Report\n  - Confusion Matrix\n\n### 2. Visualization:\nA decision tree plot displaying:\n- Feature splits\n- Feature importance\n- Class labels\n\nExample:\n![Decision Tree Example](https://github.com/dms-codes/decisiion-tree-drugs/blob/main/decision-tree-drugs.png?raw=true)\n\n---\n\n## Customization\n\n### File Paths:\nModify the `DATA_DIR` and `DATA_FILE` constants to change the dataset path:\n\n```python\nDATA_DIR = \"data\"\nDATA_FILE = \"drug200.csv\"\n```\n\n### Target Column:\nUpdate the `TARGET_COLUMN` constant to specify the target column name:\n\n```python\nTARGET_COLUMN = \"Drug\"\n```\n\n### Class Labels:\nUpdate the `class_names` parameter in the visualization function for your dataset's target labels:\n\n```python\nclass_names=['drugA', 'drugB', 'drugC', 'drugX', 'drugY']\n```\n\n---\n\n## Dependencies and Version Information\n\nThis code has been tested with the following versions:\n- Python 3.8+\n- scikit-learn 1.2+\n- pandas 1.4+\n- matplotlib 3.5+\n\n---\n\n## Acknowledgments\n\n- **Dataset**: The `drug200.csv` dataset used in this project.\n- **Libraries**: This project leverages the power of scikit-learn and matplotlib for machine learning and visualization.\n\n---\n\n## License\n\nThis project is licensed under the MIT License. You are free to use, modify, and distribute this code for any purpose.\n\n---\n\n## Author\n\nIf you have any questions, feel free to reach out! 😊\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdms-codes%2Fdecision-tree-drugs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdms-codes%2Fdecision-tree-drugs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdms-codes%2Fdecision-tree-drugs/lists"}