{
  "id": 327164,
  "title": "R snippet to estimate Normalized Gini Coefficient.",
  "url": "/competitions/amex-default-prediction/discussion/327164",
  "author_name": "Marília Prata",
  "post_date": "2022-05-25T22:54:42.195000",
  "votes": 16,
  "comment_count": 0,
  "views": 0,
  "content": "<h1>Topic made by Dmitriy Guller  (5 years ago)</h1>\n<p>dmitriyguller</p>\n<p>According to Dmitriy this definition restates the Gini as the covariance of scaled prediction rank and scaled target value. He personally found that to be a more intuitive definition, as it makes it clear why Gini is an appropriate rank metric to use.</p>\n<p>Five years ago, Kagglers used to apply R language regularly.  I hope that those that work with R find it useful.</p>\n<p>normalizedGini2 &lt;- function(aa, pp) {<br>\ngini &lt;- function(aa, pp) {<br>\n    rank_pp &lt;- data.table::frank(pp)<br>\n    return(cov(rank_pp / mean(rank_pp), aa / mean(aa)))<br>\n}<br>\nreturn(gini(aa, pp) / gini(aa, aa))}</p>\n<p><a href=\"https://www.kaggle.com/c/porto-seguro-safe-driver-prediction/discussion/40576\" target=\"_blank\">https://www.kaggle.com/c/porto-seguro-safe-driver-prediction/discussion/40576</a>)</p>",
  "messages": [
    {
      "id": 1801578,
      "postDate": "2022-05-25T22:54:42.197Z",
      "content": "<h1>Topic made by Dmitriy Guller  (5 years ago)</h1>\n<p>dmitriyguller</p>\n<p>According to Dmitriy this definition restates the Gini as the covariance of scaled prediction rank and scaled target value. He personally found that to be a more intuitive definition, as it makes it clear why Gini is an appropriate rank metric to use.</p>\n<p>Five years ago, Kagglers used to apply R language regularly.  I hope that those that work with R find it useful.</p>\n<p>normalizedGini2 &lt;- function(aa, pp) {<br>\ngini &lt;- function(aa, pp) {<br>\n    rank_pp &lt;- data.table::frank(pp)<br>\n    return(cov(rank_pp / mean(rank_pp), aa / mean(aa)))<br>\n}<br>\nreturn(gini(aa, pp) / gini(aa, aa))}</p>\n<p><a href=\"https://www.kaggle.com/c/porto-seguro-safe-driver-prediction/discussion/40576\" target=\"_blank\">https://www.kaggle.com/c/porto-seguro-safe-driver-prediction/discussion/40576</a>)</p>",
      "rawMarkdown": "#Topic made by Dmitriy Guller  (5 years ago)\ndmitriyguller\n\nAccording to Dmitriy this definition restates the Gini as the covariance of scaled prediction rank and scaled target value. He personally found that to be a more intuitive definition, as it makes it clear why Gini is an appropriate rank metric to use.\n\nFive years ago, Kagglers used to apply R language regularly.  I hope that those that work with R find it useful.\n\nnormalizedGini2 <- function(aa, pp) {\ngini <- function(aa, pp) {\n    rank_pp <- data.table::frank(pp)\n    return(cov(rank_pp / mean(rank_pp), aa / mean(aa)))\n}\nreturn(gini(aa, pp) / gini(aa, aa))}\n\nhttps://www.kaggle.com/c/porto-seguro-safe-driver-prediction/discussion/40576)",
      "votes": 16
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "1801578": "#Topic made by Dmitriy Guller  (5 years ago)\ndmitriyguller\n\nAccording to Dmitriy this definition restates the Gini as the covariance of scaled prediction rank and scaled target value. He personally found that to be a more intuitive definition, as it makes it clear why Gini is an appropriate rank metric to use.\n\nFive years ago, Kagglers used to apply R language regularly.  I hope that those that work with R find it useful.\n\nnormalizedGini2 <- function(aa, pp) {\ngini <- function(aa, pp) {\n    rank_pp <- data.table::frank(pp)\n    return(cov(rank_pp / mean(rank_pp), aa / mean(aa)))\n}\nreturn(gini(aa, pp) / gini(aa, aa))}\n\nhttps://www.kaggle.com/c/porto-seguro-safe-driver-prediction/discussion/40576)"
  }
}