{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Regularized Linear Regression and Bias vs Variance\n", "\n", "In the first half of the example, we will implement regularized linear regression to predict the amount of water flowing out of a dam using the change of water level in a reservoir. In the next half, you will go through some diagnostics of debugging learning algorithms and examine the effects of bias v.s. variance.\n", "\n", "NOTE: The example and sample data is being taken from the \"Machine Learning course by Andrew Ng\" in Coursera." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# initial imports\n", "import numpy as np\n", "from matplotlib import pyplot as plt\n", "%matplotlib notebook\n", "import seaborn as sns" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# imports from my models designed for these examples\n", "from models.linear_regression import compute_cost, gradient_descent, compute_gradient, train_linear_reg, validation_curve\n", "from models.data_preprocessing import add_bias_unit, map_feature, feature_normalize" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loading and Visualizing Data\n", "\n", "We start the exercise by first loading and visualizing the dataset. \n", "The following code will load the dataset into your environment and plot the data.\n", "\n", "We will begin by visualizing the dataset containing historical records on the\n", "change in the water level, x, and the amount of water flowing out of the dam,\n", "y.\n", "\n", "This dataset is divided into three parts: \n", "