{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "yugMU9MjJtBl"
   },
   "source": [
    "# Activity: Build a Naive Bayes model "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "EzWqJunmJotv"
   },
   "source": [
    "## Introduction\n",
    "\n",
    "In this activity, you will build your own Naive Bayes model. Naive Bayes models can be valuable to use any time you are doing work with predictions because they give you a way to account for new information. In today's world, where data is constantly evolving, modeling with Naive Bayes can help you adapt quickly and make more accurate predictions about what could occur.\n",
    "\n",
    "For this activity, you work for a firm that provides insights for management and coaches in the National Basketball Association (NBA), a professional basketball league in North America. The league is interested in retaining players who can last in the high-pressure environment of professional basketball and help the team be successful over time. In the previous activity, you analyzed a subset of data that contained information about the NBA players and their performance records. You conducted feature engineering to determine which features would most effectively predict a player's career duration. You will now use those insights to build a model that predicts whether a player will have an NBA career lasting five years or more. \n",
    "\n",
    "The data for this activity consists of performance statistics from each player's rookie year. There are 1,341 observations, and each observation in the data represents a different player in the NBA. Your target variable is a Boolean value that indicates whether a given player will last in the league for five years. Since you previously performed feature engineering on this data, it is now ready for modeling.   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "yTVinL1hJqoy"
   },
   "source": [
    "## Step 1: Imports"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "DDIRpqkZJ4S8"
   },
   "source": [
    "### Import packages\n",
    "\n",
    "Begin with your import statements. Of particular note here are `pandas` and from `sklearn`, `naive_bayes`, `model_selection`, and `metrics`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "id": "1nDjAJPa4lVZ"
   },
   "outputs": [],
   "source": [
    "# Import relevant libraries and modules.\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.metrics import recall_score, precision_score, accuracy_score, f1_score, confusion_matrix, ConfusionMatrixDisplay\n",
    "from sklearn.naive_bayes import *\n",
    "from sklearn.model_selection import *\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hKylHziGzY3X"
   },
   "source": [
    "### Load the dataset\n",
    "\n",
    "Recall that in the lab about feature engineering, you outputted features for the NBA player dataset along with the target variable ``target_5yrs``. Data was imported as a DataFrame called `extracted_data`. As shown in this cell, the dataset has been automatically loaded in for you. You do not need to download the .csv file, or provide more code, in order to access the dataset and proceed with this lab. Please continue with this activity by completing the following instructions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "id": "4ebqpNcm4BDH"
   },
   "outputs": [],
   "source": [
    "# RUN THIS CELL TO IMPORT YOUR DATA.\n",
    "# Load extracted_nba_players_data.csv into a DataFrame called extracted_data.\n",
    "\n",
    "df = pd.read_csv('extracted_nba_players_data.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "yXvtnFn5oBIG"
   },
   "source": [
    "### Display the data\n",
    "\n",
    "Review the first 10 rows of data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "id": "JWu8u19C2sn1"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fg</th>\n",
       "      <th>3p</th>\n",
       "      <th>ft</th>\n",
       "      <th>reb</th>\n",
       "      <th>ast</th>\n",
       "      <th>stl</th>\n",
       "      <th>blk</th>\n",
       "      <th>tov</th>\n",
       "      <th>target_5yrs</th>\n",
       "      <th>total_points</th>\n",
       "      <th>efficiency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>34.7</td>\n",
       "      <td>25.0</td>\n",
       "      <td>69.9</td>\n",
       "      <td>4.1</td>\n",
       "      <td>1.9</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.4</td>\n",
       "      <td>1.3</td>\n",
       "      <td>0</td>\n",
       "      <td>266.4</td>\n",
       "      <td>0.270073</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>29.6</td>\n",
       "      <td>23.5</td>\n",
       "      <td>76.5</td>\n",
       "      <td>2.4</td>\n",
       "      <td>3.7</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1.6</td>\n",
       "      <td>0</td>\n",
       "      <td>252.0</td>\n",
       "      <td>0.267658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>42.2</td>\n",
       "      <td>24.4</td>\n",
       "      <td>67.0</td>\n",
       "      <td>2.2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>384.8</td>\n",
       "      <td>0.339869</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>42.6</td>\n",
       "      <td>22.6</td>\n",
       "      <td>68.9</td>\n",
       "      <td>1.9</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>330.6</td>\n",
       "      <td>0.491379</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>52.4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>67.4</td>\n",
       "      <td>2.5</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.8</td>\n",
       "      <td>1</td>\n",
       "      <td>216.0</td>\n",
       "      <td>0.391304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>42.3</td>\n",
       "      <td>32.5</td>\n",
       "      <td>73.2</td>\n",
       "      <td>0.8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0</td>\n",
       "      <td>277.5</td>\n",
       "      <td>0.324561</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>43.5</td>\n",
       "      <td>50.0</td>\n",
       "      <td>81.1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.7</td>\n",
       "      <td>1</td>\n",
       "      <td>409.2</td>\n",
       "      <td>0.605505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>41.5</td>\n",
       "      <td>30.0</td>\n",
       "      <td>87.5</td>\n",
       "      <td>1.7</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.7</td>\n",
       "      <td>1</td>\n",
       "      <td>273.6</td>\n",
       "      <td>0.553398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>39.2</td>\n",
       "      <td>23.3</td>\n",
       "      <td>71.4</td>\n",
       "      <td>0.8</td>\n",
       "      <td>2.3</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0</td>\n",
       "      <td>156.0</td>\n",
       "      <td>0.242424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>38.3</td>\n",
       "      <td>21.4</td>\n",
       "      <td>67.8</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0</td>\n",
       "      <td>155.4</td>\n",
       "      <td>0.435294</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     fg    3p    ft  reb  ast  stl  blk  tov  target_5yrs  total_points  \\\n",
       "0  34.7  25.0  69.9  4.1  1.9  0.4  0.4  1.3            0         266.4   \n",
       "1  29.6  23.5  76.5  2.4  3.7  1.1  0.5  1.6            0         252.0   \n",
       "2  42.2  24.4  67.0  2.2  1.0  0.5  0.3  1.0            0         384.8   \n",
       "3  42.6  22.6  68.9  1.9  0.8  0.6  0.1  1.0            1         330.6   \n",
       "4  52.4   0.0  67.4  2.5  0.3  0.3  0.4  0.8            1         216.0   \n",
       "5  42.3  32.5  73.2  0.8  1.8  0.4  0.0  0.7            0         277.5   \n",
       "6  43.5  50.0  81.1  2.0  0.6  0.2  0.1  0.7            1         409.2   \n",
       "7  41.5  30.0  87.5  1.7  0.2  0.2  0.1  0.7            1         273.6   \n",
       "8  39.2  23.3  71.4  0.8  2.3  0.3  0.0  1.1            0         156.0   \n",
       "9  38.3  21.4  67.8  1.1  0.3  0.2  0.0  0.7            0         155.4   \n",
       "\n",
       "   efficiency  \n",
       "0    0.270073  \n",
       "1    0.267658  \n",
       "2    0.339869  \n",
       "3    0.491379  \n",
       "4    0.391304  \n",
       "5    0.324561  \n",
       "6    0.605505  \n",
       "7    0.553398  \n",
       "8    0.242424  \n",
       "9    0.435294  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Display the first 10 rows of data.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "df.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "4zz8claq0Swi"
   },
   "source": [
    "## Step 2: Model preparation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "8kgPx_MP0cuc"
   },
   "source": [
    "### Isolate your target and predictor variables\n",
    "Separately define the target variable (`target_5yrs`) and the features."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "id": "xO46EzS8oBIG"
   },
   "outputs": [],
   "source": [
    "# Define the y (target) variable.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "y = df[['target_5yrs']]\n",
    "\n",
    "# Define the X (predictor) variables.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "X = df.drop(columns='target_5yrs')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "CzQNmlZ75e_Y"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 1</strong></h4></summary>\n",
    "\n",
    "Refer to [the content about splitting your data into X and y](https://www.coursera.org/learn/the-nuts-and-bolts-of-machine-learning/lecture/VxbUT/construct-a-naive-bayes-model-with-python).\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WWXkObsg5gzd"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 2</strong></h4></summary>\n",
    "\n",
    "In `pandas`, subset your DataFrame by using square brackets `[]` to specify which column(s) to select.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "JU9z6ufC5n58"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 3</strong></h4></summary>\n",
    "\n",
    "Quickly subset a DataFrame to exclude a particular column by using the `drop()` function and specifying the column to drop.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "xj8-Pb0N-rjW"
   },
   "source": [
    "### Display the first 10 rows of your target data\n",
    "\n",
    "Display the first 10 rows of your target and predictor variables. This will help you get a sense of how the data is structured."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "id": "pivKfaxQ5uHZ"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>target_5yrs</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   target_5yrs\n",
       "0            0\n",
       "1            0\n",
       "2            0\n",
       "3            1\n",
       "4            1\n",
       "5            0\n",
       "6            1\n",
       "7            1\n",
       "8            0\n",
       "9            0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Display the first 10 rows of your target data.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "y.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "oDls2RifZhu2"
   },
   "source": [
    "**Question:** What do you observe about the your target variable?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "sc4IshYKzENq"
   },
   "source": "The target is a binary (Boolean) variable. In the first 10 rows, 4 are 1 and 6 are 0, so it looks reasonably balanced — although 10 rows are too few to judge the full distribution."
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "id": "2kDZK5qe-4B0"
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fg</th>\n",
       "      <th>3p</th>\n",
       "      <th>ft</th>\n",
       "      <th>reb</th>\n",
       "      <th>ast</th>\n",
       "      <th>stl</th>\n",
       "      <th>blk</th>\n",
       "      <th>tov</th>\n",
       "      <th>total_points</th>\n",
       "      <th>efficiency</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>34.7</td>\n",
       "      <td>25.0</td>\n",
       "      <td>69.9</td>\n",
       "      <td>4.1</td>\n",
       "      <td>1.9</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.4</td>\n",
       "      <td>1.3</td>\n",
       "      <td>266.4</td>\n",
       "      <td>0.270073</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>29.6</td>\n",
       "      <td>23.5</td>\n",
       "      <td>76.5</td>\n",
       "      <td>2.4</td>\n",
       "      <td>3.7</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1.6</td>\n",
       "      <td>252.0</td>\n",
       "      <td>0.267658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>42.2</td>\n",
       "      <td>24.4</td>\n",
       "      <td>67.0</td>\n",
       "      <td>2.2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>384.8</td>\n",
       "      <td>0.339869</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>42.6</td>\n",
       "      <td>22.6</td>\n",
       "      <td>68.9</td>\n",
       "      <td>1.9</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>330.6</td>\n",
       "      <td>0.491379</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>52.4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>67.4</td>\n",
       "      <td>2.5</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.8</td>\n",
       "      <td>216.0</td>\n",
       "      <td>0.391304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>42.3</td>\n",
       "      <td>32.5</td>\n",
       "      <td>73.2</td>\n",
       "      <td>0.8</td>\n",
       "      <td>1.8</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>277.5</td>\n",
       "      <td>0.324561</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>43.5</td>\n",
       "      <td>50.0</td>\n",
       "      <td>81.1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.7</td>\n",
       "      <td>409.2</td>\n",
       "      <td>0.605505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>41.5</td>\n",
       "      <td>30.0</td>\n",
       "      <td>87.5</td>\n",
       "      <td>1.7</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.7</td>\n",
       "      <td>273.6</td>\n",
       "      <td>0.553398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>39.2</td>\n",
       "      <td>23.3</td>\n",
       "      <td>71.4</td>\n",
       "      <td>0.8</td>\n",
       "      <td>2.3</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.1</td>\n",
       "      <td>156.0</td>\n",
       "      <td>0.242424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>38.3</td>\n",
       "      <td>21.4</td>\n",
       "      <td>67.8</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>155.4</td>\n",
       "      <td>0.435294</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     fg    3p    ft  reb  ast  stl  blk  tov  total_points  efficiency\n",
       "0  34.7  25.0  69.9  4.1  1.9  0.4  0.4  1.3         266.4    0.270073\n",
       "1  29.6  23.5  76.5  2.4  3.7  1.1  0.5  1.6         252.0    0.267658\n",
       "2  42.2  24.4  67.0  2.2  1.0  0.5  0.3  1.0         384.8    0.339869\n",
       "3  42.6  22.6  68.9  1.9  0.8  0.6  0.1  1.0         330.6    0.491379\n",
       "4  52.4   0.0  67.4  2.5  0.3  0.3  0.4  0.8         216.0    0.391304\n",
       "5  42.3  32.5  73.2  0.8  1.8  0.4  0.0  0.7         277.5    0.324561\n",
       "6  43.5  50.0  81.1  2.0  0.6  0.2  0.1  0.7         409.2    0.605505\n",
       "7  41.5  30.0  87.5  1.7  0.2  0.2  0.1  0.7         273.6    0.553398\n",
       "8  39.2  23.3  71.4  0.8  2.3  0.3  0.0  1.1         156.0    0.242424\n",
       "9  38.3  21.4  67.8  1.1  0.3  0.2  0.0  0.7         155.4    0.435294"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Display the first 10 rows of your predictor variables.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "X.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Albdy39HZwQT"
   },
   "source": [
    "**Question:** What do you observe about the your predictor variables?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "oD5l-FnazDYh"
   },
   "source": "All predictors are continuous. They sit on very different scales (`total_points` in the hundreds, `efficiency` below 1). That matters for distance-based models, but Gaussian Naive Bayes fits a separate mean and variance for each feature, so scaling does not change its predictions."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "cQ-wo4UOoBII"
   },
   "source": [
    "### Perform a split operation on your data\n",
    "\n",
    "Divide your data into a training set (75% of data) and test set (25% of data). This is an important step in the process, as it allows you to reserve a part of the data that the model has not observed. This tests how well the model generalizes—or performs—on new data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "id": "pO2AdPR7oBIJ"
   },
   "outputs": [],
   "source": [
    "# Perform the split operation on your data.\n",
    "# Assign the outputs as follows: X_train, X_test, y_train, y_test.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.25, random_state=42)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "DgY9icEY2mKn"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 1</strong></h4></summary>\n",
    "\n",
    "Refer to [the content about splitting your data between a training and test set](https://www.coursera.org/learn/the-nuts-and-bolts-of-machine-learning/lecture/VxbUT/construct-a-naive-bayes-model-with-python).\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "pUmzKZUU2mKp"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 2</strong></h4></summary>\n",
    "\n",
    "Call the function in the `model_selection` module of `sklearn` on the features and target variable, in order to perform the splitting.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ORy1MNR62mKq"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 3</strong></h4></summary>\n",
    "\n",
    "Call the `model_selection.train_test_split()` function, passing in both `features` and `target`, while configuring the appropriate `test_size`.\n",
    "\n",
    "Assign the output of this split as `X_train`, `X_test`, `y_train`, `y_test`.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Gjasizab0tSL"
   },
   "source": [
    "### Print the shape of each output \n",
    "\n",
    "Print the shape of each output from your train-test split. This will verify that the split operated as expected."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "id": "xtxpSjCm4jCa"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1005, 10)\n",
      "(335, 10)\n",
      "(1005, 1)\n",
      "(335, 1)\n"
     ]
    }
   ],
   "source": [
    "# Print the shape (rows, columns) of the output from the train-test split.\n",
    "\n",
    "# Print the shape of X_train.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "print(X_train.shape)\n",
    "\n",
    "\n",
    "# Print the shape of X_test.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "print(X_test.shape)\n",
    "\n",
    "\n",
    "# Print the shape of y_train.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "print(y_train.shape)\n",
    "\n",
    "\n",
    "# Print the shape of y_test.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "print(y_test.shape)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "dx8DO1Rw2ZBZ"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 1</strong></h4></summary>\n",
    "\n",
    "Call the attribute that DataFrames in `pandas` have to get the number of rows and number of columns as a tuple.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "G9pDSxlG2di1"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 2</strong></h4></summary>\n",
    "\n",
    "Call the `shape` attribute.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "zZndsnPq1UyL"
   },
   "source": [
    "**Question:** How many rows are in each of the outputs?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "74-KZfWUzBeV"
   },
   "source": "The training set has 1,005 rows and the test set has 335. Both keep the 10 predictor columns."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "_G5xBrJAZwlE"
   },
   "source": [
    "**Question:** What was the effect of the train-test split?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "w6MlJiZNzA9A"
   },
   "source": "The split randomly divided the dataset into two groups: 75% for training and 25% held out for testing, so the model is evaluated on players it has never seen."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "MY0rAjlZAheh"
   },
   "source": [
    "## Step 3: Model building"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "YS06KhTSoBIM"
   },
   "source": [
    "**Question:** Which Naive Bayes algorithm should you use?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ajt2BYgjzALD"
   },
   "source": "The target is binary and the predictors are continuous. Naive Bayes is a classification algorithm, which fits the binary target, and the variant built for continuous inputs — it assumes each feature is normally distributed within each class — is Gaussian Naive Bayes."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "OOBvfCNeoBIM"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 1</strong></h4></summary>\n",
    "\n",
    "Refer to [the content about different implementations of the Naive Bayes](https://www.coursera.org/learn/the-nuts-and-bolts-of-machine-learning/supplement/1zfDy/naive-bayes-classifiers) to determine which is appropriate in this situation.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "gzT16WHjoBIM"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 2</strong></h4></summary>\n",
    "\n",
    "Note that you are performing binary classification.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "IILInxLYoBIN"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 3</strong></h4></summary>\n",
    "\n",
    "You can identify the appropriate algorithm to use because you are performing a binary classification and assuming that the features of your model follow a normal distribution.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "m5EFtZfXoBIN"
   },
   "source": [
    "### Fit your model to your training data and predict on your test data\n",
    "\n",
    "By creating your model, you will be drawing on your feature engineering work by training the classifier on the `X_train` DataFrame. You will use this to predict `target_5yrs` from `y_train`.\n",
    "\n",
    "Start by defining `nb` to be the relevant algorithm from `sklearn`.`naive_bayes`. Then fit your model to your training data. Use this fitted model to create predictions for your test data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "id": "gUEgzQW_6oMV"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0,\n",
       "       0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1,\n",
       "       1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1,\n",
       "       1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0,\n",
       "       1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0,\n",
       "       0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1,\n",
       "       1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "       1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0,\n",
       "       0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,\n",
       "       1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0,\n",
       "       0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0,\n",
       "       1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0,\n",
       "       0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1,\n",
       "       0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1,\n",
       "       0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0,\n",
       "       1, 1, 0, 1, 0])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Assign `nb` to be the appropriate implementation of Naive Bayes.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "nb = GaussianNB()\n",
    "\n",
    "\n",
    "# Fit the model on your training data.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "\n",
    "nb.fit(X_train, y_train)\n",
    "\n",
    "# Apply your model to predict on your test data. Call this \"y_pred\".\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "y_pred = nb.predict(X_test)\n",
    "\n",
    "y_pred"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "l2vRT5XeoBIN"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 1</strong></h4></summary>\n",
    "\n",
    "Refer to [the content about constructing a Naive Bayes](https://www.coursera.org/learn/the-nuts-and-bolts-of-machine-learning/lecture/VxbUT/construct-a-naive-bayes-model-with-python).\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Vo1E7RjtoBIN"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 2</strong></h4></summary>\n",
    "\n",
    "The appropriate implementation in this case is `naive_bayes`.`GaussianNB()`. Fit this model to your training data and predict on your test data.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "azSq51xXoBIN"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 3</strong></h4></summary>\n",
    "\n",
    "Call `fit()`and pass your training feature set and target variable. Then call `predict()` on your test feature set.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qgV_6xAQAvgg"
   },
   "source": [
    "## Step 4: Results and evaluation\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "XPswDdr1oBIO"
   },
   "source": [
    "### Leverage metrics to evaluate your model's performance\n",
    "\n",
    "To evaluate the data yielded from your model, you can leverage a series of metrics and evaluation techniques from scikit-learn by examining the actual observed values in the test set relative to your model's prediction. Specifically, print the accuracy score, precision score, recall score, and f1 score associated with your test data and predicted values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "id": "INf2Rd_MoBIP"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.6537313432835821\n",
      "0.8382352941176471\n",
      "0.5480769230769231\n",
      "0.6627906976744187\n"
     ]
    }
   ],
   "source": [
    "# Print your accuracy score.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "print(accuracy_score(y_test,y_pred))\n",
    "\n",
    "\n",
    "# Print your precision score.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "print(precision_score(y_test,y_pred))\n",
    "\n",
    "\n",
    "# Print your recall score.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "print(recall_score(y_test,y_pred))\n",
    "\n",
    "\n",
    "# Print your f1 score.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "print(f1_score(y_test,y_pred))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "mEgb0a2YoBIP"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 1</strong></h4></summary>\n",
    "\n",
    "Refer to [the content about model evaluation](https://www.coursera.org/learn/the-nuts-and-bolts-of-machine-learning/lecture/EITmV/key-evaluation-metrics-for-classification-models) for detail on these metrics.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "oT143KsSoBIP"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 2</strong></h4></summary>\n",
    "\n",
    "The `metrics` module in `sklearn` has a function for computing each of these metrics.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "BECv4a2toBIP"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 3</strong></h4></summary>\n",
    "\n",
    "Call `accuracy_score()`, `precision_score()`, `recall_score()`, and `f1_score()`, passing `y_test`, and `y_pred` into each function.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "dDx7rrdNoBIP"
   },
   "source": [
    "**Question:** What is the accuracy score for your model, and what does this tell you about the success of the model's performance?\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "oD9Wu2eEy-CC"
   },
   "source": "Accuracy is the share of all predictions that were correct. About 65.4% of players were classified correctly, which is not very high. For context, 62% of the test set lasted five years or more, so always predicting \"yes\" would already score 62%: the model adds only about 3 points over that baseline."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "x3O1G_TIaaGw"
   },
   "source": [
    "**Question:** Can you evaluate the success of your model by using the accuracy score exclusively?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Fd9zpsZFy9cP"
   },
   "source": "No. Accuracy alone doesn't tell the whole story: depending on class imbalance, a model can score well while producing many false positives or false negatives. Precision, recall and F1 are needed to confirm or rule that out."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "evpAa_4noBIP"
   },
   "source": [
    "**Question:** What are the precision and recall scores for your model, and what do they mean? Is one of these scores more accurate than the other?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Di-uEPDTy8MW"
   },
   "source": "Precision is the share of predicted positives that were actually positive: 83.8% of the players the model said would last five years did. Recall is the share of actual positives the model found: 54.8%, which is fairly low. The model is reluctant to predict a long career, but when it does, it is usually right.\n\nNeither score is \"more accurate\" than the other — each measures a different kind of error, and which one matters more depends on what that error costs. Here the main problem is false negatives: the model misses almost half of the players who do last."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "7ghkTwSUoBIP"
   },
   "source": [
    "**Question:** What is the F1 score of your model, and what does this score mean?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GEUUWvrmy7aE"
   },
   "source": "The F1 score is 66.3%. It is the harmonic mean of precision and recall, so it combines both into one score when they matter equally. The gap between precision (0.84) and recall (0.55) is what pulls it down."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "mNzDfI3RoBIQ"
   },
   "source": [
    "### Gain clarity with the confusion matrix\n",
    "\n",
    "Recall that a confusion matrix is a graphic that shows your model's true and false positives and negatives. It helps to create a visual representation of the components feeding into the metrics.\n",
    "\n",
    "Create a confusion matrix based on your predicted values for the test set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "id": "ntoJ-YG7oBIQ"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at 0x79655073d690>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {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AeSro39ImL1emLJ/OyfpAkkyXK/iHhb0nSgZwenR3rdZet+D8w64j644rkXOF1SdwBJO0nqAzwAHJf20Q0DDlzPZx8C/knSqPSzA9P9K4CGduf9iaS5SHre2oTzAHBiuu8wYMAGYt0SWJomt51JapBrdQPW1kJPIGn6LgdekTQpvYYk7bmBa9hmzAmueC4n6V+bkS6c8iuSmvofgVnAM8ClwF/X/WBEvEnSb3azpKd4r4l4O3D02kEG4Exgn3QQ4zneG839EXCApBkkTeU5G4j1HqBe0tPAj4F/tDu2CthV0uMkfWznpftPBE5O43sWTwNvnfBsImZWWK7BmVlhOcGZWWE5wZlZYTnBmVlhOcGZWWE5wZlZYTnBmVlh/X9aLdW6qXPObgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Construct and display your confusion matrix.\n",
    "\n",
    "# Construct the confusion matrix for your predicted and test values.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "cm = confusion_matrix(y_test,y_pred, labels=nb.classes_)\n",
    "\n",
    "\n",
    "# Create the display for your confusion matrix.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=nb.classes_)\n",
    "\n",
    "\n",
    "# Plot the visual in-line.\n",
    "\n",
    "### YOUR CODE HERE ###\n",
    "disp.plot()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "b2lqmzQ-oBIQ"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 1</strong></h4></summary>\n",
    "\n",
    "The `metrics` module has functions to create a confusion matrix.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Wi_x2zTDoBIQ"
   },
   "source": [
    "<details>\n",
    "<summary><h4><strong>Hint 2</strong></h4></summary>\n",
    "\n",
    "Call `confusion_matrix`, passing in `y_test` and `y_pred`. Then, utilize `ConfusionMatrixDisplay()` to display your confusion matrix.\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "aLkF5znkNk7m"
   },
   "source": [
    "**Question:** What do you notice when observing your confusion matrix, and does this correlate to any of your other calculations?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "EA2eAI9Dy6OJ"
   },
   "source": "At first glance the matrix looks reasonable, but there are 94 false negatives — players who lasted five years or more that the model said would not — against only 22 false positives. This matches the metrics: high precision, low recall."
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "xur2FC5xAzp0"
   },
   "source": "## Considerations\n\n**What are some key takeaways that you learned from this lab?**\n\nGaussian Naive Bayes is a fast, effective baseline for classification with continuous features. Its \"naive\" assumption — that features are independent of each other — does not hold here: `total_points` and `efficiency` are derived from other columns, which likely limits performance.\n\n**How would you present your results to your team?**\n\nTrue positives, true negatives and false negatives are of similar size. Precision is high, but recall is low and accuracy is only about 3 points above always predicting the majority class, so the model is not yet reliable for predicting five-year careers.\n\n**How would you summarize your findings to stakeholders?**\n\nThe model misses too many players who do go on to last five years, but when it predicts a long career it is right about 84% of the time. It could support decisions where a confident \"yes\" is what matters, but it should not be used to rule players out.\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Congratulations!** You've completed this lab. However, you may not notice a green check mark next to this item on Coursera's platform. Please continue your progress regardless of the check mark. Just click on the \"save\" icon at the top of this notebook to ensure your work has been logged"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}