{"id":23986637,"url":"https://github.com/senapedev/iris-binary-classification","last_synced_at":"2026-06-08T20:31:35.197Z","repository":{"id":271229030,"uuid":"912783573","full_name":"SenapeDev/iris-binary-classification","owner":"SenapeDev","description":"Single layer perceptron for binary classification of two iris species.","archived":false,"fork":false,"pushed_at":"2025-01-06T14:23:38.000Z","size":324,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-17T20:31:58.288Z","etag":null,"topics":["binary-classification","iris-dataset","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SenapeDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-06T11:39:28.000Z","updated_at":"2025-01-21T09:55:59.000Z","dependencies_parsed_at":"2025-01-06T12:44:25.022Z","dependency_job_id":null,"html_url":"https://github.com/SenapeDev/iris-binary-classification","commit_stats":null,"previous_names":["senapedev/iris-binary-classification"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SenapeDev/iris-binary-classification","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenapeDev%2Firis-binary-classification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenapeDev%2Firis-binary-classification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenapeDev%2Firis-binary-classification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenapeDev%2Firis-binary-classification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SenapeDev","download_url":"https://codeload.github.com/SenapeDev/iris-binary-classification/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenapeDev%2Firis-binary-classification/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34080025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"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":["binary-classification","iris-dataset","machine-learning"],"created_at":"2025-01-07T15:36:43.756Z","updated_at":"2026-06-08T20:31:35.174Z","avatar_url":"https://github.com/SenapeDev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Iris binary classification model\nThis project implements a simple binary classification model using logistic regression to classify two species of the Iris dataset: **Iris-setosa** and **Iris-versicolor**. The model uses the first two features of the dataset (*sepal length* and *sepal width*) and is trained using gradient descent.\n\n## Features\n- Binary classification of two Iris species.\n- Visualizes the decision boundary during training and testing.\n- Evaluates model accuracy on the test set.\n- Fully modular code for ease of reuse and modification.\n\n## Dataset\nThe code uses the [Iris dataset](https://archive.ics.uci.edu/dataset/53/iris), which contains measurements of 150 flowers from three species:\n- **Iris-setosa**\n- **Iris-versicolor**\n- **Iris-virginica**\n\n### Data used in this project\nFor this binary classification task:\n- **Iris-setosa** is labeled as `0`.\n- **Iris-versicolor** is labeled as `1`.\n- The first two features are used:\n    - Sepal length (in cm)\n    - Sepal width (in cm)\n\n## Dependencies\nThe following Python libraries are required to run the code:\n- `numpy`\n- `pandas`\n- `matplotlib`\n### Installation\n```python\npip install numpy pandas matplotlib\n```\n\n## Code analysis\n### Data loading and preprocessing\nThe dataset is loaded from the `iris.data` file. Only the first two features and two classes are used.\n- `load_data(file_name)`\n  Splits the dataset into:\n    - **Training set**: 80% of the data (40 samples of each class).\n    - **Test set**: 20% of the data (10 samples of each class).\n\n### Model Initialization\nThe model is initialized with random weights and a bias.\n- `initialize_parameters(features)`\n\t- Random values for weights and bias are generated within the range $[-0.5, 0.5]$.\n\t- A weight is generated for each feature.\n\n### Model Training\nThe model is trained using gradient descent for a specified number of epochs. The training process visualizes the decision boundary at 10 evenly spaced epochs.\n\n- `train_model(x_train, y_train, weights, bias, epochs, eta)`\n\n### **Activation**\nThe model's activation is calculated as:\n\n\u003e$$y = \\sigma(w \\cdot x + b)$$\n\nWhere:\n- $\\sigma(z) = \\frac{1}{1 + e^{-z}}$​ is the sigmoid function.\n- $w$: Weight vector.\n- $x$: Input features.\n- $b$: Bias.\n\n### **Gradient**\nThe gradient of the error with respect to the prediction is given by:\n\n\u003e$$\\text{gradient} = (y - y_{\\text{expected}}) \\cdot y \\cdot (1 - y)$$\n\nWhere:\n- $y_{\\text{expected}}$​: Expected value (target).\n- $y$: Predicted output.\n\n#### Weight Update\nWeights are updated according to the gradient rule:\n\u003e$$w \\leftarrow w - \\eta \\cdot \\frac{1}{N} \\cdot (x^T \\cdot \\text{gradient})$$\n\nWhere:\n- $\\eta$: Learning rate.\n- $N$: Number of samples in the batch.\n- $x^T$: Transpose of the input matrix.\n\n### **4. Bias Update**\n\nThe bias is updated as:\n\n\u003e$$b \\leftarrow b - \\eta \\cdot \\frac{1}{N} \\cdot \\sum \\text{gradient}$$\n\n### Evaluation\nThe model is evaluated on the test set:\n- `evaluate_model(x_test, y_test, weights, bias)`\n\n### Visualization\nThe decision boundary and the predictions on the test set are visualized:\n- `visualize_test_predictions(x_test, y_pred_test, weights, bias)`\n\n## How to run\n### Clone the repository\n```bash\ngit clone https://github.com/SenapeDev/iris-binary-classification\n```\n\n### Download the dataset\nPlace the `iris.data` file in the same directory as the script. [Download](https://archive.ics.uci.edu/dataset/53/iris)\n\n### Run the script\n```bash\npython3 neural_network.py\n```\n\n## Output\n```\nDataset Iris loaded:\n     0    1    2    3            4\n0  5.1  3.5  1.4  0.2  Iris-setosa\n1  4.9  3.0  1.4  0.2  Iris-setosa\n2  4.7  3.2  1.3  0.2  Iris-setosa\n3  4.6  3.1  1.5  0.2  Iris-setosa\n4  5.0  3.6  1.4  0.2  Iris-setosa\nAccuracy on test set: 95.00%\n```\n\n### Screenshots\n#### Training\nDuring training, the decision boundary evolves to separate the two classes.\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"screenshots/Figure_1.png\" alt=\"Figure_1\" width=\"70%\"\u003e\n\u003c/div\u003e\n\n#### Test\nAfter training, the test set is visualized with predictions and the decision boundary.\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"screenshots/Figure_2.png\" alt=\"Figure_2\" width=\"50%\"\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenapedev%2Firis-binary-classification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsenapedev%2Firis-binary-classification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenapedev%2Firis-binary-classification/lists"}