02.01 Lesson 1 of 12
48 minFunctions, Graphs & ML Notation
Read the notation that appears in model equations: inputs, outputs, parameters, sums and the basic role of logarithms.
By the end of this lesson
You will be able to
- Explain a function as a mapping from inputs to outputs.
- Read indexed and summation notation such as
x_iandΣ. - Interpret slope and intercept in a straight-line function.
- Explain why logarithms undo exponentials.
A function is a rule with an input and output
A function takes an input and returns an output. In f(x) = 2x + 3, the name f identifies the rule, x is the input and f(x) is the result. A model is also a function: it maps an example and learned parameters to a prediction. For several features, write f(x₁, x₂, …, xₚ; θ), where θ represents the parameters the model can adjust.
def f(x):
return 2 * x + 3
print(f(4)) # 11 Read the notation you will meet repeatedly
x_i means the i-th value or example, ŷ_i means its prediction, y_i is its observed target and n is the number of observations. A summation such as Σᵢ₌₁ⁿ (y_i - ŷ_i)² means calculate a squared error for each observation and add the results. In y = wx + b, w is the slope and b is the intercept. A logarithm answers the question: “to what power must this base be raised?” It is useful for interpreting multiplicative scales and probability calculations.
Apply what you learned
ExerciseTranslate a model equation
Turn a small linear rule and a sum into ordinary Python operations. The goal is to read the symbols, not to build a model yet.
- Write
f(x) = 1.5x + 4as a Python function. - Evaluate it for
x = 0,2and-3. - Given
y = [4, 7, 8]andpred = [5, 6, 10], compute each squared error. - Add the squared errors and divide by the number of observations to calculate the mean squared error.
- In a short comment, explain what
n,y_iandŷ_imean.
Your code returns the three predictions and calculates the mean squared error as 2.0; the comments correctly identify observed values, predictions and observation count.
Free references
Study resources
- 01 Functions: FAQ Article
Read the function-notation definition and the short explanation of inputs and outputs.
- 02 Logs (logarithms), clearly explained Video
Watch the focused explanation of what a logarithm means and how it reverses exponentiation. Skip unrelated videos in the channel.
Check your understanding
Self-test
-
Question 1
In
ŷᵢ = wxᵢ + b, what does the subscriptiidentify?It identifies the observation or example. The formula produces a prediction for each indexed input. -
Question 2
What does
Σᵢ₌₁ⁿ aᵢask you to do?Add the valuesa₁throughaₙtogether, one value for each index from 1 to n.
Completion check
Move on when
You can translate a short model equation into code and explain the role of the common symbols without guessing.