{
  "id": 370553,
  "title": "Probabilistic F Score in R",
  "url": "/competitions/rsna-breast-cancer-detection/discussion/370553",
  "author_name": "Martin Svensson",
  "post_date": "2022-12-05T07:26:23.986000",
  "votes": 4,
  "comment_count": 0,
  "views": 0,
  "content": "<p>For any fellow R users joining the competition, here's an implementation of the probabilistic F score (based on the <a href=\"https://www.kaggle.com/code/sohier/probabilistic-f-score/notebook\" target=\"_blank\">Python implementation</a>). Note that, for this competition, the value of \\(\\beta\\) is 1. </p>\n<pre><code>pf_score  y_true y_pred beta \n\n  y_predwhichy_pred    \n  y_predwhichy_pred    \n\n  ctp  y_predwhichy_true  \n  cfp  y_predwhichy_true  \n\n  c_precision  ctp  ctp  cfp\n  c_recall  ctp  y_true\n\n   c_precision    c_recall   \n\n    result    beta  c_precision  c_recall  beta  c_precision  c_recall\n\n    \n\n    result  0\n\n  \n\n  result\n\n\n</code></pre>",
  "messages": [
    {
      "id": 2055579,
      "postDate": "2022-12-05T07:26:23.987Z",
      "content": "<p>For any fellow R users joining the competition, here's an implementation of the probabilistic F score (based on the <a href=\"https://www.kaggle.com/code/sohier/probabilistic-f-score/notebook\" target=\"_blank\">Python implementation</a>). Note that, for this competition, the value of \\(\\beta\\) is 1. </p>\n<pre><code>pf_score  y_true y_pred beta \n\n  y_predwhichy_pred    \n  y_predwhichy_pred    \n\n  ctp  y_predwhichy_true  \n  cfp  y_predwhichy_true  \n\n  c_precision  ctp  ctp  cfp\n  c_recall  ctp  y_true\n\n   c_precision    c_recall   \n\n    result    beta  c_precision  c_recall  beta  c_precision  c_recall\n\n    \n\n    result  0\n\n  \n\n  result\n\n\n</code></pre>",
      "rawMarkdown": "For any fellow R users joining the competition, here's an implementation of the probabilistic F score (based on the [Python implementation](https://www.kaggle.com/code/sohier/probabilistic-f-score/notebook)). Note that, for this competition, the value of \\\\(\\beta\\\\\\) is 1. \n\n```r\npf_score <- function(y_true, y_pred, beta) {\n  \n  y_pred[which(y_pred > 1)] <- 1\n  y_pred[which(y_pred < 0)] <- 0\n  \n  ctp <- sum(y_pred[which(y_true == 1)])\n  cfp <- sum(y_pred[which(y_true == 0)])\n  \n  c_precision <- ctp / (ctp + cfp)\n  c_recall <- ctp / sum(y_true)\n  \n  if (c_precision > 0 & c_recall > 0) {\n    \n    result <- (1 + beta^2) * (c_precision * c_recall) / (beta^2 * c_precision + c_recall)\n    \n  } else {\n    \n    result <- 0\n    \n  }\n  \n  return(result)\n  \n}\n```\n\n\n\n",
      "votes": 4
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "2055579": "For any fellow R users joining the competition, here's an implementation of the probabilistic F score (based on the [Python implementation](https://www.kaggle.com/code/sohier/probabilistic-f-score/notebook)). Note that, for this competition, the value of \\\\(\\beta\\\\\\) is 1. \n\n```r\npf_score <- function(y_true, y_pred, beta) {\n  \n  y_pred[which(y_pred > 1)] <- 1\n  y_pred[which(y_pred < 0)] <- 0\n  \n  ctp <- sum(y_pred[which(y_true == 1)])\n  cfp <- sum(y_pred[which(y_true == 0)])\n  \n  c_precision <- ctp / (ctp + cfp)\n  c_recall <- ctp / sum(y_true)\n  \n  if (c_precision > 0 & c_recall > 0) {\n    \n    result <- (1 + beta^2) * (c_precision * c_recall) / (beta^2 * c_precision + c_recall)\n    \n  } else {\n    \n    result <- 0\n    \n  }\n  \n  return(result)\n  \n}\n```\n\n\n\n"
  }
}