{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "DtNBZFHO3M7n"
   },
   "source": [
    "# **Waze Project**\n",
    "**Course 3 - The Power of Statistics**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WVeXS7BNzX6e"
   },
   "source": [
    "Your team is nearing the midpoint of their user churn project. So far, you’ve completed a project proposal, and used Python to explore and analyze Waze’s user data. You’ve also used Python to create data visualizations. The next step is to use statistical methods to analyze and interpret your data.\n",
    "\n",
    "You receive a new email from Sylvester Esperanza, your project manager. Sylvester tells your team about a new request from leadership: to analyze the relationship between mean amount of rides and device type. You also discover follow-up emails from three other team members: May Santner, Chidi Ga, and Harriet Hadzic. These emails discuss the details of the analysis. They would like a statistical analysis of ride data based on device type. In particular, leadership wants to know if there is a statistically significant difference in mean amount of rides between iPhone® users and Android™ users. A final email from Chidi includes your specific assignment: to conduct a two-sample hypothesis test (t-test) to analyze the difference in the mean amount of rides between iPhone users and Android users.\n",
    "\n",
    "A notebook was structured and prepared to help you in this project. Please complete the following questions and prepare an executive summary."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "rgSbVJvomcVa"
   },
   "source": [
    "# **Course 3 End-of-course project: Data exploration and hypothesis testing**\n",
    "\n",
    "In this activity, you will explore the data provided and conduct a hypothesis test.\n",
    "<br/>\n",
    "\n",
    "**The purpose** of this project is to demonstrate knowledge of how to conduct a two-sample hypothesis test.\n",
    "\n",
    "**The goal** is to apply descriptive statistics and hypothesis testing in Python.\n",
    "<br/>\n",
    "\n",
    "*This activity has three parts:*\n",
    "\n",
    "**Part 1:** Imports and data loading\n",
    "* What data packages will be necessary for hypothesis testing?\n",
    "\n",
    "**Part 2:** Conduct hypothesis testing\n",
    "* How did computing descriptive statistics help you analyze your data?\n",
    "\n",
    "* How did you formulate your null hypothesis and alternative hypothesis?\n",
    "\n",
    "**Part 3:** Communicate insights with stakeholders\n",
    "\n",
    "* What key business insight(s) emerged from your hypothesis test?\n",
    "\n",
    "* What business recommendations do you propose based on your results?\n",
    "\n",
    "<br/>\n",
    "\n",
    "\n",
    "Follow the instructions and answer the questions below to complete the activity. Then, you will complete an Executive Summary using the questions listed on the PACE Strategy Document.\n",
    "\n",
    "Be sure to complete this activity before moving on. The next course item will provide you with a completed exemplar to compare to your own work.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "9GHVSxqehVpv"
   },
   "source": [
    "# **Data exploration and hypothesis testing**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "N8qrn_UAzX6j"
   },
   "source": [
    "<img src=\"images/Pace.png\" width=\"100\" height=\"100\" align=left>\n",
    "\n",
    "# **PACE stages**\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WQ1oMthKhfzP"
   },
   "source": [
    "Throughout these project notebooks, you'll see references to the problem-solving framework PACE. The following notebook components are labeled with the respective PACE stage: Plan, Analyze, Construct, and Execute."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Bb1HNu3FzX6k"
   },
   "source": [
    "<img src=\"images/Plan.png\" width=\"100\" height=\"100\" align=left>\n",
    "\n",
    "\n",
    "## **PACE: Plan**\n",
    "\n",
    "Consider the questions in your PACE Strategy Document and those below to craft your response:\n",
    "1. What is your research question for this data project? Later on, you will need to formulate the null and alternative hypotheses as the first step of your hypothesis test. Consider your research question now, at the start of this task.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "F6_h60RuXQIz"
   },
   "source": [
    "To determine if there is a statistically significant difference in mean amount of rides between iPhone® users and Android™ users."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Kp3uDhhSg_qu"
   },
   "source": [
    "*Complete the following tasks to perform statistical analysis of your data:*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "xgQEdIN7f1Jq"
   },
   "source": [
    "### **Task 1. Imports and data loading**\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ehehvUzFj0-e"
   },
   "source": [
    "Import packages and libraries needed to compute descriptive statistics and conduct a hypothesis test."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "e6cryW4WgiIL"
   },
   "source": [
    "<details>\n",
    "  <summary><h4><strong>Hint:</strong></h4></summary>\n",
    "\n",
    "Before you begin, recall the following Python packages and functions:\n",
    "\n",
    "*Main functions*: stats.ttest_ind(a, b, equal_var)\n",
    "\n",
    "*Other functions*: mean()\n",
    "\n",
    "*Packages*: pandas, stats.scipy\n",
    "\n",
    "</details>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "id": "1Q-GL2UrgWWG"
   },
   "outputs": [],
   "source": [
    "# Import any relevant packages or libraries\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from scipy import stats"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "stMe9uT3kOmF"
   },
   "source": [
    "Import the dataset.\n",
    "\n",
    "**Note:** 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": "2qAt6Upaeg6U"
   },
   "outputs": [],
   "source": [
    "# Load dataset into dataframe\n",
    "df = pd.read_csv('waze_dataset.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "c8paWsdKzX6o"
   },
   "source": [
    "<img src=\"images/Analyze.png\" width=\"100\" height=\"100\" align=left>\n",
    "\n",
    "<img src=\"images/Construct.png\" width=\"100\" height=\"100\" align=left>\n",
    "\n",
    "## **PACE: Analyze and Construct**\n",
    "\n",
    "Consider the questions in your PACE Strategy Document and those below to craft your response:\n",
    "1. Data professionals use descriptive statistics for exploratory data analysis (EDA). How can computing descriptive statistics help you learn more about your data in this stage of your analysis?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "rX5xJnWUXxsW"
   },
   "source": [
    "Descriptive statistics are used to explore and summarize data."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "UKhYTdVhf5B2"
   },
   "source": [
    "### **Task 2. Data exploration**\n",
    "\n",
    "Use descriptive statistics to conduct exploratory data analysis (EDA)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "AzYm91yQrS9s"
   },
   "source": [
    "<details>\n",
    "  <summary><h4><strong>Hint:</strong></h4></summary>\n",
    "\n",
    "Refer back to *Self Review Descriptive Statistics* for this step-by-step proccess.\n",
    "\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "JAq7ag0pTNgl"
   },
   "source": [
    "**Note:** In the dataset, `device` is a categorical variable with the labels `iPhone` and `Android`.\n",
    "\n",
    "In order to perform this analysis, you must turn each label into an integer.  The following code assigns a `1` for an `iPhone` user and a `2` for `Android`.  It assigns this label back to the variable `device_new`.\n",
    "\n",
    "**Note:** Creating a new variable is ideal so that you don't overwrite original data.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GaJ4golwD8et"
   },
   "source": [
    "1. Create a dictionary called `map_dictionary` that contains the class labels (`'Android'` and `'iPhone'`) for keys and the values you want to convert them to (`2` and `1`) as values.\n",
    "\n",
    "2. Create a new column called `device_type` that is a copy of the `device` column.\n",
    "\n",
    "3. Use the [`map()`](https://pandas.pydata.org/docs/reference/api/pandas.Series.map.html#pandas-series-map) method on the `device_type` series. Pass `map_dictionary` as its argument. Reassign the result back to the `device_type` series.\n",
    "</br></br>\n",
    "When you pass a dictionary to the `Series.map()` method, it will replace the data in the series where that data matches the dictionary's keys. The values that get imputed are the values of the dictionary.\n",
    "\n",
    "```\n",
    "Example:\n",
    "df['column']\n",
    "```\n",
    "\n",
    "|column |\n",
    "|  :-:       |\n",
    "| A     |\n",
    "| B     |\n",
    "| A     |\n",
    "| B     |\n",
    "\n",
    "```\n",
    "map_dictionary = {'A': 2, 'B': 1}\n",
    "df['column'] = df['column'].map(map_dictionary)\n",
    "df['column']\n",
    "```\n",
    "\n",
    "|column |\n",
    "|  :-: |\n",
    "| 2    |\n",
    "| 1    |\n",
    "| 2    |\n",
    "| 1    |\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "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>ID</th>\n",
       "      <th>label</th>\n",
       "      <th>sessions</th>\n",
       "      <th>drives</th>\n",
       "      <th>total_sessions</th>\n",
       "      <th>n_days_after_onboarding</th>\n",
       "      <th>total_navigations_fav1</th>\n",
       "      <th>total_navigations_fav2</th>\n",
       "      <th>driven_km_drives</th>\n",
       "      <th>duration_minutes_drives</th>\n",
       "      <th>activity_days</th>\n",
       "      <th>driving_days</th>\n",
       "      <th>device</th>\n",
       "      <th>device_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14299</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999.000000</td>\n",
       "      <td>14999</td>\n",
       "      <td>14999.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>unique</th>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>NaN</td>\n",
       "      <td>retained</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>iPhone</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>freq</th>\n",
       "      <td>NaN</td>\n",
       "      <td>11763</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9672</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>7499.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>80.633776</td>\n",
       "      <td>67.281152</td>\n",
       "      <td>189.964447</td>\n",
       "      <td>1749.837789</td>\n",
       "      <td>121.605974</td>\n",
       "      <td>29.672512</td>\n",
       "      <td>4039.340921</td>\n",
       "      <td>1860.976012</td>\n",
       "      <td>15.537102</td>\n",
       "      <td>12.179879</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.355157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>4329.982679</td>\n",
       "      <td>NaN</td>\n",
       "      <td>80.699065</td>\n",
       "      <td>65.913872</td>\n",
       "      <td>136.405128</td>\n",
       "      <td>1008.513876</td>\n",
       "      <td>148.121544</td>\n",
       "      <td>45.394651</td>\n",
       "      <td>2502.149334</td>\n",
       "      <td>1446.702288</td>\n",
       "      <td>9.004655</td>\n",
       "      <td>7.824036</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.478577</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.220211</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>60.441250</td>\n",
       "      <td>18.282082</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>3749.500000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>90.661156</td>\n",
       "      <td>878.000000</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2212.600607</td>\n",
       "      <td>835.996260</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>7499.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>56.000000</td>\n",
       "      <td>48.000000</td>\n",
       "      <td>159.568115</td>\n",
       "      <td>1741.000000</td>\n",
       "      <td>71.000000</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>3493.858085</td>\n",
       "      <td>1478.249859</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>11248.500000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>112.000000</td>\n",
       "      <td>93.000000</td>\n",
       "      <td>254.192341</td>\n",
       "      <td>2623.500000</td>\n",
       "      <td>178.000000</td>\n",
       "      <td>43.000000</td>\n",
       "      <td>5289.861262</td>\n",
       "      <td>2464.362632</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>14998.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>743.000000</td>\n",
       "      <td>596.000000</td>\n",
       "      <td>1216.154633</td>\n",
       "      <td>3500.000000</td>\n",
       "      <td>1236.000000</td>\n",
       "      <td>415.000000</td>\n",
       "      <td>21183.401890</td>\n",
       "      <td>15851.727160</td>\n",
       "      <td>31.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  ID     label      sessions        drives  total_sessions  \\\n",
       "count   14999.000000     14299  14999.000000  14999.000000    14999.000000   \n",
       "unique           NaN         2           NaN           NaN             NaN   \n",
       "top              NaN  retained           NaN           NaN             NaN   \n",
       "freq             NaN     11763           NaN           NaN             NaN   \n",
       "mean     7499.000000       NaN     80.633776     67.281152      189.964447   \n",
       "std      4329.982679       NaN     80.699065     65.913872      136.405128   \n",
       "min         0.000000       NaN      0.000000      0.000000        0.220211   \n",
       "25%      3749.500000       NaN     23.000000     20.000000       90.661156   \n",
       "50%      7499.000000       NaN     56.000000     48.000000      159.568115   \n",
       "75%     11248.500000       NaN    112.000000     93.000000      254.192341   \n",
       "max     14998.000000       NaN    743.000000    596.000000     1216.154633   \n",
       "\n",
       "        n_days_after_onboarding  total_navigations_fav1  \\\n",
       "count              14999.000000            14999.000000   \n",
       "unique                      NaN                     NaN   \n",
       "top                         NaN                     NaN   \n",
       "freq                        NaN                     NaN   \n",
       "mean                1749.837789              121.605974   \n",
       "std                 1008.513876              148.121544   \n",
       "min                    4.000000                0.000000   \n",
       "25%                  878.000000                9.000000   \n",
       "50%                 1741.000000               71.000000   \n",
       "75%                 2623.500000              178.000000   \n",
       "max                 3500.000000             1236.000000   \n",
       "\n",
       "        total_navigations_fav2  driven_km_drives  duration_minutes_drives  \\\n",
       "count             14999.000000      14999.000000             14999.000000   \n",
       "unique                     NaN               NaN                      NaN   \n",
       "top                        NaN               NaN                      NaN   \n",
       "freq                       NaN               NaN                      NaN   \n",
       "mean                 29.672512       4039.340921              1860.976012   \n",
       "std                  45.394651       2502.149334              1446.702288   \n",
       "min                   0.000000         60.441250                18.282082   \n",
       "25%                   0.000000       2212.600607               835.996260   \n",
       "50%                   9.000000       3493.858085              1478.249859   \n",
       "75%                  43.000000       5289.861262              2464.362632   \n",
       "max                 415.000000      21183.401890             15851.727160   \n",
       "\n",
       "        activity_days  driving_days  device   device_type  \n",
       "count    14999.000000  14999.000000   14999  14999.000000  \n",
       "unique            NaN           NaN       2           NaN  \n",
       "top               NaN           NaN  iPhone           NaN  \n",
       "freq              NaN           NaN    9672           NaN  \n",
       "mean        15.537102     12.179879     NaN      1.355157  \n",
       "std          9.004655      7.824036     NaN      0.478577  \n",
       "min          0.000000      0.000000     NaN      1.000000  \n",
       "25%          8.000000      5.000000     NaN      1.000000  \n",
       "50%         16.000000     12.000000     NaN      1.000000  \n",
       "75%         23.000000     19.000000     NaN      2.000000  \n",
       "max         31.000000     30.000000     NaN      2.000000  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe(include=\"all\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "id": "piHSZbnjEXw-"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2\n",
       "1    1\n",
       "2    2\n",
       "3    1\n",
       "4    2\n",
       "Name: device_type, dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. Create `map_dictionary`\n",
    "map_dictionary = {'Android': 2, 'iPhone': 1}\n",
    "# 2. Create new `device_type` column\n",
    "df['device_type'] = df['device'].copy()\n",
    "# 3. Map the new column to the dictionary\n",
    "df['device_type'] = df['device_type'].map(map_dictionary)\n",
    "df['device_type'].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "-fFiNg4hdGBK"
   },
   "source": [
    "You are interested in the relationship between device type and the number of drives. One approach is to look at the average number of drives for each device type. Calculate these averages."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "id": "2LGEWrdVXgI2"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "device_type\n",
       "1    67.859078\n",
       "2    66.231838\n",
       "Name: drives, dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(\"device_type\")[\"drives\"].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Z_u-zWvGdfII"
   },
   "source": [
    "Based on the averages shown, it appears that drivers who use an iPhone device to interact with the application have a higher number of drives on average. However, this difference might arise from random sampling, rather than being a true difference in the number of drives. To assess whether the difference is statistically significant, you can conduct a hypothesis test."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "QpFRQDaNzX6p"
   },
   "source": [
    "\n",
    "### **Task 3. Hypothesis testing**\n",
    "\n",
    "Your goal is to conduct a two-sample t-test. Recall the steps for conducting a hypothesis test:\n",
    "\n",
    "\n",
    "1.   State the null hypothesis and the alternative hypothesis\n",
    "2.   Choose a signficance level\n",
    "3.   Find the p-value\n",
    "4.   Reject or fail to reject the null hypothesis\n",
    "\n",
    "**Note:** This is a t-test for two independent samples. This is the appropriate test since the two groups are independent (Android users vs. iPhone users)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "phXxr74vVPrs"
   },
   "source": [
    "Recall the difference between the null hypothesis ($H_0$) and the alternative hypothesis ($H_A$).\n",
    "\n",
    "**Question:** What are your hypotheses for this data project?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "SkDeGggZYM84"
   },
   "source": [
    "$H_0$: There is no difference in the mean amount of rides between iPhone® users and Android™ users.\n",
    "\n",
    "$H_A$: There is a difference in the mean amount of rides between iPhone® users and Android™ users."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "IVHpnfvNeTUA"
   },
   "source": [
    "Next, choose 5% as the significance level and proceed with a two-sample t-test.\n",
    "\n",
    "You can use the `stats.ttest_ind()` function to perform the test.\n",
    "\n",
    "\n",
    "**Technical note**: The default for the argument `equal_var` in `stats.ttest_ind()` is `True`, which assumes population variances are equal. This equal variance assumption might not hold in practice (that is, there is no strong reason to assume that the two groups have the same variance); you can relax this assumption by setting `equal_var` to `False`, and `stats.ttest_ind()` will perform the unequal variances $t$-test (known as Welch's `t`-test). Refer to the [scipy t-test documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_ind.html) for more information.\n",
    "\n",
    "\n",
    "1. Isolate the `drives` column for iPhone users.\n",
    "2. Isolate the `drives` column for Android users.\n",
    "3. Perform the t-test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "id": "rdlsXg7Dhbrd"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Ttest_indResult(statistic=1.4635232068852353, pvalue=0.1433519726802059)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. Isolate the `drives` column for iPhone users.\n",
    "a = df[df[\"device_type\"] == 1][\"drives\"]\n",
    "# 2. Isolate the `drives` column for Android users.\n",
    "b = df[df[\"device_type\"] == 2][\"drives\"]\n",
    "# 3. Perform the t-test\n",
    "stats.ttest_ind(a=a, b=b, equal_var=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "64Wq_VSaVsNm"
   },
   "source": [
    "**Question:** Based on the p-value you got above, do you reject or fail to reject the null hypothesis?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "SGLHv2FY1P2-"
   },
   "source": [
    "With a p-value (0.1434) being higher than 0.05 (as the significance level is 5%), we fail to reject the null hypothesis.\n",
    "\n",
    "Therefore, we can conclude at the 5% significance level that there is no statistically significant difference in the mean amount of rides between iPhone® users and Android™ users."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Ab4e-W3mzX6r"
   },
   "source": [
    "<img src=\"images/Execute.png\" width=\"100\" height=\"100\" align=left>\n",
    "\n",
    "## **PACE: Execute**\n",
    "\n",
    "Consider the questions in your PACE Strategy Document to reflect on the Execute stage."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "h1PRfiD3hcwE"
   },
   "source": [
    "### **Task 4. Communicate insights with stakeholders**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "ItreFaZKhvVw"
   },
   "source": [
    "Now that you've completed your hypothesis test, the next step is to share your findings with the Waze leadership team. Consider the following question as you prepare to write your executive summary:\n",
    "\n",
    "* What business insight(s) can you draw from the result of your hypothesis test?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "-CgNingVY4Bw"
   },
   "source": [
    "We can conclude at the 5% significance level that there is no difference in the mean amount of rides between iPhone users and Android users of Waze.<br>\n",
    "One possible next step is to explore what other factors influence the variation in the number of drives, and run additional hypothesis tests to learn more about user behavior. Further, temporary changes in marketing or user interface for the Waze app may provide more data to investigate churn."
   ]
  },
  {
   "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": {
   "provenance": [
    {
     "file_id": "1VMShPM3amGvcOZx0J5yHz1kb04rzCFvN",
     "timestamp": 1671052168408
    },
    {
     "file_id": "1su07KaK4RI6MI85tMf2H19qop9LcqqDy",
     "timestamp": 1669648371757
    },
    {
     "file_id": "1f5FzGbEQi1DvhHY8u-K32sklfpgir_pK",
     "timestamp": 1669589913543
    }
   ]
  },
  "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
}
