{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# default_exp metrics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Metrics\n",
    "\n",
    "> Metrics should follow the scikit-learn pattern of accepting two arguments: \n",
    "\n",
    "1. `y_true` (labels)\n",
    "2. either `y_pred` (hard predictions) or `y_score` (soft predictions)\n",
    "\n",
    "Matching the order and naming of these arguments is required. If additional \n",
    "arguments are necessary, they can be specified with the use of `functools.partial`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#hide\n",
    "from nbdev.showdoc import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# export\n",
    "def percent_positive(y_true, y_pred):\n",
    "    \"\"\"Compute the percent of predictions that are positive. This\n",
    "    can help us identify when a model is predicting all ones or zeros.\n",
    "    \"\"\"\n",
    "    return (y_pred == 1).float().mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# export\n",
    "def mean_soft_prediction(y_true, y_score):\n",
    "    \"\"\"Compute the mean predicted probability.\"\"\"\n",
    "    return y_score.mean() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# export\n",
    "def batch_size(y_true, y_pred):\n",
    "    \"\"\"Count the number of items in the current batch.\"\"\"\n",
    "    return y_true.shape[0]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
