{"action":"created","comment":{"url":"https://api.github.com/repos/aldro61/mmit/pulls/comments/197473090","pull_request_review_id":131228748,"id":197473090,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NzQ3MzA5MA==","diff_hunk":"@@ -0,0 +1,191 @@\n+fit_and_score <- structure(function(tree, target.mat, feature.mat, \n+                                    parameters, feature_names=NULL, \n+                                    n_folds = 3, scorer=NULL, loss = \"hinge\",\n+                                    pruning = TRUE){\n+  ### total length\n+  l <- length(target.mat[, 1])\n+  \n+  ### train and test index for each fold\n+  fold_split_idx <- NULL\n+  \n+  ### initial row\n+  fold_split_idx$train <- seq(from = 1, to = ((l/n_folds)*(n_folds-1)), by = 1)\n+  fold_split_idx$test <- seq(from = ((l/n_folds)*(n_folds-1)) + 1, to = l, by = 1)\n+  \n+  ### middle values\n+  for(n in (n_folds-1):2){\n+    this_row_train <- c(seq(from = 1, to = ((l/n_folds)*(n-1)), by = 1), seq(from = as.integer((l/n_folds)*(n)+1), to = l, by = 1))\n+    this_row_test <- seq(from = ((l/n_folds)*(n-1)) + 1, to = as.integer((l/n_folds)*(n)))\n+    \n+    fold_split_idx$train <- rbind(fold_split_idx$train, this_row_train)\n+    fold_split_idx$test <- rbind(fold_split_idx$test, this_row_test)\n+  }\n+  \n+  ### end row\n+  this_row_train <- seq(from = (as.integer((l/n_folds)+1)), to = l, by = 1)\n+  this_row_test <- seq(from = 1, to = as.integer((l/n_folds)), by = 1)\n+  \n+  fold_split_idx$train <- rbind(fold_split_idx$train, this_row_train)\n+  fold_split_idx$test <- rbind(fold_split_idx$test, this_row_test)\n+  \n+  ### fold trees\n+  fold_tree <- NULL\n+  for(i in 1:n_folds){\n+    fold_tree[[i]] <- mmit(target.mat[fold_split_idx$train[i,],], feature.mat[fold_split_idx$train[i,],],  \n+                                       maxdepth = as.numeric(parameters$maxdepth), margin = as.numeric(parameters$margin), \n+                                       loss = loss, min_sample = as.numeric(parameters$min_sample))\n+  }\n+  \n+  ### master tree\n+  master_tree <- mmit(target.mat, feature.mat,  \n+                      maxdepth = as.numeric(parameters$maxdepth), margin = as.numeric(parameters$margin), \n+                      loss = loss, min_sample = as.numeric(parameters$min_sample))\n+  \n+  \n+  ### if pruning\n+  if(pruning){\n+    # Get the pruned master and cross-validation trees\n+    master_data <- pruning(master_tree)\n+    master_alphas <- master_data[, 1]\n+    master_pruned_trees <- master_data[, -1]\n+    \n+    fold_alphas <- NULL\n+    fold_prune_trees <- NULL\n+    for(i in 1 : n_folds){\n+      fold_data <- pruning(fold_tree[[i]])\n+      fold_alphas[[i]] <- fold_data[, 1] \n+      fold_prune_trees[[i]] <- fold_data[, -1]\n+    }\n+    \n+    ### alphas list should not contain repeating alpha\n+    master_alphas <- master_alphas[!duplicated(master_alphas)]\n+    fold_alphas <- fold_alphas[!duplicated(fold_alphas)]\n+    \n+    \n+    # Compute the test risk for all pruned trees of each fold\n+    alpha_path_score <- NULL\n+    for(i in 1 : n_folds){\n+      for(j in 1 : length(fold_prune_trees[[i]][,1])){\n+        ### convert pruned tree list to partynode\n+        node <- fold_prune_trees[[i]][[j]]\n+        \n+        fit <- fitted_node(node, feature.mat[fold_split_idx$test[i,],])\n+        n <- nodeapply(node, ids = fit, info_node)\n+        ###prediction of test data\n+        prediction <- matrix(unlist(n), nrow = length(n), byrow = T)[,1]\n+        ###error calc\n+        fold_test_scores <- scorer(target.mat[fold_split_idx$test[i,],], prediction)\n+        \n+        ### creating a dataframe with init alpha, final alpha, score value\n+        if(j < (length(fold_alphas[[i]]) - 1)){\n+          alpha_path_score <- rbind(alpha_path_score, c(fold_alphas[[i]][j], fold_alphas[[i]][j+1], fold_test_scores))\n+        }\n+        else{\n+          alpha_path_score <- rbind(alpha_path_score, c(fold_alphas[[i]][j], Inf, fold_test_scores))\n+        }\n+        colnames(alpha_path_score) <- c(\"init alpha\", \" final alpha\", \"score\")\n+        alpha_path_score <- as.data.frame(alpha_path_score)\n+      }\n+      \n+    }\n+    \n+    # Prune the master tree based on the CV estimates\n+    alphas <- NULL\n+    alpha_cv_scores <- NULL\n+    alpha_train_scores <- NULL\n+    alpha_train_objective_values <- NULL\n+    best_alpha <- -1\n+    best_score <- Inf\n+    best_tree <- NULL\n+    \n+    for(i in 1:length(master_pruned_trees[,1])){\n+      if(i < (length(master_alphas) - 1)){\n+        geo_mean_alpha_k <- sqrt(master_alphas[[i]]* master_alphas[[i + 1]])\n+      }\n+      else{\n+        geo_mean_alpha_k <- Inf\n+      }\n+      \n+      ### compute cv_score as mean of each fold scores\n+      cv_score <- 0\n+      for(i in 1:n_folds){","path":"Rpackage/R/fitAndScore.R","position":111,"original_position":111,"commit_id":"4e89f19fd30b9adc0898cd59819495e6caf43434","original_commit_id":"4e89f19fd30b9adc0898cd59819495e6caf43434","user":{"login":"aldro61","id":2374980,"node_id":"MDQ6VXNlcjIzNzQ5ODA=","avatar_url":"https://avatars0.githubusercontent.com/u/2374980?v=4","gravatar_id":"","url":"https://api.github.com/users/aldro61","html_url":"https://github.com/aldro61","followers_url":"https://api.github.com/users/aldro61/followers","following_url":"https://api.github.com/users/aldro61/following{/other_user}","gists_url":"https://api.github.com/users/aldro61/gists{/gist_id}","starred_url":"https://api.github.com/users/aldro61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldro61/subscriptions","organizations_url":"https://api.github.com/users/aldro61/orgs","repos_url":"https://api.github.com/users/aldro61/repos","events_url":"https://api.github.com/users/aldro61/events{/privacy}","received_events_url":"https://api.github.com/users/aldro61/received_events","type":"User","site_admin":false},"body":"alpha_path_score should be indexed with the fold","created_at":"2018-06-22T14:58:48Z","updated_at":"2018-06-22T14:58:48Z","html_url":"https://github.com/aldro61/mmit/pull/25#discussion_r197473090","pull_request_url":"https://api.github.com/repos/aldro61/mmit/pulls/25","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/aldro61/mmit/pulls/comments/197473090"},"html":{"href":"https://github.com/aldro61/mmit/pull/25#discussion_r197473090"},"pull_request":{"href":"https://api.github.com/repos/aldro61/mmit/pulls/25"}},"in_reply_to_id":197440488},"pull_request":{"url":"https://api.github.com/repos/aldro61/mmit/pulls/25","id":192047993,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkyMDQ3OTkz","html_url":"https://github.com/aldro61/mmit/pull/25","diff_url":"https://github.com/aldro61/mmit/pull/25.diff","patch_url":"https://github.com/aldro61/mmit/pull/25.patch","issue_url":"https://api.github.com/repos/aldro61/mmit/issues/25","number":25,"state":"open","locked":false,"title":"Prunning","user":{"login":"parismita","id":17319560,"node_id":"MDQ6VXNlcjE3MzE5NTYw","avatar_url":"https://avatars1.githubusercontent.com/u/17319560?v=4","gravatar_id":"","url":"https://api.github.com/users/parismita","html_url":"https://github.com/parismita","followers_url":"https://api.github.com/users/parismita/followers","following_url":"https://api.github.com/users/parismita/following{/other_user}","gists_url":"https://api.github.com/users/parismita/gists{/gist_id}","starred_url":"https://api.github.com/users/parismita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parismita/subscriptions","organizations_url":"https://api.github.com/users/parismita/orgs","repos_url":"https://api.github.com/users/parismita/repos","events_url":"https://api.github.com/users/parismita/events{/privacy}","received_events_url":"https://api.github.com/users/parismita/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-06-01T14:16:48Z","updated_at":"2018-06-22T14:58:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f8ea18c76d4b4cc05f5b7bb237d74c3571eb3873","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/aldro61/mmit/pulls/25/commits","review_comments_url":"https://api.github.com/repos/aldro61/mmit/pulls/25/comments","review_comment_url":"https://api.github.com/repos/aldro61/mmit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aldro61/mmit/issues/25/comments","statuses_url":"https://api.github.com/repos/aldro61/mmit/statuses/4e89f19fd30b9adc0898cd59819495e6caf43434","head":{"label":"parismita:prunning","ref":"prunning","sha":"4e89f19fd30b9adc0898cd59819495e6caf43434","user":{"login":"parismita","id":17319560,"node_id":"MDQ6VXNlcjE3MzE5NTYw","avatar_url":"https://avatars1.githubusercontent.com/u/17319560?v=4","gravatar_id":"","url":"https://api.github.com/users/parismita","html_url":"https://github.com/parismita","followers_url":"https://api.github.com/users/parismita/followers","following_url":"https://api.github.com/users/parismita/following{/other_user}","gists_url":"https://api.github.com/users/parismita/gists{/gist_id}","starred_url":"https://api.github.com/users/parismita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parismita/subscriptions","organizations_url":"https://api.github.com/users/parismita/orgs","repos_url":"https://api.github.com/users/parismita/repos","events_url":"https://api.github.com/users/parismita/events{/privacy}","received_events_url":"https://api.github.com/users/parismita/received_events","type":"User","site_admin":false},"repo":{"id":130852547,"node_id":"MDEwOlJlcG9zaXRvcnkxMzA4NTI1NDc=","name":"mmit","full_name":"parismita/mmit","owner":{"login":"parismita","id":17319560,"node_id":"MDQ6VXNlcjE3MzE5NTYw","avatar_url":"https://avatars1.githubusercontent.com/u/17319560?v=4","gravatar_id":"","url":"https://api.github.com/users/parismita","html_url":"https://github.com/parismita","followers_url":"https://api.github.com/users/parismita/followers","following_url":"https://api.github.com/users/parismita/following{/other_user}","gists_url":"https://api.github.com/users/parismita/gists{/gist_id}","starred_url":"https://api.github.com/users/parismita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parismita/subscriptions","organizations_url":"https://api.github.com/users/parismita/orgs","repos_url":"https://api.github.com/users/parismita/repos","events_url":"https://api.github.com/users/parismita/events{/privacy}","received_events_url":"https://api.github.com/users/parismita/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/parismita/mmit","description":"Regression trees for interval censored output data","fork":true,"url":"https://api.github.com/repos/parismita/mmit","forks_url":"https://api.github.com/repos/parismita/mmit/forks","keys_url":"https://api.github.com/repos/parismita/mmit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/parismita/mmit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/parismita/mmit/teams","hooks_url":"https://api.github.com/repos/parismita/mmit/hooks","issue_events_url":"https://api.github.com/repos/parismita/mmit/issues/events{/number}","events_url":"https://api.github.com/repos/parismita/mmit/events","assignees_url":"https://api.github.com/repos/parismita/mmit/assignees{/user}","branches_url":"https://api.github.com/repos/parismita/mmit/branches{/branch}","tags_url":"https://api.github.com/repos/parismita/mmit/tags","blobs_url":"https://api.github.com/repos/parismita/mmit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/parismita/mmit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/parismita/mmit/git/refs{/sha}","trees_url":"https://api.github.com/repos/parismita/mmit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/parismita/mmit/statuses/{sha}","languages_url":"https://api.github.com/repos/parismita/mmit/languages","stargazers_url":"https://api.github.com/repos/parismita/mmit/stargazers","contributors_url":"https://api.github.com/repos/parismita/mmit/contributors","subscribers_url":"https://api.github.com/repos/parismita/mmit/subscribers","subscription_url":"https://api.github.com/repos/parismita/mmit/subscription","commits_url":"https://api.github.com/repos/parismita/mmit/commits{/sha}","git_commits_url":"https://api.github.com/repos/parismita/mmit/git/commits{/sha}","comments_url":"https://api.github.com/repos/parismita/mmit/comments{/number}","issue_comment_url":"https://api.github.com/repos/parismita/mmit/issues/comments{/number}","contents_url":"https://api.github.com/repos/parismita/mmit/contents/{+path}","compare_url":"https://api.github.com/repos/parismita/mmit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/parismita/mmit/merges","archive_url":"https://api.github.com/repos/parismita/mmit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/parismita/mmit/downloads","issues_url":"https://api.github.com/repos/parismita/mmit/issues{/number}","pulls_url":"https://api.github.com/repos/parismita/mmit/pulls{/number}","milestones_url":"https://api.github.com/repos/parismita/mmit/milestones{/number}","notifications_url":"https://api.github.com/repos/parismita/mmit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/parismita/mmit/labels{/name}","releases_url":"https://api.github.com/repos/parismita/mmit/releases{/id}","deployments_url":"https://api.github.com/repos/parismita/mmit/deployments","created_at":"2018-04-24T12:43:07Z","updated_at":"2018-06-08T13:23:38Z","pushed_at":"2018-06-21T19:37:23Z","git_url":"git://github.com/parismita/mmit.git","ssh_url":"git@github.com:parismita/mmit.git","clone_url":"https://github.com/parismita/mmit.git","svn_url":"https://github.com/parismita/mmit","homepage":"https://aldro61.github.io/mmit/","size":306,"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,"open_issues_count":0,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"aldro61:master","ref":"master","sha":"557084a8937460e4f1b955bf2141293a215c18b7","user":{"login":"aldro61","id":2374980,"node_id":"MDQ6VXNlcjIzNzQ5ODA=","avatar_url":"https://avatars0.githubusercontent.com/u/2374980?v=4","gravatar_id":"","url":"https://api.github.com/users/aldro61","html_url":"https://github.com/aldro61","followers_url":"https://api.github.com/users/aldro61/followers","following_url":"https://api.github.com/users/aldro61/following{/other_user}","gists_url":"https://api.github.com/users/aldro61/gists{/gist_id}","starred_url":"https://api.github.com/users/aldro61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldro61/subscriptions","organizations_url":"https://api.github.com/users/aldro61/orgs","repos_url":"https://api.github.com/users/aldro61/repos","events_url":"https://api.github.com/users/aldro61/events{/privacy}","received_events_url":"https://api.github.com/users/aldro61/received_events","type":"User","site_admin":false},"repo":{"id":84226032,"node_id":"MDEwOlJlcG9zaXRvcnk4NDIyNjAzMg==","name":"mmit","full_name":"aldro61/mmit","owner":{"login":"aldro61","id":2374980,"node_id":"MDQ6VXNlcjIzNzQ5ODA=","avatar_url":"https://avatars0.githubusercontent.com/u/2374980?v=4","gravatar_id":"","url":"https://api.github.com/users/aldro61","html_url":"https://github.com/aldro61","followers_url":"https://api.github.com/users/aldro61/followers","following_url":"https://api.github.com/users/aldro61/following{/other_user}","gists_url":"https://api.github.com/users/aldro61/gists{/gist_id}","starred_url":"https://api.github.com/users/aldro61/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aldro61/subscriptions","organizations_url":"https://api.github.com/users/aldro61/orgs","repos_url":"https://api.github.com/users/aldro61/repos","events_url":"https://api.github.com/users/aldro61/events{/privacy}","received_events_url":"https://api.github.com/users/aldro61/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aldro61/mmit","description":"Regression trees for interval censored output data","fork":false,"url":"https://api.github.com/repos/aldro61/mmit","forks_url":"https://api.github.com/repos/aldro61/mmit/forks","keys_url":"https://api.github.com/repos/aldro61/mmit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aldro61/mmit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aldro61/mmit/teams","hooks_url":"https://api.github.com/repos/aldro61/mmit/hooks","issue_events_url":"https://api.github.com/repos/aldro61/mmit/issues/events{/number}","events_url":"https://api.github.com/repos/aldro61/mmit/events","assignees_url":"https://api.github.com/repos/aldro61/mmit/assignees{/user}","branches_url":"https://api.github.com/repos/aldro61/mmit/branches{/branch}","tags_url":"https://api.github.com/repos/aldro61/mmit/tags","blobs_url":"https://api.github.com/repos/aldro61/mmit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aldro61/mmit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aldro61/mmit/git/refs{/sha}","trees_url":"https://api.github.com/repos/aldro61/mmit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aldro61/mmit/statuses/{sha}","languages_url":"https://api.github.com/repos/aldro61/mmit/languages","stargazers_url":"https://api.github.com/repos/aldro61/mmit/stargazers","contributors_url":"https://api.github.com/repos/aldro61/mmit/contributors","subscribers_url":"https://api.github.com/repos/aldro61/mmit/subscribers","subscription_url":"https://api.github.com/repos/aldro61/mmit/subscription","commits_url":"https://api.github.com/repos/aldro61/mmit/commits{/sha}","git_commits_url":"https://api.github.com/repos/aldro61/mmit/git/commits{/sha}","comments_url":"https://api.github.com/repos/aldro61/mmit/comments{/number}","issue_comment_url":"https://api.github.com/repos/aldro61/mmit/issues/comments{/number}","contents_url":"https://api.github.com/repos/aldro61/mmit/contents/{+path}","compare_url":"https://api.github.com/repos/aldro61/mmit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aldro61/mmit/merges","archive_url":"https://api.github.com/repos/aldro61/mmit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aldro61/mmit/downloads","issues_url":"https://api.github.com/repos/aldro61/mmit/issues{/number}","pulls_url":"https://api.github.com/repos/aldro61/mmit/pulls{/number}","milestones_url":"https://api.github.com/repos/aldro61/mmit/milestones{/number}","notifications_url":"https://api.github.com/repos/aldro61/mmit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aldro61/mmit/labels{/name}","releases_url":"https://api.github.com/repos/aldro61/mmit/releases{/id}","deployments_url":"https://api.github.com/repos/aldro61/mmit/deployments","created_at":"2017-03-07T17:14:35Z","updated_at":"2018-06-08T13:33:43Z","pushed_at":"2018-06-21T19:37:24Z","git_url":"git://github.com/aldro61/mmit.git","ssh_url":"git@github.com:aldro61/mmit.git","clone_url":"https://github.com/aldro61/mmit.git","svn_url":"https://github.com/aldro61/mmit","homepage":"https://aldro61.github.io/mmit/","size":262,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":7,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":3,"open_issues":7,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/aldro61/mmit/pulls/25"},"html":{"href":"https://github.com/aldro61/mmit/pull/25"},"issue":{"href":"https://api.github.com/repos/aldro61/mmit/issues/25"},"comments":{"href":"https://api.github.com/repos/aldro61/mmit/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/aldro61/mmit/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/aldro61/mmit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aldro61/mmit/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/aldro61/mmit/statuses/4e89f19fd30b9adc0898cd59819495e6caf43434"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"aldro61"}}