{"id":22895885,"url":"https://github.com/daniel-lima-lopez/ada-knn-python","last_synced_at":"2025-03-31T23:38:56.645Z","repository":{"id":251271407,"uuid":"836863449","full_name":"daniel-lima-lopez/Ada-kNN-Python","owner":"daniel-lima-lopez","description":"A python implementation of the classifier Ada-kNN","archived":false,"fork":false,"pushed_at":"2024-08-13T19:42:11.000Z","size":545,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T01:45:42.033Z","etag":null,"topics":["ada-knn","adaptive-knn","knn","knn-algorithm","knn-classification","machine-learning","neural-networks"],"latest_commit_sha":null,"homepage":"","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/daniel-lima-lopez.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-08-01T18:02:09.000Z","updated_at":"2024-08-13T19:42:15.000Z","dependencies_parsed_at":"2024-12-13T23:32:40.972Z","dependency_job_id":"23a793f1-67a8-4920-8ed7-da7542b10dde","html_url":"https://github.com/daniel-lima-lopez/Ada-kNN-Python","commit_stats":null,"previous_names":["daniel-lima-lopez/ada-knn-python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-lima-lopez%2FAda-kNN-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-lima-lopez%2FAda-kNN-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-lima-lopez%2FAda-kNN-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-lima-lopez%2FAda-kNN-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniel-lima-lopez","download_url":"https://codeload.github.com/daniel-lima-lopez/Ada-kNN-Python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246558117,"owners_count":20796696,"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":["ada-knn","adaptive-knn","knn","knn-algorithm","knn-classification","machine-learning","neural-networks"],"created_at":"2024-12-13T23:32:36.250Z","updated_at":"2025-03-31T23:38:56.625Z","avatar_url":"https://github.com/daniel-lima-lopez.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ada-kNN-Python\nThis is a python implementation of the Ada-kNN classifier, proposed by [Mullick et al.](https://ieeexplore.ieee.org/abstract/document/8326728)\n## Classifier description\nThe classifier is an extension of kNN, in which a strategy based on Multi-layer perceptron (MLP) is proposed to automate the choice of the parameter k, for each instance to be classified.\n\nThe operation of Ada-kNN is described below:\n- First, for each instance $x_i$ in the training set, a series of experiments are performed to identify the $k$ values which correctly classify $x_i$ with kNN.\n- With this information, an MLP architecture is trained to predict the most appropriate $k$ value for classifying a given instance based on their attribute values.\n- Once the neural network has been trained, for each instance to be classified, the most appropriate value of $k$ is predicted with this network, then a conventional kNN classifier performs a prediction with this value.\n\n## Installation\nClone this repository:\n```bash\ngit clone git@github.com:daniel-lima-lopez/Ada-kNN-Python.git\n```\nmove to installation directory:\n```bash\ncd Ada-kNN-Python\n```\n\n## Basic usage\nThe classifier can be used without specifying any value:\n```python\nimport Ada_kNN as ada\nclassifier = ada.Ada_kNN()\n```\nHowever, the training parameters can be modified:\n- `alpha`: number of experiments consdiered on $X_{test}$\n- `lr` (0.01): learning rate for MLP traning\n- `batch_size` (4): batch size for MLP traning\n- `epochs` (100): number of epochs for MLP traning\n\nOnce instantiated the classifier, we can perform a simple test:\n```python\nimport pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score\n\n# data preapration\ndataset = pd.read_csv('Datasets/wine.csv')\nXs = dataset.drop('class', axis=1).values\nys = dataset['class'].values\n\n# data split\nX_train, X_test, y_train, y_test = train_test_split(Xs, ys, test_size=0.2, random_state=2) #12\n\n# fit the classifier\nclassifier.fit(X_train, y_train)\n\n# predictions on test set\npreds = classifier.predict(X_test)\nprint(f'accuracy: {accuracy_score(y_true=y_test, y_pred=preds)}')\n```\n\n## Experiments\nExperiments were conducted to compare the performance of Ada-kNN with kNN. On each experiment, a 10-fold cross-validation was performed. For kNN, the `k` values considered are 1, 3, 5, 7, and 9. The accuracy on appendicitis, balance-scale, bands, climate, music and spectf datasets are presented on the following figures, where it is observed that the dynamic decision of \nk-value enhances accuracy in certain cases, but in others, it does not:\n\n\u003cimg src=\"imgs/ks_appendicitis.png\" alt=\"drawing\" width=\"500\"/\u003e\n\u003cimg src=\"imgs/ks_balance-scale.png\" alt=\"drawing\" width=\"500\"/\u003e\n\u003cimg src=\"imgs/ks_bands.png\" alt=\"drawing\" width=\"500\"/\u003e\n\u003cimg src=\"imgs/ks_climate.png\" alt=\"drawing\" width=\"500\"/\u003e\n\u003cimg src=\"imgs/ks_music.png\" alt=\"drawing\" width=\"500\"/\u003e\n\u003cimg src=\"imgs/ks_spectf.png\" alt=\"drawing\" width=\"500\"/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-lima-lopez%2Fada-knn-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel-lima-lopez%2Fada-knn-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-lima-lopez%2Fada-knn-python/lists"}