How it works...

Here is the explanation for the code:

  • theta0 = np.linspace(-10, 10, 100) and theta1 = np.linspace(-1, 4, 100) help us compute the Loss, which is the error for the ranges of theta0 and theta1 values. All this data is available in the form of Excel files, so we read them all using pd.read_excel()
  • np.meshgrid() creates the mesh grid between theta0 and theta1 to get X and Y, then passes on X, Y, and Loss to plot the contour plot.
  • CS = plt.contour() draws the contour plot. 
  • np.logspace(-2,3,20) specifies the range of values on a logarithmic scale for the Loss attribute, which needs to be drawn on a contour plot. On a linear scale, this range will be from 0.01 (10 to the power of -2) to 1,000 (10 to the power of 3). And 20 is the number of samples it draws in this range, using which contours are plotted. 
  • plt.clabel() specifies that actual loss values to be plotted on the contour as labels. As can be seen in the plot, the value of loss (error) goes all the way to 545.559 from zero!

We get the output as follows: