Lesson Introduction

Hi there! Today, we're talking about functions. By the end, you'll know what functions are in math and how they apply to machine learning. We'll also teach you how to define and use functions in Python. Let's begin!

What is a Function?
Functions Examples
Defining a Function in Python
Evaluating a Function
Plotting the Function
Understanding the Code for Plotting

To help you better understand plotting, here is a breakdown of the code:

  • We import matplotlib.pyplot for plotting and numpy for array handling.
  • We define the function simple_function as before.
  • We generate a list of x-values ranging from -10 to 10 using np.linspace(-10, 10, 400). The 400 specifies the number of points to generate, ensuring a smooth plot.
  • We compute the corresponding y-values by passing our list of x-values to simple_function. Although the function is designed for a single input number, numpy allows it to process the entire list of x-values, returning a list of y-values.
  • We plot these x and y values using plt.plot.

Don't worry about memorizing all this plotting code! We will provide it in the exercises so you can focus on understanding functions rather than learning how to plot them with python.

Evaluating Function with the Plot
Common Mathematical Functions
Lesson Summary

Great job! Today, we learned what functions are and how they relate inputs to outputs in math and programming. We also learned how to define a function in Python, saw a practical example of evaluating a function, and even plotted a function.

Functions are essential in machine learning for modeling and solving optimization problems. Understanding functions lays the foundation for more complex topics.

Awesome! Now, you'll get hands-on experience defining and evaluating your own functions in Python. This will solidify your understanding of functions, which is crucial for your journey into machine learning and beyond. Let's get started!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal