Hello everyone,

I started the machine learning course today. While working on Jupiter Lab 02 on week 1 (chapter 1), I got a question on my mind. We defined a function to get the desired output plot, but when we try to find the predicted value, we have used the same function, “f = wx + b.” What is the need for a user-defined function here? Why do we need a function if we use a linear, straight-line formula? Could someone please explain this to me?


Mohana Krishna Alla.

Hello Mohana Krishna Alla @Mohana_Krishna_Alla,

Because it is a good practice!

Let me give you a bigger picture but this lab may not be the best example. Model is a tunable thing, which means that if we find model A doesn’t work well, we want to try model B. However, if a model is called 10 times in our code, we don’t want to change 10 copies of code for changing model from A to B. A way out of this is to define a function for it and call it whenever needed, and when we need to make a change, we change the definition of the function. This is not just the best practice for ML codes, but for programming generally.

With this in mind, isn’t it good to adopt the practice from day 1?


Thank you very much for your explanation Raymond.

You are welcome @Mohana_Krishna_Alla!