{
  "id": 70437,
  "title": "What is the best way to calculate the RMSE?",
  "url": "/competitions/ga-customer-revenue-prediction/discussion/70437",
  "author_name": "akKaggle",
  "post_date": "2018-11-03T16:52:48.972000",
  "votes": 0,
  "comment_count": 0,
  "views": 0,
  "content": "<p>Hi,</p>\n\n<p>For the train and val RMSE, should you calculate the RMSE for each visit's predicted revenue or should you calculate the RMSE on the sum of the predicted revenue for each fullVisitorId?</p>\n\n<p>I'm using this function to Calculate RMSE on the sum of the predicted revenue for each fullVisitorId.</p>\n\n<pre><code>def score(preds, idx):\n  df = train.iloc[idx][['fullVisitorId', 'totals.transactionRevenue']].copy()\n\n  df.loc[:, 'PredictedLogRevenue'] = np.expm1(preds)\n  df.loc[:, 'totals.transactionRevenue'] = np.expm1(df.loc[:, 'totals.transactionRevenue'])\n\n  df = df[['fullVisitorId', 'PredictedLogRevenue', 'totals.transactionRevenue']].groupby('fullVisitorId').sum().reset_index()\n\n  df[\"PredictedLogRevenue\"] = np.log1p(df[\"PredictedLogRevenue\"])\n  df[\"totals.transactionRevenue\"] = np.log1p(df[\"totals.transactionRevenue\"])\n\n  rsme = mean_squared_error(df[\"totals.transactionRevenue\"], df[\"PredictedLogRevenue\"])**0.5\n\n  return rsme\n</code></pre>\n\n<p>Thanks</p>",
  "messages": [
    {
      "id": 414817,
      "postDate": "2018-11-03T16:52:48.973Z",
      "content": "<p>Hi,</p>\n\n<p>For the train and val RMSE, should you calculate the RMSE for each visit's predicted revenue or should you calculate the RMSE on the sum of the predicted revenue for each fullVisitorId?</p>\n\n<p>I'm using this function to Calculate RMSE on the sum of the predicted revenue for each fullVisitorId.</p>\n\n<pre><code>def score(preds, idx):\n  df = train.iloc[idx][['fullVisitorId', 'totals.transactionRevenue']].copy()\n\n  df.loc[:, 'PredictedLogRevenue'] = np.expm1(preds)\n  df.loc[:, 'totals.transactionRevenue'] = np.expm1(df.loc[:, 'totals.transactionRevenue'])\n\n  df = df[['fullVisitorId', 'PredictedLogRevenue', 'totals.transactionRevenue']].groupby('fullVisitorId').sum().reset_index()\n\n  df[\"PredictedLogRevenue\"] = np.log1p(df[\"PredictedLogRevenue\"])\n  df[\"totals.transactionRevenue\"] = np.log1p(df[\"totals.transactionRevenue\"])\n\n  rsme = mean_squared_error(df[\"totals.transactionRevenue\"], df[\"PredictedLogRevenue\"])**0.5\n\n  return rsme\n</code></pre>\n\n<p>Thanks</p>",
      "rawMarkdown": "Hi,\n\nFor the train and val RMSE, should you calculate the RMSE for each visit's predicted revenue or should you calculate the RMSE on the sum of the predicted revenue for each fullVisitorId?\n\nI'm using this function to Calculate RMSE on the sum of the predicted revenue for each fullVisitorId.\n\n    def score(preds, idx):\n      df = train.iloc[idx][['fullVisitorId', 'totals.transactionRevenue']].copy()\n    \n      df.loc[:, 'PredictedLogRevenue'] = np.expm1(preds)\n      df.loc[:, 'totals.transactionRevenue'] = np.expm1(df.loc[:, 'totals.transactionRevenue'])\n    \n      df = df[['fullVisitorId', 'PredictedLogRevenue', 'totals.transactionRevenue']].groupby('fullVisitorId').sum().reset_index()\n        \n      df[\"PredictedLogRevenue\"] = np.log1p(df[\"PredictedLogRevenue\"])\n      df[\"totals.transactionRevenue\"] = np.log1p(df[\"totals.transactionRevenue\"])\n    \n      rsme = mean_squared_error(df[\"totals.transactionRevenue\"], df[\"PredictedLogRevenue\"])**0.5\n    \n      return rsme\n\nThanks"
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "414817": "Hi,\n\nFor the train and val RMSE, should you calculate the RMSE for each visit's predicted revenue or should you calculate the RMSE on the sum of the predicted revenue for each fullVisitorId?\n\nI'm using this function to Calculate RMSE on the sum of the predicted revenue for each fullVisitorId.\n\n    def score(preds, idx):\n      df = train.iloc[idx][['fullVisitorId', 'totals.transactionRevenue']].copy()\n    \n      df.loc[:, 'PredictedLogRevenue'] = np.expm1(preds)\n      df.loc[:, 'totals.transactionRevenue'] = np.expm1(df.loc[:, 'totals.transactionRevenue'])\n    \n      df = df[['fullVisitorId', 'PredictedLogRevenue', 'totals.transactionRevenue']].groupby('fullVisitorId').sum().reset_index()\n        \n      df[\"PredictedLogRevenue\"] = np.log1p(df[\"PredictedLogRevenue\"])\n      df[\"totals.transactionRevenue\"] = np.log1p(df[\"totals.transactionRevenue\"])\n    \n      rsme = mean_squared_error(df[\"totals.transactionRevenue\"], df[\"PredictedLogRevenue\"])**0.5\n    \n      return rsme\n\nThanks"
  }
}