ml-schoo-and-maybe-andrew-ng/work/.ipynb_checkpoints/oldC1_W2_Lab01_Model_Repres...

383 lines
36 KiB
Plaintext
Raw Normal View History

2022-11-15 10:53:25 -05:00
{
"cells": [
{
"cell_type": "markdown",
"id": "specialized-stanley",
"metadata": {},
"source": [
"# Ungraded Lab: Model Representation\n",
"\n",
"In this ungraded lab, you will implement the model $f$ for linear regression with one variable.\n"
]
},
{
"cell_type": "markdown",
"id": "active-bernard",
"metadata": {},
"source": [
"## Problem Statement\n",
"\n",
"You will use the motivating example of housing price prediction again. For sake of simplicity, let's assume that you just have two data points - a house with 1000 square feet sold for \\\\$200,000 and a house with 2000 square feet sold for \\\\$400,000.\n",
"\n",
"Therefore, your dataset contains the following two points - \n",
"\n",
"| Size (feet$^2$) | Price (1000s of dollars) |\n",
"| -------------------| ------------------------ |\n",
"| 1000 | 200 |\n",
"| 2000 | 400 |\n",
"\n",
"You'd like to fit a linear regression model (represented with a straight line) through these two points, so you can then predict price for other houses - say, a house with 1200 feet$^2$.\n",
"\n",
"### Notation: `X` and `y`\n",
"\n",
"For the next few labs, you will use lists in python to represent your dataset. As shown in the video:\n",
"- `X` represents input variables, also called input features (in this case - Size (feet$^2$)) and \n",
"- `y` represents output variables, also known as target variables (in this case - Price (1000s of dollars)). \n",
"\n",
"Please run the following code cell to create your `X` and `y` variables."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "headed-custom",
"metadata": {},
"outputs": [],
"source": [
"# X is the input variable (size in square feet)\n",
"# y in the output variable (price in 1000s of dollars)\n",
"X = [1000, 2000] \n",
"y = [200, 400]"
]
},
{
"cell_type": "markdown",
"id": "dependent-attribute",
"metadata": {},
"source": [
"### Number of training examples `m`\n",
"You will use `m` to denote the number of training examples. In Python, use the `len()` function to get the number of examples in a list. You can get `m` by running the next code cell."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "novel-vessel",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of training examples is: 2\n"
]
}
],
"source": [
"# m is the number of training examples\n",
"m = len(X)\n",
"print(\"Number of training examples is: %d\" %m)"
]
},
{
"cell_type": "markdown",
"id": "permanent-uncertainty",
"metadata": {},
"source": [
"### Training example `x_i, y_i`\n",
"\n",
"You will use (x$^i$, y$^i$) to denote the $i^{th}$ training example. Since Python is zero indexed, (x$^0$, y$^0$) is (1000, 200) and (x$^1$, y$^1$) is (2000, 300). \n",
"\n",
"Run the next code block below to get the $i^{th}$ training example in a Python list."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "executive-chick",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(x^(0), y^(0)) = (1000, 200)\n"
]
}
],
"source": [
"i = 0 # Change this to 1 to see (x^1, y^1)\n",
"\n",
"x_i = X[i]\n",
"y_i = y[i]\n",
"print(\"(x^(%d), y^(%d)) = (%d, %d)\" %(i, i, x_i, y_i))"
]
},
{
"cell_type": "markdown",
"id": "solid-sharing",
"metadata": {},
"source": [
"### Plotting the data\n",
"First, let's run the cell below to import [matplotlib](http://matplotlib.org), which is a famous library to plot graphs in Python. "
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "designing-sociology",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"id": "virgin-germany",
"metadata": {},
"source": [
"You can plot these two points using the `scatter()` function in the `matplotlib` library, as shown in the cell below. \n",
"- The function arguments `marker` and `c` show the points as red crosses (the default is blue dots).\n",
"\n",
"You can also use other functions in the `matplotlib` library to display the title and labels for the axes."
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "reduced-cartoon",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Text(0.5, 0, 'Size (feet^2)')"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACx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Ae27VbT20vAD7WysAiIqL9Gl4p2H4Z2GWwJ5a0tqTbJd0paa6kz5byiyQ9KGlOeU0u5ZJ0nqT5ku6StPOgaxMREauk2X6BOyRdA/wYeKGn0PYVAxyzFNjb9vPl9tVby8NwAP9i+7Je+x8AbFtebwO+Uf5GRESbNJsUNgaeBPauKzPQb1Io8ys/X1bHlNdAcy4fAny3HHebpLGSxtle1GSMERGxippKCraPXZmTl/6IWcA2wAW2Z0j6KPB5SZ+heubhNNtLgfHAw3WHLyxli3qd83jgeIAttthiZcKKiIh+NJUUJK0NfBjYgWrMIwBsHzfQcaU/YrKkscCVknakuovpUWBNYCrwSeAsQH2doo9zTi3H0d3dPdCVR0REDFKzt6R+D9gc2A+4GZgAPNfsm9heAkwH9re9yJWlwHeAXctuC4GJdYdNAB5p9j0iImLVNZsUtrH9aeAF29OAvwXeNNABkrrKFQKS1gH2Ae6VNK6UCXgv1TDcANcAR5e7kHYDnkl/QkREezXb0fzn8ndJaQJ6FJjU4JhxwLTSr7AacKntayX9UlIXVXPRHOCEsv91wIHAfOBFqvGVIiKijZpNClMlbQR8muoX/XrAZwY6wPZdwE59lO/dx+49dyud2GQ8ERHRAs3effRfZfFmYOvWhRMREcNpwKQg6eMDbbf9laENJyIihlOjK4X12xJFRES8KgyYFGx/tl2BRETE8GvUfHTeQNttZ6TUiIg
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Plot the data points\n",
"plt.scatter(X, y, marker='x', c='r')\n",
"\n",
"# Set the title\n",
"plt.title(\"Housing Prices\")\n",
"# Set the y-axis label\n",
"plt.ylabel('Price (in 1000s of dollars)')\n",
"# Set the x-axis label\n",
"plt.xlabel('Size (feet^2)')"
]
},
{
"cell_type": "markdown",
"id": "level-nirvana",
"metadata": {},
"source": [
"## Model function\n",
"\n",
"The model function for linear regression (which is a function that maps from `X` to `y`) is represented as \n",
"\n",
"$f(x) = w_0 + w_1x$\n",
"\n",
"The formula above is how you can represent straight lines - different values of $w_0$ and $w_1$ give you different straight lines on the plot. Let's try to get a better intuition for this through the code blocks below.\n",
"\n",
"Let's represent $w$ as a list in python, with $w_0$ as the first item in the list and $w_1$ as the second. \n",
"\n",
"Let's start with $w_0 = 3$ and $w_1 = 1$ \n",
"\n",
"### Note: You can come back to this cell to adjust the model's w0 and w1 parameters"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "temporal-investor",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"w_0: 1\n",
"w_1: 0.2\n"
]
}
],
"source": [
"# You can come back here later to adjust w0 and w1\n",
"w = [1, 0.2] \n",
"print(\"w_0:\", w[0])\n",
"print(\"w_1:\", w[1])"
]
},
{
"cell_type": "markdown",
"id": "capable-westminster",
"metadata": {},
"source": [
"Now, let's calculate the value of $f(x)$ for your two data points. You can explicitly write this out for each data point as - \n",
"\n",
"for $x^0$, `f = w[0]+w[1]*X[0]`\n",
"\n",
"for $x^1$, `f = w[0]+w[1]*X[1]`\n",
"\n",
"For a large number of data points, this can get unwieldy and repetitive. So instead, you can calculate the function output in a `for` loop as follows - \n",
"\n",
"```\n",
"f = []\n",
"for i in range(len(X)):\n",
" f_x = w[0] + w[1]*X[i]\n",
" f.append(f_x)\n",
"```\n",
"\n",
"Paste the code shown above in the `calculate_hypothesis` function below."
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "tracked-bubble",
"metadata": {},
"outputs": [],
"source": [
"def calculate_model_output(w, X):\n",
" # Copy the code shown in the markdown here\n",
" f = []\n",
" for i in range(len(X)):\n",
" f_x = w[0] + w[1]*X[i]\n",
" f.append(f_x)\n",
" return f"
]
},
{
"cell_type": "markdown",
"id": "blind-vocabulary",
"metadata": {},
"source": [
"Now let's call the `calculate_hypothesis` function and plot the output using the `plot` method from `matplotlib` libarary."
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "blocked-franklin",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [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h4rQvva1VIS2+eaVjqoy3FMwsy6ruSK0kSO7bkIA9xTMrIt66ik46qjaLUJrK/cUzKxLqS9C69evtovQ2so9BTPrMpoWoV14Iay3XqWj6lzcUzCzmvfWW3DEEY1FaI8/nq40ckL4KCcFM6tZEWloaOut4aabGovQdt+90pF1Xh4+MrOa1LQI7Z//7Ho1B23hnoKZ1RQXoa0Y9xTMrGa88EK6zPSJJ1yE1lbuKZhZ1SssQpsyxUVoK6JoT0FSP+BQYA+gB/A+MAm4F7ghIt4ta4RmZq1wEVr7arWnIGkEcBQwEtiXlBS2AX4BrAHcKWlAuYM0M2tq4UI49dTGldDuustFaO2hWE/hsIiY06RtATAh3/4gaeOyRGZm1gIXoZVPqz2F+oQgaW1JK+X7W0oaIGnVwn3MzMrNRWjlV+qJ5seANST1BB4CfghcW66gzMwKNS1C+8UvXIRWLqVekqqIeE/SkcAlEfFbSc+UMzAzM4AZM+D4412E1lFK7SkoX4V0COmqI3CNg5mVUX0RWp8+LkLrSKV+sQ8EzgTuiIjJkj4FPFK+sMysK5s6Na2E5iK0jldKncLKwNcjouHS04h4BTi5nIGZWdezeDFcdFEqRFtnHRg+HA47DKRKR9Z1FE0KEbFU0k4dEYyZdV3jxqUitEmTXIRWSaWeU3hG0l2SDpP0zfpba0+QtIakpyQ9K2mypHNz+7WSXpU0Md+2z+2SNEzSNEnPSdpxBY/NzKpAfRFav34wd66L0Cqt1HMKGwJvAXsWtAVweyvPWQTsGRELck3D6FwhDfA/EXFbk/33A7bIt12AK/JfM6tRI0fCscemIrTjj4cLLnDNQaWVlBQi4ofL+8IREaTqZ4BV8y1aecqBwHX5eWMldZPUIyJmLe97m1nn9tZbqXdw/fXw2c+mIjTXHHQOJQ0f5aGgEyRdLukv9bc
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"f = calculate_model_output(w, X)\n",
"\n",
"# Plot our hypothesis\n",
"plt.plot(X, f, c='b')\n",
"\n",
"# Plot the data points\n",
"plt.scatter(X, y, marker='x', c='r')\n",
"\n",
"# Set the title\n",
"plt.title(\"Housing Prices\")\n",
"# Set the y-axis label\n",
"plt.ylabel('Price (in 1000s of dollars)')\n",
"# Set the x-axis label\n",
"plt.xlabel('Size (feet^2)')"
]
},
{
"cell_type": "markdown",
"id": "dominican-panel",
"metadata": {},
"source": [
"As you can see, $w_0 = 2$ and $w_1 = 1$ does not result in a line that fits our data. \n",
"\n",
"### Challenge\n",
"Try experimenting with different values of $w_0$ and $w_1$. What should the values be for getting a line that fits our data?\n",
"\n",
"#### Tip:\n",
"You can use your mouse to click on the triangle to the left of the green \"Hints\" below to reveal some hints for choosing w0 and w1."
]
},
{
"cell_type": "markdown",
"id": "respected-median",
"metadata": {},
"source": [
"<details>\n",
"<summary>\n",
" <font size='3', color='darkgreen'><b>Hints</b></font>\n",
"</summary>\n",
" <p>\n",
" <ul>\n",
" <li>Try w0 = 1 and w1 = 0.5, or w = [0, 0.2] </li>\n",
" </ul>\n",
" </p>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "recreational-tennis",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}