{"action":"created","issue":{"url":"https://api.github.com/repos/dmlc/xgboost/issues/659","labels_url":"https://api.github.com/repos/dmlc/xgboost/issues/659/labels{/name}","comments_url":"https://api.github.com/repos/dmlc/xgboost/issues/659/comments","events_url":"https://api.github.com/repos/dmlc/xgboost/issues/659/events","html_url":"https://github.com/dmlc/xgboost/issues/659","id":119340818,"number":659,"title":" [R] custom metrics in xgb.cv","user":{"login":"hectep","id":6478308,"avatar_url":"https://avatars.githubusercontent.com/u/6478308?v=3","gravatar_id":"","url":"https://api.github.com/users/hectep","html_url":"https://github.com/hectep","followers_url":"https://api.github.com/users/hectep/followers","following_url":"https://api.github.com/users/hectep/following{/other_user}","gists_url":"https://api.github.com/users/hectep/gists{/gist_id}","starred_url":"https://api.github.com/users/hectep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hectep/subscriptions","organizations_url":"https://api.github.com/users/hectep/orgs","repos_url":"https://api.github.com/users/hectep/repos","events_url":"https://api.github.com/users/hectep/events{/privacy}","received_events_url":"https://api.github.com/users/hectep/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-29T06:19:55Z","updated_at":"2016-01-08T14:21:49Z","closed_at":null,"body":"The issue is related to  #333\r\nI'm trying to implement the same  quadratic weighted kappa in xgb.cv\r\nThe code is:\r\n```\r\nevalerror <- function(preds, dtrain) {\r\n      library(Metrics)\r\n      labels <- getinfo(dtrain, \"label\")\r\n      err <- ScoreQuadraticWeightedKappa(as.numeric(labels),as.numeric(preds))\r\n      return(list(metric = \"kappa\", value = err))\r\n}\r\n\r\nparam <- list(  objective           = \"reg:linear\",\r\n                nthread             = 4,\r\n                eta                 = 0.05,\r\n                max_depth           = 100,  \r\n                subsample           = 0.6,\r\n                min_child_weight    = 2, \r\n                colsample_bytree    = 0.6,\r\n                eval_metric         = \"rmse\"\r\n           \r\n)\r\n\r\ncv <- xgb.cv(data = dtrain, nfold = 5, maximize = TRUE, feval = evalerror, \r\n             nround = 200, \r\n             early.stop.round = 10,  print.every.n = 10)\r\n```\r\nBut after the first round it returns this error:\r\n```\r\n[0]\ttrain-kappa:NaN+NA\ttest-kappa:NaN+NA\r\nError in if ((maximize && score > bestScore) || (!maximize && score <  : \r\n  missing value where TRUE/FALSE needed\r\n```\r\nDo i miss something obvious here?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dmlc/xgboost/issues/comments/170016425","html_url":"https://github.com/dmlc/xgboost/issues/659#issuecomment-170016425","issue_url":"https://api.github.com/repos/dmlc/xgboost/issues/659","id":170016425,"user":{"login":"terrytangyuan","id":4269898,"avatar_url":"https://avatars.githubusercontent.com/u/4269898?v=3","gravatar_id":"","url":"https://api.github.com/users/terrytangyuan","html_url":"https://github.com/terrytangyuan","followers_url":"https://api.github.com/users/terrytangyuan/followers","following_url":"https://api.github.com/users/terrytangyuan/following{/other_user}","gists_url":"https://api.github.com/users/terrytangyuan/gists{/gist_id}","starred_url":"https://api.github.com/users/terrytangyuan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/terrytangyuan/subscriptions","organizations_url":"https://api.github.com/users/terrytangyuan/orgs","repos_url":"https://api.github.com/users/terrytangyuan/repos","events_url":"https://api.github.com/users/terrytangyuan/events{/privacy}","received_events_url":"https://api.github.com/users/terrytangyuan/received_events","type":"User","site_admin":false},"created_at":"2016-01-08T14:21:49Z","updated_at":"2016-01-08T14:21:49Z","body":"It's possible that you label/pred contains NA. Could you print those out to see if it's true? It would be better if you can provide a reproducible example. What's the output of str(dtrain)? "}}