Excali

Blog

Publish Date: 2023-12-03

Software Engineer Learning Machine Learning - Day 5

AI

Disclaimer: If you haven’t read/watched day 4, I recommend you do that before reading this article.

For those of you who prefer to watch a video I made on my channel regarding my journey:

Polynomial Regression

If a linear function does not fit our data well, we can change the behavior or curve of our hypothesis function by making it a quadratic (hθ(x) = θ₀ + θ₁x₁ + θ₂x₁²), cubic (hθ(x) = θ₀ + θ₁x₁ + θ₂x₁² + θ₃x₁³), square root (hθ(x) = θ₀ + θ₁√x₁) function or any other form.

For example:

  • If our data looks like this:

Quadratic Data

A quadratic hypothesis function (hθ(x) = x₁² - 10x₁ + 25) will be a good match:

Quadratic Graph And Data

  • If our data looks like this:

Square Root Data

A squared root hypothesis function (hθ(x) = √x₁) will be a good match:

Square Root Graph And Data

Features

  • Combining Features - sometimes one feature is dependable on another feature, in this case, we combine them into one. For instance, if we want our hypothesis function to ignore x₂ when x₁ = 0 and address x₂ when x₁ = 1 we can introduce a new feature x₃ = x₁x₂ to our hypothesis, and end up with hθ(x) = θ₀ + θ₁x₁ + θ₃x₁x₂.

  • Scaling - when using a polynomial hypothesis one thing to keep in mind is the range of our features. For instance, if our hypothesis is of the form hθ(x) = θ₀ + θ₁x₁ + θ₂x₁² + θ₃x₁³, and x₁ has a range 1 - 1000 then a range of x₁² becomes 1 - 1000000 and that of x₁³ becomes 1 - 1000000000 giving x₁³ a great impact on our hypothesis output.