{"id":21185578,"url":"https://github.com/manome/python-silvq","last_synced_at":"2025-06-16T19:37:16.901Z","repository":{"id":187004726,"uuid":"347732112","full_name":"manome/python-silvq","owner":"manome","description":"This project provides an implementation of self-incremental learning vector quantization. This implementation is based on the below paper. https://www.nature.com/articles/s41598-021-83182-4.","archived":false,"fork":false,"pushed_at":"2024-08-16T09:15:05.000Z","size":822,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T20:16:11.676Z","etag":null,"topics":["learning-vector-quantization","learning-vector-quantization-network","supervised-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manome.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}},"created_at":"2021-03-14T19:21:59.000Z","updated_at":"2024-08-16T09:15:08.000Z","dependencies_parsed_at":"2024-08-17T03:31:30.427Z","dependency_job_id":null,"html_url":"https://github.com/manome/python-silvq","commit_stats":null,"previous_names":["manome/python-silvq"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/manome/python-silvq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manome%2Fpython-silvq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manome%2Fpython-silvq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manome%2Fpython-silvq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manome%2Fpython-silvq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manome","download_url":"https://codeload.github.com/manome/python-silvq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manome%2Fpython-silvq/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260224604,"owners_count":22977432,"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":["learning-vector-quantization","learning-vector-quantization-network","supervised-learning"],"created_at":"2024-11-20T18:17:11.660Z","updated_at":"2025-06-16T19:37:16.874Z","avatar_url":"https://github.com/manome.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Self-incremental learning vector quantization\n\nThis implementation is based on the below paper.\nSelf-incremental learning vector quantization with human cognitive biases (https://www.nature.com/articles/s41598-021-83182-4).\n\nCompatible with Python3.6 and above.\n\n## Requirements\n\n- NumPy\n- scikit-learn\n- matplotlib\n\n## Quickstart\n\nThis is the minimum code to run SilvqModel.\n\n```python\nimport numpy as np\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.datasets import load_iris\nfrom lvq import SilvqModel\n\n# Load dataset\niris = load_iris()\nx = iris.data\ny = iris.target\n# Split dataset into training set and test set\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=8, shuffle=True, stratify=y)\n\n# Generating model\nmodel = SilvqModel(x.shape[1], theta=0.8, bias_type='ls')\n# Training the model\nmodel.fit(x_train, y_train, epochs=1)\n# Predict the response for test dataset\ny_predict = model.predict(x_test)\n\n# Evaluating the model\nprint('Accuracy: %.3f' %accuracy_score(y_test, y_predict))\n```\n\nFor more information, [score_iris_silvq.py](score_iris_silvq.py).\n\n## Techniques\n\nThe following techniques can be used to improve accuracy.\n\n```python\nfrom lvq import SilvqModel\nfrom lvq.utils import choice_prototypes\n\ninitial_prototypes = choice_prototypes(x_train, y_train, prototypes_per_class=1, random_state=None)\nmodel = SilvqModel(x.shape[1], theta=0.5, bias_type='ls', initial_prototypes=initial_prototypes)\nmodel.fit(x_train, y_train, epochs=30)\n```\n\nFor more information, [score_wine_silvq.py](score_wine_silvq.py).\n\n## Conformal prediction\n\nConformal prediction can be performed.\n\n```python\nimport numpy as np\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.datasets import load_digits\nfrom lvq import SilvqModel\nfrom lvq.utils import conformal_predict, accuracy_score_conformal_predictions\n\n# Load dataset\ndigits = load_digits()\nx = digits.data\ny = digits.target\n# Split dataset into training set and test set\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=8, shuffle=True, stratify=y)\n# Split training dataset into training set and calibration set\nx_train, x_calib, y_train, y_calib = train_test_split(x_train, y_train, test_size=0.2, random_state=8, shuffle=True, stratify=y_train)\n\n# Generating model\nmodel = SilvqModel(x.shape[1], theta=0.5, bias_type='ls')\n# Training the model\nmodel.fit(x_train, y_train, epochs=30)\n# Predict the response for test dataset\ny_predict = model.predict(x_test)\n\n# Evaluate the model's accuracy\nprint('Accuracy: %.3f' %accuracy_score(y_test, y_predict))\n\n# Conformal prediction\nconformal_predictions = conformal_predict(model, x_calib, y_calib, x_test, confidence_level=0.99)\n\n# Evaluate the model's accuracy in conformal predictions\nprint('Conformal prediction accuracy: %.3f' %accuracy_score_conformal_predictions(y_test, conformal_predictions))\n\n# Display the results of 10 conformal predictions\nprint('** Displaying 10 sample conformal predictions')\nfor idx in range(10):\n    print('Test{}: True Label: {}, Predicted: {}'.format(idx, y_test[idx], conformal_predictions[idx]))\nprint('*********************************************')\n```\n\nFor more information, [score_conformal_prediction_digits_silvq.py](score_conformal_prediction_digits_silvq.py).\n\n## Data compression \u0026 noise reduction\n\nYou can use this model to perform data compression and noise reduction.\n\n```python\nimport numpy as np\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.datasets import load_breast_cancer\nfrom lvq import SilvqModel\n\n# Load dataset\nbreast_cancer = load_breast_cancer()\nx = breast_cancer.data\ny = breast_cancer.target\n# Split dataset into training set and test set\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=8, shuffle=True, stratify=y)\n\n# Generating model\nmodel = SilvqModel(x.shape[1], theta=0.5, bias_type='ls')\n# Training the model\nmodel.fit(x_train, y_train, epochs=30)\n# Predict the response for test dataset\ny_predict = model.predict(x_test)\n\n# Evaluating the model\nprint('** Original ****************************')\nprint('Accuracy: %.3f' %accuracy_score(y_test, y_predict))\nprint('Number of prototypes: {}'.format(model.n_prototypes))\n\n# Noise reduction\nmodel.delete_prototype(140)\n# Predict the response for test dataset\ny_predict = model.predict(x_test)\n\n# Evaluating the model\nprint('** Noise reduction *********************')\nprint('Accuracy: %.3f' %accuracy_score(y_test, y_predict))\nprint('Number of prototypes: {}'.format(model.n_prototypes))\n```\n\nFor more information, [export_compression_artificial_dataset2_silvq.py](export_compression_artificial_dataset2_silvq.py), [export_compression_and_noise_reduction_artificial_dataset2_silvq.py](export_compression_and_noise_reduction_artificial_dataset2_silvq.py), and [score_noise_reduction_breast_cancer_silvq.py](score_noise_reduction_breast_cancer_silvq.py).\n\n## Plot prototypes\n\nYou can use plot2d to visualize the prototype of SilvqModel.\n\n```python\nfrom lvq.utils import plot2d\nplot2d(model, x, y)\n```\n\nThe plot shows the target class of each data point (big circle) and which class was predicted (smaller circle).\nIt also shows the prototypes (diamond).\n\n\u003cp align='center'\u003e\n    \u003cimg src='img/plot2d_artificial_dataset1_silvq.png' alt='plot2d_artificial_dataset1_silvq'\u003e\n\u003c/p\u003e\n\nFor more information, [plot2d_artificial_dataset1_silvq.py](plot2d_artificial_dataset1_silvq.py).\n\n\u003cp align='center'\u003e\n    \u003cimg src='img/plot2d_artificial_dataset2_silvq.png' alt='plot2d_artificial_dataset2_silvq'\u003e\n\u003c/p\u003e\n\nFor more information, [plot2d_artificial_dataset2_silvq.py](plot2d_artificial_dataset2_silvq.py).\n\n\u003cp align='center'\u003e\n    \u003cimg src='img/plot2d_moons_silvq.png' alt='plot2d_moons_silvq.png'\u003e\n\u003c/p\u003e\n\nFor more information, [plot2d_moons_silvq.py](plot2d_moons_silvq.py).\n\n## Note\nSelf-incremental learning vector quantization (SILVQ) provides a learning algorithm that can be intuitively understood. To improve SILVQ performance, distances other than the Euclidean distance, such as cosine distance, may be used instead. As with advanced LVQ algorithms designing models to strictly minimize classification errors may be possible. However, human learning is variable and compound; it is not exclusively based on minimizing the classification errors.\n\nThis research aims to contribute to both the computer science and cognitive science fields and hopes to support the research of explainable artificial intelligence (XAI) to address the black box problem of machine learning.\n\n## License\nThis is free and open-source software licensed under the 3-clause BSD license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanome%2Fpython-silvq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanome%2Fpython-silvq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanome%2Fpython-silvq/lists"}