{"action":"created","comment":{"url":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/comments/273221182","pull_request_review_id":224064693,"id":273221182,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI3MzIyMTE4Mg==","diff_hunk":"@@ -445,62 +454,124 @@ def predict(self, array):\n             array (ndarray): numeric array comprised of N records.\n \n         Returns:\n-            DataFrame: Nx2 array where column 1 and 2 is depth and score.\n+            out: array that contains the `id`, `score`, and `depth` per record.\n         \"\"\"\n-        data = pd.DataFrame(array)\n+        data, mapping = preprocess(array)\n+\n+        # if an ndarray or DataFrame lacking index-name is given, set index name\n+        if data.index.names == [None]:\n+            data.index.names = [\"id\"]\n \n         # for keeping track of anomaly scores\n-        scores = []\n+        out = []\n \n         # generate an anomaly score for each row in the dataset, array\n-        for i in range(len(data)):\n+        for ix, row in data.iterrows():\n \n             # for each record, i, find out its depth in each tree, j\n             depth = 0\n             for j in range(self.num_trees):\n-                depth += float(TreeScore(data.values[i], self.trees[j]).path)\n+                depth += float(TreeScore(row.values, self.trees[j]).path)\n \n             # scale the depth by the total number of trees\n             depth_scaled = depth / self.num_trees\n \n             # output a `score` and `depth` per record\n             score = s(depth_scaled, self.sample_size)\n-            scores.append([score, depth_scaled])\n \n-        # return anomaly score and depth for each record\n-        out = pd.DataFrame(scores,\n-                           index=data.index,\n-                           columns=[\"score\", \"depth\"])\n+            # each record (row) has a score and depth\n+            record = {\"score\": score,\n+                      \"depth\": depth_scaled,\n+                      \"is_anomalous\": bool(score > .5)}\n \n-        # sort by score so that dissemination can be easier\n-        return out.sort_values(\"score\", ascending=False)\n+            # if the index is a MultiIndex each index name index value\n+            if isinstance(ix, (tuple, list)):\n+                record.update(zip(data.index.names, ix))\n \n-    def contrast(self, array, min_score=0.55):\n+            # otherwise, the index is just an Index, so map this one name\n+            else:\n+                record.update({data.index.name: ix})\n+\n+            # create a centralized data-structure to feed into json.dumps(...)\n+            out.append(record)\n+        self.predictions = out\n+        return self.predictions\n+\n+    def to_report(self):\n+\n+        # read-in predictions as a pandas DataFrame\n+        frame = pd.DataFrame.from_records(self.predictions)\n+        dic = {}\n+\n+        # determine those deemed anomalous from normal\n+        normal = frame[~frame[\"is_anomalous\"]][\"score\"]\n+        anomalies = frame[frame[\"is_anomalous\"]][\"score\"]\n+\n+        # figure 1 - a boxplot of anomaly score distributions\n+        plt.clf()","path":"rad/rad.py","position":310,"original_position":310,"commit_id":"e1d860c49de031247e25594c6b00a6ff7205596f","original_commit_id":"e1d860c49de031247e25594c6b00a6ff7205596f","user":{"login":"jameswnl","id":2421248,"node_id":"MDQ6VXNlcjI0MjEyNDg=","avatar_url":"https://avatars2.githubusercontent.com/u/2421248?v=4","gravatar_id":"","url":"https://api.github.com/users/jameswnl","html_url":"https://github.com/jameswnl","followers_url":"https://api.github.com/users/jameswnl/followers","following_url":"https://api.github.com/users/jameswnl/following{/other_user}","gists_url":"https://api.github.com/users/jameswnl/gists{/gist_id}","starred_url":"https://api.github.com/users/jameswnl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jameswnl/subscriptions","organizations_url":"https://api.github.com/users/jameswnl/orgs","repos_url":"https://api.github.com/users/jameswnl/repos","events_url":"https://api.github.com/users/jameswnl/events{/privacy}","received_events_url":"https://api.github.com/users/jameswnl/received_events","type":"User","site_admin":false},"body":"if `plt` is not available, can we fail it early on?","created_at":"2019-04-08T20:19:24Z","updated_at":"2019-04-08T20:19:31Z","html_url":"https://github.com/ManageIQ/aiops-rad/pull/5#discussion_r273221182","pull_request_url":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/5","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/comments/273221182"},"html":{"href":"https://github.com/ManageIQ/aiops-rad/pull/5#discussion_r273221182"},"pull_request":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/5","id":267198361,"node_id":"MDExOlB1bGxSZXF1ZXN0MjY3MTk4MzYx","html_url":"https://github.com/ManageIQ/aiops-rad/pull/5","diff_url":"https://github.com/ManageIQ/aiops-rad/pull/5.diff","patch_url":"https://github.com/ManageIQ/aiops-rad/pull/5.patch","issue_url":"https://api.github.com/repos/ManageIQ/aiops-rad/issues/5","number":5,"state":"open","locked":false,"title":"Isolationforest","user":{"login":"parsahosseini","id":44847666,"node_id":"MDQ6VXNlcjQ0ODQ3NjY2","avatar_url":"https://avatars3.githubusercontent.com/u/44847666?v=4","gravatar_id":"","url":"https://api.github.com/users/parsahosseini","html_url":"https://github.com/parsahosseini","followers_url":"https://api.github.com/users/parsahosseini/followers","following_url":"https://api.github.com/users/parsahosseini/following{/other_user}","gists_url":"https://api.github.com/users/parsahosseini/gists{/gist_id}","starred_url":"https://api.github.com/users/parsahosseini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parsahosseini/subscriptions","organizations_url":"https://api.github.com/users/parsahosseini/orgs","repos_url":"https://api.github.com/users/parsahosseini/repos","events_url":"https://api.github.com/users/parsahosseini/events{/privacy}","received_events_url":"https://api.github.com/users/parsahosseini/received_events","type":"User","site_admin":false},"body":"new use-cases for `IsolationTree` and a new `as_json` argument when `predict` is executed.","created_at":"2019-04-03T20:24:39Z","updated_at":"2019-04-08T20:19:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0c230f6b237e2da8c274358e85040973b5bc1c82","assignee":null,"assignees":[],"requested_reviewers":[{"login":"tumido","id":7453394,"node_id":"MDQ6VXNlcjc0NTMzOTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/7453394?v=4","gravatar_id":"","url":"https://api.github.com/users/tumido","html_url":"https://github.com/tumido","followers_url":"https://api.github.com/users/tumido/followers","following_url":"https://api.github.com/users/tumido/following{/other_user}","gists_url":"https://api.github.com/users/tumido/gists{/gist_id}","starred_url":"https://api.github.com/users/tumido/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tumido/subscriptions","organizations_url":"https://api.github.com/users/tumido/orgs","repos_url":"https://api.github.com/users/tumido/repos","events_url":"https://api.github.com/users/tumido/events{/privacy}","received_events_url":"https://api.github.com/users/tumido/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":1292527447,"node_id":"MDU6TGFiZWwxMjkyNTI3NDQ3","url":"https://api.github.com/repos/ManageIQ/aiops-rad/labels/enhancement","name":"enhancement","color":"a2eeef","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/5/commits","review_comments_url":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/5/comments","review_comment_url":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ManageIQ/aiops-rad/issues/5/comments","statuses_url":"https://api.github.com/repos/ManageIQ/aiops-rad/statuses/e1d860c49de031247e25594c6b00a6ff7205596f","head":{"label":"parsahosseini:isolationforest","ref":"isolationforest","sha":"e1d860c49de031247e25594c6b00a6ff7205596f","user":{"login":"parsahosseini","id":44847666,"node_id":"MDQ6VXNlcjQ0ODQ3NjY2","avatar_url":"https://avatars3.githubusercontent.com/u/44847666?v=4","gravatar_id":"","url":"https://api.github.com/users/parsahosseini","html_url":"https://github.com/parsahosseini","followers_url":"https://api.github.com/users/parsahosseini/followers","following_url":"https://api.github.com/users/parsahosseini/following{/other_user}","gists_url":"https://api.github.com/users/parsahosseini/gists{/gist_id}","starred_url":"https://api.github.com/users/parsahosseini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parsahosseini/subscriptions","organizations_url":"https://api.github.com/users/parsahosseini/orgs","repos_url":"https://api.github.com/users/parsahosseini/repos","events_url":"https://api.github.com/users/parsahosseini/events{/privacy}","received_events_url":"https://api.github.com/users/parsahosseini/received_events","type":"User","site_admin":false},"repo":{"id":178907955,"node_id":"MDEwOlJlcG9zaXRvcnkxNzg5MDc5NTU=","name":"aiops-rad","full_name":"parsahosseini/aiops-rad","private":false,"owner":{"login":"parsahosseini","id":44847666,"node_id":"MDQ6VXNlcjQ0ODQ3NjY2","avatar_url":"https://avatars3.githubusercontent.com/u/44847666?v=4","gravatar_id":"","url":"https://api.github.com/users/parsahosseini","html_url":"https://github.com/parsahosseini","followers_url":"https://api.github.com/users/parsahosseini/followers","following_url":"https://api.github.com/users/parsahosseini/following{/other_user}","gists_url":"https://api.github.com/users/parsahosseini/gists{/gist_id}","starred_url":"https://api.github.com/users/parsahosseini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parsahosseini/subscriptions","organizations_url":"https://api.github.com/users/parsahosseini/orgs","repos_url":"https://api.github.com/users/parsahosseini/repos","events_url":"https://api.github.com/users/parsahosseini/events{/privacy}","received_events_url":"https://api.github.com/users/parsahosseini/received_events","type":"User","site_admin":false},"html_url":"https://github.com/parsahosseini/aiops-rad","description":"AI-Ops Red Hat Anomaly Detection (RAD)","fork":true,"url":"https://api.github.com/repos/parsahosseini/aiops-rad","forks_url":"https://api.github.com/repos/parsahosseini/aiops-rad/forks","keys_url":"https://api.github.com/repos/parsahosseini/aiops-rad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/parsahosseini/aiops-rad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/parsahosseini/aiops-rad/teams","hooks_url":"https://api.github.com/repos/parsahosseini/aiops-rad/hooks","issue_events_url":"https://api.github.com/repos/parsahosseini/aiops-rad/issues/events{/number}","events_url":"https://api.github.com/repos/parsahosseini/aiops-rad/events","assignees_url":"https://api.github.com/repos/parsahosseini/aiops-rad/assignees{/user}","branches_url":"https://api.github.com/repos/parsahosseini/aiops-rad/branches{/branch}","tags_url":"https://api.github.com/repos/parsahosseini/aiops-rad/tags","blobs_url":"https://api.github.com/repos/parsahosseini/aiops-rad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/parsahosseini/aiops-rad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/parsahosseini/aiops-rad/git/refs{/sha}","trees_url":"https://api.github.com/repos/parsahosseini/aiops-rad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/parsahosseini/aiops-rad/statuses/{sha}","languages_url":"https://api.github.com/repos/parsahosseini/aiops-rad/languages","stargazers_url":"https://api.github.com/repos/parsahosseini/aiops-rad/stargazers","contributors_url":"https://api.github.com/repos/parsahosseini/aiops-rad/contributors","subscribers_url":"https://api.github.com/repos/parsahosseini/aiops-rad/subscribers","subscription_url":"https://api.github.com/repos/parsahosseini/aiops-rad/subscription","commits_url":"https://api.github.com/repos/parsahosseini/aiops-rad/commits{/sha}","git_commits_url":"https://api.github.com/repos/parsahosseini/aiops-rad/git/commits{/sha}","comments_url":"https://api.github.com/repos/parsahosseini/aiops-rad/comments{/number}","issue_comment_url":"https://api.github.com/repos/parsahosseini/aiops-rad/issues/comments{/number}","contents_url":"https://api.github.com/repos/parsahosseini/aiops-rad/contents/{+path}","compare_url":"https://api.github.com/repos/parsahosseini/aiops-rad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/parsahosseini/aiops-rad/merges","archive_url":"https://api.github.com/repos/parsahosseini/aiops-rad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/parsahosseini/aiops-rad/downloads","issues_url":"https://api.github.com/repos/parsahosseini/aiops-rad/issues{/number}","pulls_url":"https://api.github.com/repos/parsahosseini/aiops-rad/pulls{/number}","milestones_url":"https://api.github.com/repos/parsahosseini/aiops-rad/milestones{/number}","notifications_url":"https://api.github.com/repos/parsahosseini/aiops-rad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/parsahosseini/aiops-rad/labels{/name}","releases_url":"https://api.github.com/repos/parsahosseini/aiops-rad/releases{/id}","deployments_url":"https://api.github.com/repos/parsahosseini/aiops-rad/deployments","created_at":"2019-04-01T16:55:25Z","updated_at":"2019-04-03T22:41:03Z","pushed_at":"2019-04-08T19:41:23Z","git_url":"git://github.com/parsahosseini/aiops-rad.git","ssh_url":"git@github.com:parsahosseini/aiops-rad.git","clone_url":"https://github.com/parsahosseini/aiops-rad.git","svn_url":"https://github.com/parsahosseini/aiops-rad","homepage":"","size":30,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ManageIQ:master","ref":"master","sha":"57459c89ec637dbc8eca1f2a11b6ec65de06da25","user":{"login":"ManageIQ","id":1125575,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjU1NzU=","avatar_url":"https://avatars0.githubusercontent.com/u/1125575?v=4","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"repo":{"id":178061358,"node_id":"MDEwOlJlcG9zaXRvcnkxNzgwNjEzNTg=","name":"aiops-rad","full_name":"ManageIQ/aiops-rad","private":false,"owner":{"login":"ManageIQ","id":1125575,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjU1NzU=","avatar_url":"https://avatars0.githubusercontent.com/u/1125575?v=4","gravatar_id":"","url":"https://api.github.com/users/ManageIQ","html_url":"https://github.com/ManageIQ","followers_url":"https://api.github.com/users/ManageIQ/followers","following_url":"https://api.github.com/users/ManageIQ/following{/other_user}","gists_url":"https://api.github.com/users/ManageIQ/gists{/gist_id}","starred_url":"https://api.github.com/users/ManageIQ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManageIQ/subscriptions","organizations_url":"https://api.github.com/users/ManageIQ/orgs","repos_url":"https://api.github.com/users/ManageIQ/repos","events_url":"https://api.github.com/users/ManageIQ/events{/privacy}","received_events_url":"https://api.github.com/users/ManageIQ/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/ManageIQ/aiops-rad","description":"AI-Ops Red Hat Anomaly Detection (RAD)","fork":false,"url":"https://api.github.com/repos/ManageIQ/aiops-rad","forks_url":"https://api.github.com/repos/ManageIQ/aiops-rad/forks","keys_url":"https://api.github.com/repos/ManageIQ/aiops-rad/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ManageIQ/aiops-rad/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ManageIQ/aiops-rad/teams","hooks_url":"https://api.github.com/repos/ManageIQ/aiops-rad/hooks","issue_events_url":"https://api.github.com/repos/ManageIQ/aiops-rad/issues/events{/number}","events_url":"https://api.github.com/repos/ManageIQ/aiops-rad/events","assignees_url":"https://api.github.com/repos/ManageIQ/aiops-rad/assignees{/user}","branches_url":"https://api.github.com/repos/ManageIQ/aiops-rad/branches{/branch}","tags_url":"https://api.github.com/repos/ManageIQ/aiops-rad/tags","blobs_url":"https://api.github.com/repos/ManageIQ/aiops-rad/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ManageIQ/aiops-rad/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ManageIQ/aiops-rad/git/refs{/sha}","trees_url":"https://api.github.com/repos/ManageIQ/aiops-rad/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ManageIQ/aiops-rad/statuses/{sha}","languages_url":"https://api.github.com/repos/ManageIQ/aiops-rad/languages","stargazers_url":"https://api.github.com/repos/ManageIQ/aiops-rad/stargazers","contributors_url":"https://api.github.com/repos/ManageIQ/aiops-rad/contributors","subscribers_url":"https://api.github.com/repos/ManageIQ/aiops-rad/subscribers","subscription_url":"https://api.github.com/repos/ManageIQ/aiops-rad/subscription","commits_url":"https://api.github.com/repos/ManageIQ/aiops-rad/commits{/sha}","git_commits_url":"https://api.github.com/repos/ManageIQ/aiops-rad/git/commits{/sha}","comments_url":"https://api.github.com/repos/ManageIQ/aiops-rad/comments{/number}","issue_comment_url":"https://api.github.com/repos/ManageIQ/aiops-rad/issues/comments{/number}","contents_url":"https://api.github.com/repos/ManageIQ/aiops-rad/contents/{+path}","compare_url":"https://api.github.com/repos/ManageIQ/aiops-rad/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ManageIQ/aiops-rad/merges","archive_url":"https://api.github.com/repos/ManageIQ/aiops-rad/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ManageIQ/aiops-rad/downloads","issues_url":"https://api.github.com/repos/ManageIQ/aiops-rad/issues{/number}","pulls_url":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls{/number}","milestones_url":"https://api.github.com/repos/ManageIQ/aiops-rad/milestones{/number}","notifications_url":"https://api.github.com/repos/ManageIQ/aiops-rad/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ManageIQ/aiops-rad/labels{/name}","releases_url":"https://api.github.com/repos/ManageIQ/aiops-rad/releases{/id}","deployments_url":"https://api.github.com/repos/ManageIQ/aiops-rad/deployments","created_at":"2019-03-27T19:28:46Z","updated_at":"2019-04-03T13:20:55Z","pushed_at":"2019-04-08T19:41:25Z","git_url":"git://github.com/ManageIQ/aiops-rad.git","ssh_url":"git@github.com:ManageIQ/aiops-rad.git","clone_url":"https://github.com/ManageIQ/aiops-rad.git","svn_url":"https://github.com/ManageIQ/aiops-rad","homepage":"","size":22,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":null,"forks":3,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/5"},"html":{"href":"https://github.com/ManageIQ/aiops-rad/pull/5"},"issue":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/issues/5"},"comments":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/ManageIQ/aiops-rad/statuses/e1d860c49de031247e25594c6b00a6ff7205596f"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"jameswnl"}}