What is Machine Learning?

Machine learning is a subset of artificial intelligence where systems learn patterns from data rather than being explicitly programmed with rules.

Instead of writing:

"If the email contains 'free money', mark it as spam"

You give the system thousands of emails labeled as spam or not spam, and it figures out the patterns on its own.

The Three Ingredients

Every ML system needs three things:

  • DataExamples to learn from (images, text, numbers, etc.)
  • ModelA mathematical function that maps inputs to outputs
  • Learning algorithmA method to adjust the model based on how wrong its predictions are
  • Your First ML Model in 5 Lines

    Let's see ML in action. We'll train a simple linear regression model to predict housing prices based on square footage.

    Run the code below:

    Python
    Loading editor...
    Loading Python runtime...

    The model learned a relationship between square footage and price from the data. It didn't need explicit rules — it found the pattern (a linear relationship) automatically.

    This is the core idea of ML: learn from examples, then generalize to new inputs.

    Types of Machine Learning

    There are three main categories:

  • Supervised LearningYou provide labeled examples (input → correct output). The model learns to predict the output for new inputs. Example: predicting house prices, classifying emails as spam.
  • Unsupervised LearningYou provide data without labels. The model finds hidden structure or patterns. Example: grouping customers into segments, dimensionality reduction.
  • Reinforcement LearningAn agent learns by interacting with an environment and receiving rewards. Example: game-playing AI, robotics.
  • We'll cover supervised and unsupervised learning in the next two lessons.

    Try It Yourself

    Modify the code below to predict the price of a 2500 sqft house. What happens when you predict for a house far outside the training range (like 10,000 sqft)? Does the prediction still make sense?

    Python
    Loading editor...
    Loading Python runtime...

    Key Takeaways

  • ML systems learn from data instead of following explicit rules
  • Every ML system needs data, a model, and a learning algorithm
  • There are three main types: supervised, unsupervised, and reinforcement learning
  • Simple models like linear regression can already capture useful patterns
  • Models can break down when extrapolating far outside their training data