{"id":13713601,"url":"https://github.com/kamil5b/knnGo","last_synced_at":"2025-05-07T00:31:42.081Z","repository":{"id":48787254,"uuid":"385003647","full_name":"kamil5b/knnGo","owner":"kamil5b","description":"I created K-Nearest Neighbor Algorithm using Go language. Initially, this project is for my assignment but I decided to publish it.","archived":false,"fork":false,"pushed_at":"2022-01-06T21:49:02.000Z","size":60,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-14T00:34:00.231Z","etag":null,"topics":["ai","artificial-intelligence","go","golang","knn","knn-algorithm","knn-classification","knn-classifier"],"latest_commit_sha":null,"homepage":"","language":"Go","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/kamil5b.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}},"created_at":"2021-07-11T16:50:43.000Z","updated_at":"2024-05-25T17:24:27.000Z","dependencies_parsed_at":"2022-07-25T05:16:10.067Z","dependency_job_id":null,"html_url":"https://github.com/kamil5b/knnGo","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil5b%2FknnGo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil5b%2FknnGo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil5b%2FknnGo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kamil5b%2FknnGo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kamil5b","download_url":"https://codeload.github.com/kamil5b/knnGo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252791485,"owners_count":21804780,"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":["ai","artificial-intelligence","go","golang","knn","knn-algorithm","knn-classification","knn-classifier"],"created_at":"2024-08-02T23:01:40.189Z","updated_at":"2025-05-07T00:31:41.776Z","avatar_url":"https://github.com/kamil5b.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# KNN Classification Algorithm using Go\n\nA basic K-Nearest Neighbors Classification Algorithm using Go by kamil5b\n\n### TABLE OF CONTENT\n\u003c!--\n- [How it work](#how-it-work)\n  * [Processing Dataset](#processing-dataset)\n  * [Processing Data Input](#processing-data-input)\n    + [Euclidean Distance](#euclidean-distance)\n    + [Mantahattan Distance](#mantahattan-distance)\n    + [Minkowski Distance](#minkowski-distance)\n    + [Chebyshev/Supremum Distance](#chebyshev-or-supremum-distance)\n    + [Cosine Distance](#cosine-distance)\n    + [Jaccard Distance](#jaccard-distance)\n- [How to use](#how-to-use)--\u003e\n- [How it work](#how-it-work)\n  * [Processing Dataset](#processing-dataset)\n  * [Processing Data Input](#processing-data-input)\n    + [Euclidean Distance](#euclidean-distance)\n    + [Manhattan Distance](#manhattan-distance)\n    + [Minkowski Distance](#minkowski-distance)\n    + [Chebyshev Or Supremum Distance](#chebyshev-or-supremum-distance)\n    + [Cosine Distance](#cosine-distance)\n    + [Jaccard Distance](#jaccard-distance)\n- [How to use](#how-to-use)\n  * [knnGo.go types and functions](#knngogo-types-and-functions)\n    + [type KNNData struct](#type-knndata-struct)\n    + [func KNNClassification](#func-knnclassification)\n    + [func (d KNNData) PrintKNNData](#func--d-knndata--printknndata)\n    + [func ValueVote](#func-valuevote)\n  * [distance.go functions](#distancego-functions)\n    + [func EuclideanDistance](#func-euclideandistance)\n    + [func ManhattanDistance](#func-manhattandistance)\n    + [func MinkowskiDistance](#func-minkowskidistance)\n    + [func ChebyshevDistance](#func-chebyshevdistance)\n    + [func SupremumDistance](#func-supremumdistance)\n    + [func CosineDistance](#func-cosinedistance)\n    + [func JaccardDistance](#func-jaccarddistance)\n\n# How it work\n\nThe inputs for this package are a dataset that contain a classification column and the attributes columns and an unclassified data input based on the dataset cases\n\n## Processing Dataset\n```Go\ntype KNNData struct {\n\tClassification string\n\tAttributes     []float64\n\tDistance       float64\n}\n```\n\nFor each data row in a dataset there will be a classification column and the attributes columns and they are casted to the KNNData type.\nEach attributes **have** to be casted to float64 before cast it to the KNNData Attributes.\n\nEach data row will be stored in the KNNData array.\n\n## Processing Data Input\n\nThe input is an unclassified data containing attributes that similar with or based on the dataset that we've worked on.\n\nCalculate the distance of the input data with the rest of data in the dataset using :\n\n- Euclidean Distance\n- Manhattan Distance\n- Minkowski Distance\n- Chebyshev/Supremum Distance\n- Cosine Distance\n- Jaccard Distace\n\n### Euclidean Distance\n\nEuclidean distance is the length of a line segment between the two points. \n\u003cimg src=\"https://render.githubusercontent.com/render/math?math=e^{i \\pi} = -1\"\u003e\n\n### Manhattan Distance\n\nManhattan distance is\n\n### Minkowski Distance\n\nMinkowski distance is\n\n### Chebyshev Or Supremum Distance\n\nChebyshev a.k.a Supremum distance is\n\n### Cosine Distance\n\nCosine distance is\n\n### Jaccard Distance\n\nJaccard distance is\n\n# How to use\n\nTo use this package, you have to download and install this repository.\n\nWrite this to your terminal :\n```sh\ngo get github.com/kamil5b/knnGo\n```\nIf you want to use this package to your code you also need to import it\n```Go\nimport github.com/kamil5b/knnGo\n```\n\nIn order this package work, the dataset you are using **must** be converted to an array of [KNNData](#type-knndata-struct) where the classification is a string and the attributes are float64. **(if your attributes data is ranked enum data, you may convert it to an integer array that contains the ranking of the enum which then convert it to discrete float64)**\n\n## knnGo.go types and functions\n### type KNNData struct\n```Go\ntype KNNData struct {\n\tClassification string\n\tAttributes     []float64\n\tDistance       float64\n}\n```\n### func KNNClassification\n```Go\nfunc KNNClassification(k int, dataset []KNNData, inputAttributes []float64, distance string, p int) (KNNData, error)\n```\nThis is the main function for this package. This function returning a KNNData containing the classification of the input data and for the attributes are the input data attribute itself. \n\n- k is a value for how much neighbor we observe\n- dataset in this parameter is an array of KNNData which is converted from dataset that we had\n- inputAttributes is an array of float64 that contains the input attributes\n- distance is an enum that converted into non-case-sensitive string. The available distances are :\n  * [euclidean](#func-euclideandistance)\n  * [manhattan](#func-manhattandistance)\n  * [minkowski](#func-minkowskidistance)\n  * [chebyshev](#func-chebyshevdistance)\n  * [supremum](#func-supremumdistance)\n  * [cosine](#func-cosinedistance)\n  * [jaccard](#func-jaccarddistance)\n- p is an integer for minkowski's distance order or the p value. the value doesn't matter if you are not choosing minkowski distance\n\nThis function will calculate the distance of the input data with every data in the duplicated dataset and sort ascending based on the distances and then pick the top-k of it and then the classification for the data input is the most populated class among the top-k.\n\n### func (d KNNData) PrintKNNData\n```Go\nfunc (d KNNData) PrintKNNData()\n```\nThis function is for printing the KNNData\n\n### func ValueVote\n```Go\nfunc ValueVote(arr []string) string\n```\n\n## distance.go functions\nFunctions in this file containing the metric distances that can be used in this package, it return an array of KNNData that each data containing the result of the distances.\n\n### func [EuclideanDistance](#euclidean-distance)\n```Go\nfunc EuclideanDistance(dataset []KNNData, inputAttributes []float64) ([]KNNData, error)\n```\n\n### func [ManhattanDistance](#manhattan-distance)\n```Go\nfunc ManhattanDistance(dataset []KNNData, inputAttributes []float64) ([]KNNData, error)\n```\n\n### func [MinkowskiDistance](#minkowski-distance)\n```Go\nfunc MinkowskiDistance(dataset []KNNData, inputAttributes []float64, p int) ([]KNNData, error)\n```\n\n### func [ChebyshevDistance](#chebyshev-or-supremum-distance)\n```Go\nfunc MinkowskiDistance(dataset []KNNData, inputAttributes []float64) ([]KNNData, error)\n```\n\n### func [SupremumDistance](#chebyshev-or-supremum-distance)\n```Go\nfunc MinkowskiDistance(dataset []KNNData, inputAttributes []float64) ([]KNNData, error)\n```\n\n### func [CosineDistance](#cosine-distance)\n```Go\nfunc MinkowskiDistance(dataset []KNNData, inputAttributes []float64) ([]KNNData, error)\n```\n\n### func [JaccardDistance](#jaccard-distance)\n```Go\nfunc MinkowskiDistance(dataset []KNNData, inputAttributes []float64) ([]KNNData, error)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkamil5b%2FknnGo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkamil5b%2FknnGo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkamil5b%2FknnGo/lists"}