{"_id":"@artificialscience/k-nn","_rev":"3-bc1fb954d17864a4f9097e54adde6f9a","name":"@artificialscience/k-nn","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@artificialscience/k-nn","version":"1.0.0","description":"A k-nearest neighbors algorithm implementation","main":"src/KNN.js","scripts":{"test":"nodemon --config nodemon.json --watch"},"repository":{"type":"git","url":"git+https://github.com/nihasoft/K-NN.git"},"dependencies":{},"devDependencies":{"nodemon":"^1.18.11"},"keywords":["KNN","K-NN","k-nearest neighbors algorithm"],"author":{"name":"Hanor Sátiro Cintra"},"license":"MIT","bugs":{"url":"https://github.com/nihasoft/K-NN/issues"},"homepage":"https://github.com/nihasoft/K-NN#readme","gitHead":"c3fb370777107156545d0a6909b852df1a276834","_id":"@artificialscience/k-nn@1.0.0","_nodeVersion":"12.2.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-cQiPpuidN7fmbE9/WRg8v1poXA1eTWMdbPfWrkK8LsrcUe5HHw/qBAQElFh4Hs2pDweZ9vE39Mw7dUyatANcYw==","shasum":"451db76c2b2c37251fc1cab92d8d0226ea3540dc","tarball":"https://registry.npmjs.org/@artificialscience/k-nn/-/k-nn-1.0.0.tgz","fileCount":7,"unpackedSize":107084,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc3h25CRA9TVsSAnZWagAAQpMP/0fSBzQ7NzoEbVvxL4Cs\n9xf4sIRMkhxW8/o3mChILE4wO530DG6CF/lLmrlVGEidQl0jkN6Uj4QzJ6XX\nYFeg3uxO+aaQpi8OejnRDiPO/nhxkkt8QXrrMI2pkWhGdtgHei5Od5i/0amB\nVgHBPXRgqrBERGiaMDytFetKVm3s0JKd0H5HIcFvD5m9BI1+5J1G3vhbQz3D\n6ZpAsRTa16tcK5wYm2rFlb9TnkkudIMbcLFZTlGoQFScjfdGn3CFEyv59xku\ng/SPSbzqS5OkvlwuaBGmcT3pM31Tgiks+YbHC0E/25P7d5BBV9uh/Y2TIwj8\nXmXN0mgZ8Co+IfOht0B2Errht9EIERLOgQBOYygtwEWaxpb/9Rl/in+byPid\nsNYAadieGTuamTr42EEAfx4GU8FSV3jjfO4RuQLOhUOsJt/G5erti7ix4OK4\nC7oW/kmouaXU8yQR6JLdOjtMw8WF/SOy1MlUNNTW9q0/sBpEEwDD4Gr/69Fu\nm/cbdfpUGTDJ1uz1oICLlWSTubLpNe7Km11n3JN09orVkzbC/LHl1rBnQ7lK\nyuBF1lC5eLXJ+BbeehuvXTPMnyQ233pHhTWIfsbY6msO0/iU1Tx7srfNaKYb\nsSU1XYB4kjU9vsZz4wRG1R4/Jfe0lWyBpht7O1xHX2/eYcfPpOZk0GxzII+R\nIx9B\r\n=truZ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCJnzRTbiQXr4fCfZDI3EbA54GeEZ6aoLi4P+rD8MoJLwIgPysQJBABC7otx5cwRxdLosoKjOf2VI1L0zX2AWBNTRM="}]},"maintainers":[{"name":"hanor","email":"hanor.cintra@outlook.com"}],"_npmUser":{"name":"hanor","email":"hanor.cintra@outlook.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/k-nn_1.0.0_1558060473144_0.5485238741178458"},"_hasShrinkwrap":false},"1.0.1":{"name":"@artificialscience/k-nn","version":"1.0.1","description":"A k-nearest neighbors algorithm implementation","main":"src/KNN.js","scripts":{"test":"nodemon --config nodemon.json --watch"},"repository":{"type":"git","url":"git+https://github.com/artificialscience/K-NN.git"},"dependencies":{},"devDependencies":{"nodemon":"^1.18.11"},"keywords":["KNN js","KNN for Javascript","KNN","K-NN","k-nearest neighbors algorithm","neighbors algorithm"],"author":{"name":"Hanor Sátiro Cintra"},"license":"MIT","bugs":{"url":"https://github.com/artificialscience/K-NN/issues"},"homepage":"https://github.com/artificialscience/K-NN#readme","gitHead":"c3fb370777107156545d0a6909b852df1a276834","_id":"@artificialscience/k-nn@1.0.1","_nodeVersion":"12.2.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-43NgFRW9tdBeol7qitVhDkWD+qZWFRIGyskQjeFZtCjnXdZl+uE0Zb1xoaLBBRO4DEzFgTzixs7GWfD9UCfNyQ==","shasum":"eb08952c063ff8633a3c54b15663b5a684f54a39","tarball":"https://registry.npmjs.org/@artificialscience/k-nn/-/k-nn-1.0.1.tgz","fileCount":7,"unpackedSize":107217,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc3h63CRA9TVsSAnZWagAA+9EQAIT7RbfFMchOsb9YlLYm\nUd1z9+hxmlPgd4jGgiTYqyUnJbX7g0htWYEq4LAFzMERVkfvOTvbX9fng8v+\n8hm0nipdIkeygrdDJyVybmbmhUjgUc8OZGVMSOfZR6gg77lX0KcPnU/zUVWf\nxF40X7xTrQshESr5Ekf2zoANHEHtGcm8N5SimurpE2ejwOErHCyj7FAlSocR\ndUhtEXEyPLIiuHDLIUWFs7wFfl5bu0tXgUFU5d/8raOfYVSwNpcvhZh7ShB2\nbC6WVNvmnGxfzsw0YCZmn2dD1Rr9a2el587URiOmyZzJFUdPsUVhVVNAUcJ9\nvzYVVodpF/PCtGjyevLScd7qyeC0r0SxzaCq6ctsGMVgCNgbkAehpVbJHUUt\nAMSzxLimsT5ceikaK3lfldocYTIZHS45TJRbQEC/HLxn4vUHM8IbAEArEh8L\ngUunqxFwwS+vGv1P0xzMSwBVKJie5JE3crT7nmKN8f3UKtnL/Ntr6JXooI7U\nymCDLURMLkdDlvgmRiIM64DlvFKUXLbuM4jWK9C2PnL8zoKMyU4o2DA2WkJx\n+oWeM/M7AmPxnvH6MUJ9RZL4MZPKeBvpHFPE9a5b4HTE+e5uPxk9eAc3MB9t\ns5ZxA2d668np7GCXIt068J/XQ+ZcwcZSeVydnKdaBQ4SBap437B18xP/5fq7\npDAd\r\n=OBYs\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBLDnjoD94KN37Xu2yWsIGnkEcpYeIqkb/CBgkwMtxdbAiEApi2eBKAOlDsTlbQZP4cWINwb73NBkLGGETrJJUBYeoc="}]},"maintainers":[{"name":"hanor","email":"hanor.cintra@outlook.com"}],"_npmUser":{"name":"hanor","email":"hanor.cintra@outlook.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/k-nn_1.0.1_1558060726678_0.5397041698921368"},"_hasShrinkwrap":false},"1.0.2":{"name":"@artificialscience/k-nn","version":"1.0.2","description":"A k-nearest neighbors algorithm implementation","main":"src/KNN.js","scripts":{"test":"nodemon --config nodemon.json --watch"},"repository":{"type":"git","url":"git+https://github.com/artificialscience/K-NN.git"},"dependencies":{},"devDependencies":{"nodemon":"^1.18.11"},"keywords":["KNN js","KNN for Javascript","KNN","K-NN","k-nearest neighbors algorithm","neighbors algorithm"],"author":{"name":"Hanor Sátiro Cintra"},"license":"MIT","bugs":{"url":"https://github.com/artificialscience/K-NN/issues"},"homepage":"https://github.com/artificialscience/K-NN#readme","gitHead":"0c88b91109760294e30cb4d9d820d2a795731116","_id":"@artificialscience/k-nn@1.0.2","_nodeVersion":"12.2.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-2wk5nqtnS/gL+xKRpJ7OlQLLovgUIiuoeodGymHd5VwvJSCq9BHUGSq3mMCU83TbeYPbMiNtdC6NBzwIrfDnGw==","shasum":"186fe419376a887c5cf9d063da58637bfb3069aa","tarball":"https://registry.npmjs.org/@artificialscience/k-nn/-/k-nn-1.0.2.tgz","fileCount":7,"unpackedSize":107229,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc3h+nCRA9TVsSAnZWagAAe6cP/RG3evw0PATykwzHPV5j\ngHLPmIY4XQXFBskRF5xDO6bux0hwdRbPFgRTvMuxjsmJTjfQvaCcO09W8cJi\nGVLiEKtqU2HHTEIxRKsYYgrCqERsapbDjw4nSQOY0OVNFxrvXffwq+94DFj1\n+SzDKhWw/preGkzWodgjxc/6g1mzuAq0oZQ6cP6nMHLE4gW/9bFY8XSaaILb\n8AW8mu/M/+fU/DwXXIvxcr4zbdW2K6YACzmkGT6GCpHkgU/x18m4v/SohQQa\nohTJ/yu+cvuAgJE+hvmgsX5zCyoM4l/Zv7s0NOezJv/0E8cwVnU2A/8wvCB+\nUdcl0HrPDH4VWPfLLAIIUg33adYwFdHR+YxQ9e58ou95pq/xwtyh4sTzTLzE\nAf0n00RfsLcbe3g/ErvY0QoaRgCYmlNJLhoWOR7Y9K9HbFXP9OldBCZnmsJ7\nPYDVOICC+ISr8CJ4EmiPVLI/wf2948UKi1PIJZpqtmmRPMdF3BfAtdGR1lcY\nwctTJ7ouf4xS4BWuLRsErN2t0M+yA30JnfdE1/wII13O3pUPlaS4cl+d3BV6\nIWK6TXG+pOUtst3UxtM/87eepi5Upg07Sehol80JcX5Uti7XOeuvhiTrUJPd\nnURqCyiGyxIC4gY8ZD34ZSWhk+m80IBz10tnSglgdr/r70/ls7yYh49C856K\n0WmQ\r\n=mQ6i\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDnly7PbdRmRgUqQNbj3mV8pi004ynu9DNPuA+YOjHOOwIgRA4klhGADwozc3UA4IxuYSOfqEcGkmVZK/rh/Ts+r8U="}]},"maintainers":[{"name":"hanor","email":"hanor.cintra@outlook.com"}],"_npmUser":{"name":"hanor","email":"hanor.cintra@outlook.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/k-nn_1.0.2_1558060966800_0.14455121759544842"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-17T02:34:32.933Z","1.0.0":"2019-05-17T02:34:33.342Z","modified":"2022-04-04T15:38:50.963Z","1.0.1":"2019-05-17T02:38:46.829Z","1.0.2":"2019-05-17T02:42:47.107Z"},"maintainers":[{"name":"hanor","email":"hanor.cintra@outlook.com"}],"description":"A k-nearest neighbors algorithm implementation","homepage":"https://github.com/artificialscience/K-NN#readme","keywords":["KNN js","KNN for Javascript","KNN","K-NN","k-nearest neighbors algorithm","neighbors algorithm"],"repository":{"type":"git","url":"git+https://github.com/artificialscience/K-NN.git"},"author":{"name":"Hanor Sátiro Cintra"},"bugs":{"url":"https://github.com/artificialscience/K-NN/issues"},"license":"MIT","readme":"# K-NN\r\n\r\nA k-nearest neighbors algorithm implementation for Javascript/Typescript\r\n\r\n# What this will do ?\r\n\r\nIn a data context this will classify a feature using a dataset of features, that is a prediction.\r\n\r\n## How it works ?\r\n\r\nBy default the algorithm will use K as 1, the last index of the feature array as the goal besides that you should give the dimension as parameter in the constructor. Remember the features is array of array and if the dimension is more than 3 you need to give a custom implementation of distance calculator.\r\n\r\n### The predict method will:\r\n\r\n    1 - Will calculate all the distances between the points of the features and the prediction feature;\r\n    2 - Will create an array with the calculated distances and your respective goals (point);\r\n    3 - Will sort the array created in step 2 in crescent mode then will slice using the K (if you not train, the K is equal to 1);\r\n    4 - For the most frequency, return the goal;\r\n\r\n    Remember in this predict method the feature to predict, should not have the goal. Because the goal is the objective to predict.\r\n\r\n### The traning method will:\r\n\r\n    1 - Will normalize the array with min and max if normalize equals a true;\r\n    2 - Will create an array shuffling the features then will split the data into traning set and test set, using for that the parameters testSize shuffleTimes and the features to train;\r\n    3 - For k times (a parameter of this method) and for every test set will predict and compare the actual goal with the prediction goal to calculte the accuracy;\r\n    4 - Return the best accuracy found and your respective K;\r\n\r\n# Installing\r\n\r\n`npm install @artificialscience/k-nn`\r\n\r\n## Using\r\n\r\nFor ESM 6\r\n\r\n    import * as KNN from '@artificialscience/k-nn';\r\nOr\r\n\r\n    const KNN = require('@artificialscience/k-nn');\r\n\r\n## An Example for 3 Dimension\r\n\r\n    /*\r\n    * Note: by default, the algorithm will consider the last index and will use\r\n    * the dimension passed in KNN constructor as the size of variables to use on the distance\r\n    * calculator that is the first 3(for this example: new KNN(3) variables in every row on \r\n    * the features.\r\n    */\r\n    const features = [\r\n        [10, 0.5068958512233102, 16, 1],\r\n        [12, 0.5105356367730379, 16, 7],\r\n        [12, 0.5323562633463617, 16, 7],\r\n        [40, 0.517546804614676, 16, 2],\r\n        [48, 0.5158030616769878, 16, 2],\r\n        [83, 0.5262942735596369, 16, 6],\r\n        [80, 0.5362942735596369, 16, 6],\r\n        [97, 0.5281527464327415, 16, 5],\r\n        [98, 0.5148717143151224, 16, 5],\r\n        [99, 0.5248717143151224, 16, 5],\r\n        [100, 0.5148717143151224, 16, 5],\r\n        [98, 0.5448717143151224, 16, 5],\r\n        [98, 0.5648717143151224, 16, 5],\r\n        [94, 0.5148717143151224, 16, 5],\r\n        [98, 0.52148717143151224, 16, 5]\r\n    ];\r\n    const knn = new KNN(3);\r\n    let [accuracy, k] = knn.training(features, 4, features.length, 2, true);\r\n    let goal = knn.predict(features, [100, 0.53, 16]);\r\n    console.log('Accuracy about: ' + accuracy + ', was predicted the goal as: ' + goal);\r\n\r\n# Examples\r\n\r\nYou can see some examples in ./test/main.js\r\n\r\n# Customization\r\n\r\nThis algorithm supports some customizating like: \r\n\r\n## DistanceFunction\r\n\r\nWill calculate the distance beetween 2 points, by default the implementation for 2d and 3d dimension will use pytagoras theorem. You can create a custom function to do that passing in the constructor or using the set method fot that. \r\n\r\n## GoalFunction\r\n\r\nThe goal function will return the goal of the calculated distance, represents basically the goal. The default implementation will assume the last position in a feature as the goal.\r\n\r\n# License\r\n\r\n MIT License\r\n\r\nCopyright (c) 2019 artificialscience\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.\r\n","readmeFilename":"README.md"}