{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Title :\n",
"Exercise: Beta Values for Data from Random Universe\n",
"\n",
"## Description :\n",
"\n",
"Given a `RandomUniverse(dataframe)->dataframe` function that gives a new dataset from a \"parallel\" universe, calculate the $\\beta_0$'s and $\\beta_1$'s and plot a histogram like the one below.\n",
"\n",
"\n",
"\n",
"## Data Description:\n",
"\n",
"## Instructions:\n",
"\n",
"- Get a new dataframe using the RandomUniverse function already provided in the exercise\n",
"- Calculate $\\beta_0$, $\\beta_1$ for that particular dataframe\n",
"- Add the calculated $\\beta_0$ and $\\beta_1$ values to a python list\n",
"- Plot a histogram using the lists calculated above\n",
"\n",
"## Hints: \n",
"\n",
"$${\\widehat {\\beta_1 }}={\\frac {\\sum _{i=1}^{n}(x_{i}-{\\bar {x}})(y_{i}-{\\bar {y}})}{\\sum _{i=1}^{n}(x_{i}-{\\bar {x}})^{2}}}$$\n",
"\n",
"$${\\widehat {\\beta_0 }}={\\bar {y}}-{\\widehat {\\beta_1 }}\\,{\\bar {x}}$$\n",
"\n",
"plt.subplots()\n",
"Create a figure and a set of subplots\n",
"\n",
"ax.hist()\n",
"Plot a histogram from a list or series."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Import necessary libraries\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from randomuniverse import RandomUniverse\n",
"%matplotlib inline\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | tv | \n", "sales | \n", "
---|---|---|
0 | \n", "230.1 | \n", "465.26 | \n", "
1 | \n", "44.5 | \n", "218.95 | \n", "
2 | \n", "17.2 | \n", "195.79 | \n", "
3 | \n", "151.5 | \n", "389.47 | \n", "
4 | \n", "180.8 | \n", "271.58 | \n", "