Contour plot
The contour plot is typically used to display how the error varies with varying coefficients that are being optimized in a ML algorithm such as linear regression. If the linear regression coefficients are theta0 and theta1, and the error between the predicted value and the actual value is a loss, then for a given loss value, all the values of theta0 and theta1 form a contour. For different values of loss, different contours are formed by varying values of theta0 and theta1.
Getting ready
The loss, theta0, theta1, and theta (optimal values of theta0 and theta1 that give lowest error) data are taken from one of the regression problems for plotting the contour plot. If theta0 and theta1 are vectors of size 1 x n, then the loss will be in the form of a n x n matrix.
Import the required libraries. We will introduce one more library for color mapping from matplotlib
:
import matplotlib.pyplot as plt import pandas as pd import numpy as np from matplotlib import cm
We also need to understand...