Introduction to AI & ML

Machine learning is a branch of artificial intelligence (AI) in which computers learn patterns directly from data to make predictions or decisions, instead of following rules a programmer writes by hand.

Learn Introduction to AI & ML in our free AI & Machine Learning course — a beginner-friendly interactive lesson with worked examples, a practice exercise and…

Part of the free AI & Machine Learning course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

By the end of this lesson you'll be able to explain what machine learning is, name the three types, walk through the ML workflow, and run your very first "learning" program in plain Python.

Imagine teaching a child to tell cats from dogs. You don't hand them a rulebook ("if pointy ears and whiskers, then cat"). You just show them lots of labelled photos . After enough examples, they recognise animals they've never seen before.

That is machine learning. The "child" is a computer, the photos are data , and the recognition skill it builds is the model . The big shift from normal programming: instead of you writing the rules, the computer learns the rules from the data.

Machine learning is a way of writing programs where, instead of coding the rules yourself, you feed the computer examples and let it discover the rules. You give it data; it gives you back a pattern it can reuse on new data.

You give examples. The computer finds the rule.

These three words get mixed up constantly. They are nested , not synonyms — picture three boxes, each inside the last:

So every deep-learning system is ML, and every ML system is AI — but not the other way round. A simple if-statement chatbot is "AI" but isn't ML; a spam filter trained on emails is ML but isn't necessarily deep learning.

Worked Example: A Model That Learns

Read every comment, then press Run. This uses plain Python only (no libraries) so it works right here in the browser. Watch it figure out a pattern nobody coded.

Almost every ML problem falls into one of three buckets. Knowing which one you're in tells you what data you need.

Learn from labelled examples (input + correct answer). "Here are 1,000 emails marked spam / not-spam — learn the pattern."

Find hidden groups in unlabelled data. "Here are 10,000 customers — group them by behaviour, no labels given."

Learn from rewards by trial and error. "Play a million games — a win is good, a loss is bad — find the winning strategy."

Every ML project, from a hobby script to a self-driving car, follows the same five steps:

🎯 Your Turn #1: Build Features (X and y)

Fill in the two blanks marked ___ . Follow each # 👉 hint, run it, and check your output against the # ✅ Expected output at the bottom.

🎯 Your Turn #2: Make a Train/Test Split

Now the most important habit in ML: holding data back for honest testing. Replace each ___ , run, and confirm the expected output.

You did the maths by hand above to understand it. In real projects, three libraries do the heavy lifting so you write two lines instead of twenty:

Fast numeric arrays and maths. The number-crunching engine everything else is built on.

Loads and cleans table-shaped data — like a spreadsheet you control with code (the DataFrame ).

Ready-made models you train with .fit() and use with .predict() .

Read-Only Example: The Real Library Stack

Here's the same study-hours model written the professional way. Read it to see how little code real ML takes — the # Expected output comments show what it prints when you run it locally.

These four trip up almost every beginner. Spotting them early saves hours of confusion.

Treating them as the same thing, or calling every chatbot "deep learning".

✅ Fix: remember the nesting — Deep Learning ⊂ ML ⊂ AI. A rule-based bot is AI but not ML; a spam model is ML but may not be deep learning.

Testing the model on the exact data it trained on. It scores ~100% and then flops on real data.

✅ Fix: hold data back. Train on one slice, test on a hidden slice (you did this in Your Turn #2).

Expecting a great model from messy, biased, or tiny data. The model can only be as good as what you feed it.

✅ Fix: clean and check your data first. Five clean rows beat five thousand wrong ones. Most real ML time is spent on data, not models.

Believing ML "just knows" things or thinks like a human. It only finds statistical patterns in the numbers it was shown.

✅ Fix: treat models as pattern-matchers, not minds. They make mistakes, reflect their data's biases, and can't reason beyond what they saw.

Time to fade the scaffolding. The starter has only a comment outline — no filled-in logic. Use plain Python (no libraries) to build a tiny trend predictor.

Lesson 1 complete — you speak the language of ML!

You can now explain learning-from-data vs hand-written rules, separate AI / ML / Deep Learning, name the three types of ML, walk the five-step workflow, and recognise the NumPy / pandas / scikit-learn stack. You even built a model that learned a pattern by itself — in plain Python.

🚀 Up next: Python for ML — install NumPy, pandas, and scikit-learn, and turn the read-only example above into code you can run for real.

Practice quiz

What best describes machine learning?

  • A program follows rules written by a human
  • A faster way to write if-statements
  • A computer learns patterns from data instead of hand-coded rules
  • A database that stores facts

Answer: A computer learns patterns from data instead of hand-coded rules. In ML you feed the computer examples (data) and it discovers the rules itself, rather than you coding them by hand.

How are AI, ML, and deep learning related?

  • AI contains ML which contains deep learning
  • They are three names for the same thing
  • Deep learning contains ML which contains AI
  • They are unrelated fields

Answer: AI contains ML which contains deep learning. They nest like boxes: AI is the broadest, ML is a subset of AI, and deep learning is a subset of ML.

Which type of learning uses labelled examples (input plus the correct answer)?

  • Unsupervised learning
  • Reinforcement learning
  • Transfer learning
  • Supervised learning

Answer: Supervised learning. Supervised learning trains on labelled data, like emails tagged spam or not-spam.

What does unsupervised learning do?

  • Learns from rewards and penalties
  • Finds hidden groups in data that has no labels
  • Predicts a number from labelled data
  • Memorises the training set exactly

Answer: Finds hidden groups in data that has no labels. Unsupervised learning discovers structure (like clusters) in unlabelled data, e.g. customer segmentation.

Reinforcement learning learns primarily from what?

  • Rewards earned by trial and error
  • Labelled answers
  • A fixed rulebook
  • Clustering similar points

Answer: Rewards earned by trial and error. An RL agent takes actions and learns from the rewards or penalties it receives over time.

Why do you split data into a training set and a test set?

  • To train the model twice as fast
  • Because libraries require exactly two files
  • To get an honest measure of performance on unseen data
  • To make the dataset larger

Answer: To get an honest measure of performance on unseen data. Testing on data the model already saw gives a falsely high score; the held-out test set measures real-world performance.

In the ML workflow, what does the 'features' step do?

  • Deploys the model to production
  • Picks the inputs (X) and the target to predict (y)
  • Collects raw observations
  • Computes the final accuracy

Answer: Picks the inputs (X) and the target to predict (y). Features means choosing the input columns X and the answer y the model should learn to predict.

Which library provides ready-made models you train with .fit()?

  • NumPy
  • pandas
  • matplotlib
  • scikit-learn

Answer: scikit-learn. scikit-learn supplies models you create, train with .fit(), and use with .predict().

What is pandas mainly used for in the ML stack?

  • Fast numeric arrays
  • Loading and cleaning table-shaped data
  • Training neural networks
  • Drawing 3D charts

Answer: Loading and cleaning table-shaped data. pandas handles table-shaped data via the DataFrame — like a spreadsheet you control with code.

What does 'garbage in, garbage out' warn about in ML?

  • Models always overfit
  • Deep learning is unnecessary
  • A model can only be as good as the data you feed it
  • You should never split data

Answer: A model can only be as good as the data you feed it. Messy, biased, or tiny data produces a poor model no matter how good the algorithm is.