{"action":"created","comment":{"url":"https://api.github.com/repos/vseloved/prj-algo2/pulls/comments/92165738","pull_request_review_id":12674769,"id":92165738,"diff_hunk":"@@ -0,0 +1,111 @@\n+import shuffle from 'shuffle-array';\n+import request from 'request';\n+\n+let dist = (v1, v2) => {\n+    let sum = 0;\n+\n+    v1.forEach((val, index) => {\n+        sum += (val - v2[index]) ** 2;\n+    });\n+\n+    return Math.sqrt(sum);\n+};\n+\n+let updateMax = (val, arr) => {\n+    let max = 0;\n+\n+    arr.forEach(obj => {\n+        max = Math.max(max, obj.d);\n+    });\n+\n+    return max;\n+};\n+\n+function mode(store) {\n+    let frequency = {};\n+    let max = 0;\n+    let result;\n+\n+    for (let v in store) {\n+        frequency[store[v]] = (frequency[store[v]] || 0) + 1;\n+\n+        if (frequency[store[v]] > max) {\n+            max = frequency[store[v]];\n+            result = store[v];\n+        }\n+    }\n+\n+    return result;\n+}\n+\n+let kNear = function (k) {\n+    let training = [];\n+\n+    this.learn = (vector, label) => {\n+        let obj = {\n+            v: vector,\n+            lab: label\n+        };\n+\n+        training.push(obj);\n+    };\n+\n+    this.classify = v => {\n+        let voteBloc = [];\n+        let maxD = 0;\n+\n+        training.forEach(obj => {\n+            let o = {\n+                d: dist(v, obj.v),\n+                vote: obj.lab\n+            };\n+\n+            if (voteBloc.length < k) {\n+                voteBloc.push(o);\n+                maxD = updateMax(maxD, voteBloc);\n+            } else if (o.d < maxD) {\n+                let bool = true;\n+                let count = 0;\n+\n+                while (bool) {\n+                    if (Number(voteBloc[count].d) === maxD) {\n+                        voteBloc.splice(count, 1, o);\n+                        maxD = updateMax(maxD, voteBloc);\n+                        bool = false;\n+                    } else if (count < voteBloc.length - 1) {\n+                        count++;\n+                    } else {\n+                        bool = false;\n+                    }\n+                }\n+            }\n+        });\n+\n+        let votes = [];\n+\n+        voteBloc.forEach(el => {\n+            votes.push(el.vote);\n+        });\n+\n+        return mode(votes);\n+    };\n+};\n+\n+request.get('https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data', (error, response, body) => {\n+    if (!error && response.statusCode == 200) {\n+        let csv = body;\n+        let k = 3;\n+        let machine = new kNear(k);\n+        let csvStrings = shuffle(csv.split('\\n'));\n+\n+        for (let i = 0; i < csvStrings.length; i++) {\n+            let strArr = csvStrings[i].split(',');\n+\n+            if (i < 100) {\n+                machine.learn([+strArr[0], +strArr[1], +strArr[2], +strArr[3]], strArr[4]);\n+            } else {\n+                console.log(machine.classify([+strArr[0], +strArr[1], +strArr[2], +strArr[3]]));\n+            }\n+        }\n+    }\n+});","path":"tasks/programulya/19/knn.js","position":111,"original_position":111,"commit_id":"e750899c568ba69fbffe3afb1e701217a23b99ad","original_commit_id":"e750899c568ba69fbffe3afb1e701217a23b99ad","user":{"login":"programulya","id":2372431,"avatar_url":"https://avatars.githubusercontent.com/u/2372431?v=3","gravatar_id":"","url":"https://api.github.com/users/programulya","html_url":"https://github.com/programulya","followers_url":"https://api.github.com/users/programulya/followers","following_url":"https://api.github.com/users/programulya/following{/other_user}","gists_url":"https://api.github.com/users/programulya/gists{/gist_id}","starred_url":"https://api.github.com/users/programulya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/programulya/subscriptions","organizations_url":"https://api.github.com/users/programulya/orgs","repos_url":"https://api.github.com/users/programulya/repos","events_url":"https://api.github.com/users/programulya/events{/privacy}","received_events_url":"https://api.github.com/users/programulya/received_events","type":"User","site_admin":false},"body":"да-да, я забыла её добавить, спасибо","created_at":"2016-12-13T13:17:07Z","updated_at":"2016-12-13T13:17:07Z","html_url":"https://github.com/vseloved/prj-algo2/pull/36#discussion_r92165738","pull_request_url":"https://api.github.com/repos/vseloved/prj-algo2/pulls/36","_links":{"self":{"href":"https://api.github.com/repos/vseloved/prj-algo2/pulls/comments/92165738"},"html":{"href":"https://github.com/vseloved/prj-algo2/pull/36#discussion_r92165738"},"pull_request":{"href":"https://api.github.com/repos/vseloved/prj-algo2/pulls/36"}}},"pull_request":{"url":"https://api.github.com/repos/vseloved/prj-algo2/pulls/36","id":97463305,"html_url":"https://github.com/vseloved/prj-algo2/pull/36","diff_url":"https://github.com/vseloved/prj-algo2/pull/36.diff","patch_url":"https://github.com/vseloved/prj-algo2/pull/36.patch","issue_url":"https://api.github.com/repos/vseloved/prj-algo2/issues/36","number":36,"state":"closed","locked":false,"title":"Add Kruskal algorithm, binary heap, KNN","user":{"login":"programulya","id":2372431,"avatar_url":"https://avatars.githubusercontent.com/u/2372431?v=3","gravatar_id":"","url":"https://api.github.com/users/programulya","html_url":"https://github.com/programulya","followers_url":"https://api.github.com/users/programulya/followers","following_url":"https://api.github.com/users/programulya/following{/other_user}","gists_url":"https://api.github.com/users/programulya/gists{/gist_id}","starred_url":"https://api.github.com/users/programulya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/programulya/subscriptions","organizations_url":"https://api.github.com/users/programulya/orgs","repos_url":"https://api.github.com/users/programulya/repos","events_url":"https://api.github.com/users/programulya/events{/privacy}","received_events_url":"https://api.github.com/users/programulya/received_events","type":"User","site_admin":false},"body":"Add Kruskal algorithm, binary heap, KNN","created_at":"2016-12-11T16:06:28Z","updated_at":"2016-12-13T13:17:07Z","closed_at":"2016-12-12T12:10:12Z","merged_at":"2016-12-12T12:10:12Z","merge_commit_sha":"e8ad2a9385ef084bf9b95d69b25701bfea0e36ce","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/vseloved/prj-algo2/pulls/36/commits","review_comments_url":"https://api.github.com/repos/vseloved/prj-algo2/pulls/36/comments","review_comment_url":"https://api.github.com/repos/vseloved/prj-algo2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/vseloved/prj-algo2/issues/36/comments","statuses_url":"https://api.github.com/repos/vseloved/prj-algo2/statuses/e750899c568ba69fbffe3afb1e701217a23b99ad","head":{"label":"programulya:master","ref":"master","sha":"e750899c568ba69fbffe3afb1e701217a23b99ad","user":{"login":"programulya","id":2372431,"avatar_url":"https://avatars.githubusercontent.com/u/2372431?v=3","gravatar_id":"","url":"https://api.github.com/users/programulya","html_url":"https://github.com/programulya","followers_url":"https://api.github.com/users/programulya/followers","following_url":"https://api.github.com/users/programulya/following{/other_user}","gists_url":"https://api.github.com/users/programulya/gists{/gist_id}","starred_url":"https://api.github.com/users/programulya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/programulya/subscriptions","organizations_url":"https://api.github.com/users/programulya/orgs","repos_url":"https://api.github.com/users/programulya/repos","events_url":"https://api.github.com/users/programulya/events{/privacy}","received_events_url":"https://api.github.com/users/programulya/received_events","type":"User","site_admin":false},"repo":{"id":69810975,"name":"prj-algo2","full_name":"programulya/prj-algo2","owner":{"login":"programulya","id":2372431,"avatar_url":"https://avatars.githubusercontent.com/u/2372431?v=3","gravatar_id":"","url":"https://api.github.com/users/programulya","html_url":"https://github.com/programulya","followers_url":"https://api.github.com/users/programulya/followers","following_url":"https://api.github.com/users/programulya/following{/other_user}","gists_url":"https://api.github.com/users/programulya/gists{/gist_id}","starred_url":"https://api.github.com/users/programulya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/programulya/subscriptions","organizations_url":"https://api.github.com/users/programulya/orgs","repos_url":"https://api.github.com/users/programulya/repos","events_url":"https://api.github.com/users/programulya/events{/privacy}","received_events_url":"https://api.github.com/users/programulya/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/programulya/prj-algo2","description":null,"fork":true,"url":"https://api.github.com/repos/programulya/prj-algo2","forks_url":"https://api.github.com/repos/programulya/prj-algo2/forks","keys_url":"https://api.github.com/repos/programulya/prj-algo2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/programulya/prj-algo2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/programulya/prj-algo2/teams","hooks_url":"https://api.github.com/repos/programulya/prj-algo2/hooks","issue_events_url":"https://api.github.com/repos/programulya/prj-algo2/issues/events{/number}","events_url":"https://api.github.com/repos/programulya/prj-algo2/events","assignees_url":"https://api.github.com/repos/programulya/prj-algo2/assignees{/user}","branches_url":"https://api.github.com/repos/programulya/prj-algo2/branches{/branch}","tags_url":"https://api.github.com/repos/programulya/prj-algo2/tags","blobs_url":"https://api.github.com/repos/programulya/prj-algo2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/programulya/prj-algo2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/programulya/prj-algo2/git/refs{/sha}","trees_url":"https://api.github.com/repos/programulya/prj-algo2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/programulya/prj-algo2/statuses/{sha}","languages_url":"https://api.github.com/repos/programulya/prj-algo2/languages","stargazers_url":"https://api.github.com/repos/programulya/prj-algo2/stargazers","contributors_url":"https://api.github.com/repos/programulya/prj-algo2/contributors","subscribers_url":"https://api.github.com/repos/programulya/prj-algo2/subscribers","subscription_url":"https://api.github.com/repos/programulya/prj-algo2/subscription","commits_url":"https://api.github.com/repos/programulya/prj-algo2/commits{/sha}","git_commits_url":"https://api.github.com/repos/programulya/prj-algo2/git/commits{/sha}","comments_url":"https://api.github.com/repos/programulya/prj-algo2/comments{/number}","issue_comment_url":"https://api.github.com/repos/programulya/prj-algo2/issues/comments{/number}","contents_url":"https://api.github.com/repos/programulya/prj-algo2/contents/{+path}","compare_url":"https://api.github.com/repos/programulya/prj-algo2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/programulya/prj-algo2/merges","archive_url":"https://api.github.com/repos/programulya/prj-algo2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/programulya/prj-algo2/downloads","issues_url":"https://api.github.com/repos/programulya/prj-algo2/issues{/number}","pulls_url":"https://api.github.com/repos/programulya/prj-algo2/pulls{/number}","milestones_url":"https://api.github.com/repos/programulya/prj-algo2/milestones{/number}","notifications_url":"https://api.github.com/repos/programulya/prj-algo2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/programulya/prj-algo2/labels{/name}","releases_url":"https://api.github.com/repos/programulya/prj-algo2/releases{/id}","deployments_url":"https://api.github.com/repos/programulya/prj-algo2/deployments","created_at":"2016-10-02T17:25:29Z","updated_at":"2016-11-05T15:19:38Z","pushed_at":"2016-12-11T16:05:18Z","git_url":"git://github.com/programulya/prj-algo2.git","ssh_url":"git@github.com:programulya/prj-algo2.git","clone_url":"https://github.com/programulya/prj-algo2.git","svn_url":"https://github.com/programulya/prj-algo2","homepage":null,"size":2534,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"vseloved:master","ref":"master","sha":"68b5f08233f91f30f997efdd360381d8f140c095","user":{"login":"vseloved","id":126027,"avatar_url":"https://avatars.githubusercontent.com/u/126027?v=3","gravatar_id":"","url":"https://api.github.com/users/vseloved","html_url":"https://github.com/vseloved","followers_url":"https://api.github.com/users/vseloved/followers","following_url":"https://api.github.com/users/vseloved/following{/other_user}","gists_url":"https://api.github.com/users/vseloved/gists{/gist_id}","starred_url":"https://api.github.com/users/vseloved/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vseloved/subscriptions","organizations_url":"https://api.github.com/users/vseloved/orgs","repos_url":"https://api.github.com/users/vseloved/repos","events_url":"https://api.github.com/users/vseloved/events{/privacy}","received_events_url":"https://api.github.com/users/vseloved/received_events","type":"User","site_admin":false},"repo":{"id":68901259,"name":"prj-algo2","full_name":"vseloved/prj-algo2","owner":{"login":"vseloved","id":126027,"avatar_url":"https://avatars.githubusercontent.com/u/126027?v=3","gravatar_id":"","url":"https://api.github.com/users/vseloved","html_url":"https://github.com/vseloved","followers_url":"https://api.github.com/users/vseloved/followers","following_url":"https://api.github.com/users/vseloved/following{/other_user}","gists_url":"https://api.github.com/users/vseloved/gists{/gist_id}","starred_url":"https://api.github.com/users/vseloved/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vseloved/subscriptions","organizations_url":"https://api.github.com/users/vseloved/orgs","repos_url":"https://api.github.com/users/vseloved/repos","events_url":"https://api.github.com/users/vseloved/events{/privacy}","received_events_url":"https://api.github.com/users/vseloved/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vseloved/prj-algo2","description":null,"fork":false,"url":"https://api.github.com/repos/vseloved/prj-algo2","forks_url":"https://api.github.com/repos/vseloved/prj-algo2/forks","keys_url":"https://api.github.com/repos/vseloved/prj-algo2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vseloved/prj-algo2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vseloved/prj-algo2/teams","hooks_url":"https://api.github.com/repos/vseloved/prj-algo2/hooks","issue_events_url":"https://api.github.com/repos/vseloved/prj-algo2/issues/events{/number}","events_url":"https://api.github.com/repos/vseloved/prj-algo2/events","assignees_url":"https://api.github.com/repos/vseloved/prj-algo2/assignees{/user}","branches_url":"https://api.github.com/repos/vseloved/prj-algo2/branches{/branch}","tags_url":"https://api.github.com/repos/vseloved/prj-algo2/tags","blobs_url":"https://api.github.com/repos/vseloved/prj-algo2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vseloved/prj-algo2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vseloved/prj-algo2/git/refs{/sha}","trees_url":"https://api.github.com/repos/vseloved/prj-algo2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vseloved/prj-algo2/statuses/{sha}","languages_url":"https://api.github.com/repos/vseloved/prj-algo2/languages","stargazers_url":"https://api.github.com/repos/vseloved/prj-algo2/stargazers","contributors_url":"https://api.github.com/repos/vseloved/prj-algo2/contributors","subscribers_url":"https://api.github.com/repos/vseloved/prj-algo2/subscribers","subscription_url":"https://api.github.com/repos/vseloved/prj-algo2/subscription","commits_url":"https://api.github.com/repos/vseloved/prj-algo2/commits{/sha}","git_commits_url":"https://api.github.com/repos/vseloved/prj-algo2/git/commits{/sha}","comments_url":"https://api.github.com/repos/vseloved/prj-algo2/comments{/number}","issue_comment_url":"https://api.github.com/repos/vseloved/prj-algo2/issues/comments{/number}","contents_url":"https://api.github.com/repos/vseloved/prj-algo2/contents/{+path}","compare_url":"https://api.github.com/repos/vseloved/prj-algo2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vseloved/prj-algo2/merges","archive_url":"https://api.github.com/repos/vseloved/prj-algo2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vseloved/prj-algo2/downloads","issues_url":"https://api.github.com/repos/vseloved/prj-algo2/issues{/number}","pulls_url":"https://api.github.com/repos/vseloved/prj-algo2/pulls{/number}","milestones_url":"https://api.github.com/repos/vseloved/prj-algo2/milestones{/number}","notifications_url":"https://api.github.com/repos/vseloved/prj-algo2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vseloved/prj-algo2/labels{/name}","releases_url":"https://api.github.com/repos/vseloved/prj-algo2/releases{/id}","deployments_url":"https://api.github.com/repos/vseloved/prj-algo2/deployments","created_at":"2016-09-22T08:32:59Z","updated_at":"2016-10-24T15:25:28Z","pushed_at":"2016-12-12T12:10:12Z","git_url":"git://github.com/vseloved/prj-algo2.git","ssh_url":"git@github.com:vseloved/prj-algo2.git","clone_url":"https://github.com/vseloved/prj-algo2.git","svn_url":"https://github.com/vseloved/prj-algo2","homepage":null,"size":2605,"stargazers_count":6,"watchers_count":6,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":2,"forks":15,"open_issues":2,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/vseloved/prj-algo2/pulls/36"},"html":{"href":"https://github.com/vseloved/prj-algo2/pull/36"},"issue":{"href":"https://api.github.com/repos/vseloved/prj-algo2/issues/36"},"comments":{"href":"https://api.github.com/repos/vseloved/prj-algo2/issues/36/comments"},"review_comments":{"href":"https://api.github.com/repos/vseloved/prj-algo2/pulls/36/comments"},"review_comment":{"href":"https://api.github.com/repos/vseloved/prj-algo2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/vseloved/prj-algo2/pulls/36/commits"},"statuses":{"href":"https://api.github.com/repos/vseloved/prj-algo2/statuses/e750899c568ba69fbffe3afb1e701217a23b99ad"}}}}
{"actor":{"display_login":"programulya"}}