When the cost_funciton is called in C1_W1_Lab03_Cost_function_Soln?

When creating a post, please add:

  • Week #1
  • [C1_W1_Lab03_Cost_function_Soln.ipynb]
  • Description:
  • I can successfully run Optional Lab: Cost Function but I have no way to know when the function “compute_cost” is actually called? can someone explain?

Hello, @vishalkukkar,

First, welcome to our community!

Yes - the compute_cost function is not called anywhere in that optional lab, and it seems the lab was only meant to show how the function is written. However, as you proceed to the next optional lab, a similar compute_cost will be defined again and, this time, used. :wink:

Cheers,
Raymond

1 Like

Thanks @rmwkwok. I see the functions plt_stationary and plt_update_onclick are not part of the matplotlib.pyplot (plt) module then how they are called? sorry I am new to jupyter notebooks and python

Hello, @vishalkukkar,

There are 3 steps. First they were defined in separate .py file(s), then imported from there to the lab, and used.

Below is a simple example that demo the idea:

First, define the following function and save it in a whatever_name.py:

def sum(a, b):
    return a + b

Then, in a jupyter notebook, import and use it:

from whatever_name import sum

print('answer is: ', sum(3, 4))

If you wonder how those functions were defined, you might, on the notebook interface, click “File” > “Open”, then you will see some .py files, and the functions can be found in one or more of those files.

Note, however, that since this MLS is not for teaching Python, you might not find as much explanation to those code as we have to the machine learning concepts in the notebook.

Cheers,
Raymond

1 Like