{
  "id": 615294,
  "title": "HELP:LB is -2?",
  "url": "/competitions/csiro-biomass/discussion/615294",
  "author_name": "",
  "post_date": "2025-11-10T04:51:39.787907800Z",
  "votes": null,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Hi, everyone, I found my there is a big diff in my CV and LB.I want to konw whether my metric function has an error. \n`# metrics\ndef weighted_r2_score(oy_true, oy_pred, opt):\n    \"\"\"\n    计算加权R²分数 (与Kaggle官方评分一致)</p>\n<pre><code>参数:\ny_true: [n_samples, n_targets]\ny_pred: [n_samples, n_targets]\nweights: [n_targets] 每个目标的权重\n\n返回:\nfloat: 加权R²分数\n\ny_true = oy_true * np.array(.target_std) + np.array(.target_mean)\ny_pred = oy_pred * np.array(.target_std) + np.array(.target_mean)\n\nweights = np.array(.weights)\ny_true = np.array(y_true)\ny_pred = np.array(y_pred)\n\n# 计算加权平均真实值\nweighted_mean = np.sum(y_true * weights) / (y_true)  # TODO 易错\n\n# 计算分子 (加权残差平方和)\nss_res = np.sum(weights * (y_true - y_pred) ** )\n\n# 计算分母 (加权总平方和)\nss_tot = np.sum(weights * (y_true - weighted_mean) ** )\n\n# 防止除零\n ss_tot == :\n     \n\n  - (ss_res / ss_tot)`\n</code></pre>",
  "messages": [
    {
      "id": "3314119",
      "postDate": "11/10/2025 04:51:39",
      "content": "<p>Hi, everyone, I found my there is a big diff in my CV and LB.I want to konw whether my metric function has an error. \n`# metrics\ndef weighted_r2_score(oy_true, oy_pred, opt):\n    \"\"\"\n    计算加权R²分数 (与Kaggle官方评分一致)</p>\n<pre><code>参数:\ny_true: [n_samples, n_targets]\ny_pred: [n_samples, n_targets]\nweights: [n_targets] 每个目标的权重\n\n返回:\nfloat: 加权R²分数\n\ny_true = oy_true * np.array(.target_std) + np.array(.target_mean)\ny_pred = oy_pred * np.array(.target_std) + np.array(.target_mean)\n\nweights = np.array(.weights)\ny_true = np.array(y_true)\ny_pred = np.array(y_pred)\n\n# 计算加权平均真实值\nweighted_mean = np.sum(y_true * weights) / (y_true)  # TODO 易错\n\n# 计算分子 (加权残差平方和)\nss_res = np.sum(weights * (y_true - y_pred) ** )\n\n# 计算分母 (加权总平方和)\nss_tot = np.sum(weights * (y_true - weighted_mean) ** )\n\n# 防止除零\n ss_tot == :\n     \n\n  - (ss_res / ss_tot)`\n</code></pre>",
      "rawMarkdown": "Hi, everyone, I found my there is a big diff in my CV and LB.I want to konw whether my metric function has an error. \n`# metrics\ndef weighted_r2_score(oy_true, oy_pred, opt):\n    \"\"\"\n    计算加权R²分数 (与Kaggle官方评分一致)\n    \n    参数:\n    y_true: [n_samples, n_targets]\n    y_pred: [n_samples, n_targets]\n    weights: [n_targets] 每个目标的权重\n    \n    返回:\n    float: 加权R²分数\n    \"\"\"\n    y_true = oy_true * np.array(opt.target_std) + np.array(opt.target_mean)\n    y_pred = oy_pred * np.array(opt.target_std) + np.array(opt.target_mean)\n\n    weights = np.array(opt.weights)\n    y_true = np.array(y_true)\n    y_pred = np.array(y_pred)\n    \n    # 计算加权平均真实值\n    weighted_mean = np.sum(y_true * weights) / len(y_true)  # TODO 易错\n    \n    # 计算分子 (加权残差平方和)\n    ss_res = np.sum(weights * (y_true - y_pred) ** 2)\n    \n    # 计算分母 (加权总平方和)\n    ss_tot = np.sum(weights * (y_true - weighted_mean) ** 2)\n    \n    # 防止除零\n    if ss_tot == 0:\n        return 0.0\n    \n    return 1 - (ss_res / ss_tot)`",
      "votes": null
    },
    {
      "id": "3317972",
      "postDate": "11/10/2025 23:24:48",
      "content": "<p>why not just copy and paste from the metric notebook</p>",
      "rawMarkdown": "why not just copy and paste from the metric notebook",
      "votes": null
    },
    {
      "id": "3318153",
      "postDate": "11/11/2025 03:15:57",
      "content": "<p>Where? Thanks.</p>",
      "rawMarkdown": "Where? Thanks.",
      "votes": null
    },
    {
      "id": "3318383",
      "postDate": "11/11/2025 06:14:34",
      "content": "<p><a href=\"!https://www.kaggle.com/code/metric/r2-score?scriptVersionId=151169785\" target=\"_blank\">Here</a></p>",
      "rawMarkdown": "[Here](!https://www.kaggle.com/code/metric/r2-score?scriptVersionId=151169785)",
      "votes": null
    },
    {
      "id": "3318475",
      "postDate": "11/11/2025 07:26:36",
      "content": "<p>没找到呀哥们，可以提示一下不？</p>",
      "rawMarkdown": "没找到呀哥们，可以提示一下不？",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 3317972,
      "author_name": "porpita",
      "author_url": "",
      "post_date": "11/10/2025 23:24:48",
      "content": "<p>why not just copy and paste from the metric notebook</p>",
      "votes": null,
      "replies": [
        {
          "id": 3318153,
          "author_name": "jakkma",
          "author_url": "",
          "post_date": "11/11/2025 03:15:57",
          "content": "<p>Where? Thanks.</p>",
          "votes": null,
          "replies": [
            {
              "id": 3318383,
              "author_name": "zrongchu",
              "author_url": "",
              "post_date": "11/11/2025 06:14:34",
              "content": "<p><a href=\"!https://www.kaggle.com/code/metric/r2-score?scriptVersionId=151169785\" target=\"_blank\">Here</a></p>",
              "votes": null,
              "replies": [
                {
                  "id": 3318475,
                  "author_name": "jakkma",
                  "author_url": "",
                  "post_date": "11/11/2025 07:26:36",
                  "content": "<p>没找到呀哥们，可以提示一下不？</p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "3314119": "Hi, everyone, I found my there is a big diff in my CV and LB.I want to konw whether my metric function has an error. \n`# metrics\ndef weighted_r2_score(oy_true, oy_pred, opt):\n    \"\"\"\n    计算加权R²分数 (与Kaggle官方评分一致)\n    \n    参数:\n    y_true: [n_samples, n_targets]\n    y_pred: [n_samples, n_targets]\n    weights: [n_targets] 每个目标的权重\n    \n    返回:\n    float: 加权R²分数\n    \"\"\"\n    y_true = oy_true * np.array(opt.target_std) + np.array(opt.target_mean)\n    y_pred = oy_pred * np.array(opt.target_std) + np.array(opt.target_mean)\n\n    weights = np.array(opt.weights)\n    y_true = np.array(y_true)\n    y_pred = np.array(y_pred)\n    \n    # 计算加权平均真实值\n    weighted_mean = np.sum(y_true * weights) / len(y_true)  # TODO 易错\n    \n    # 计算分子 (加权残差平方和)\n    ss_res = np.sum(weights * (y_true - y_pred) ** 2)\n    \n    # 计算分母 (加权总平方和)\n    ss_tot = np.sum(weights * (y_true - weighted_mean) ** 2)\n    \n    # 防止除零\n    if ss_tot == 0:\n        return 0.0\n    \n    return 1 - (ss_res / ss_tot)`",
    "3317972": "why not just copy and paste from the metric notebook",
    "3318153": "Where? Thanks.",
    "3318383": "[Here](!https://www.kaggle.com/code/metric/r2-score?scriptVersionId=151169785)",
    "3318475": "没找到呀哥们，可以提示一下不？"
  },
  "source": "meta"
}