TExcelTAD
Home › Machine Learning › ML Getting Started

ML Getting Started

Machine learning (ML) is the practice of letting a computer discover rules from examples instead of writing those rules by hand. You show a program many past observations — house sizes and their prices, emails labelled "spam" or "not spam", measurements of flowers — and it builds a model that can make a sensible guess about new, unseen cases.

This course teaches machine learning with Python, the language most data scientists use every day. Every example on these pages runs right in your browser, so you can edit the code and press ▶ Run to see what changes.

What you need to know first

You should be comfortable with basic Python: variables, lists, loops, functions and import. If you are not, work through the Python course first. You do not need advanced mathematics: we explain each idea with small numbers you can check by hand before letting a library do the work.

The toolbox

Library What it gives you
NumPy Fast arrays and maths on whole columns of numbers at once
pandas Tables (DataFrame) with named columns, like a spreadsheet in code
SciPy Statistics, distributions, clustering helpers
Matplotlib Charts: scatter plots, histograms, lines
scikit-learn The models: regression, trees, clustering, evaluation tools

All of them are already available in the playground. Let's check their versions:

python · try it yourself
import numpy as np
import pandas as pd
import scipy
import sklearn
import matplotlib

print("NumPy       ", np.__version__)
print("pandas      ", pd.__version__)
print("SciPy       ", scipy.__version__)
print("scikit-learn", sklearn.__version__)
print("Matplotlib  ", matplotlib.__version__)
NumPy        2.2.5
pandas       2.3.3
SciPy        1.14.1
scikit-learn 1.7.0
Matplotlib   3.8.4

Data is the starting point

In machine learning, a data set is usually a table. Each row is one example (a sample, an observation) and each column is one property of it (a feature). Here is a tiny invented data set about cups of coffee sold by a kiosk on different days:

python · try it yourself
import pandas as pd

sales = pd.DataFrame({
    "temperature": [12, 15, 9, 22, 25, 18, 7],
    "is_weekend":  [0, 0, 1, 1, 0, 1, 0],
    "cups_sold":   [140, 120, 175, 95, 70, 110, 160],
})
print(sales)
print()
print("rows, columns:", sales.shape)
   temperature  is_weekend  cups_sold
0           12           0        140
1           15           0        120
2            9           1        175
3           22           1         95
4           25           0         70
5           18           1        110
6            7           0        160

rows, columns: (7, 3)

Looking at the numbers, you might already guess a rule: colder days sell more coffee. Machine learning automates exactly this kind of guess — and measures how good the guess is.

Kinds of data

Before you can analyse data you need to know what kind of values each column holds:

  • Numerical values are numbers. They can be discrete (counted: 3 cups, 4 children) or continuous (measured: 21.7 °C, 1.82 m).
  • Categorical values are labels that cannot be measured against each other: colours, city names, yes/no.
  • Ordinal values are categories with a natural order: school grades A–F, T-shirt sizes S < M < L.

The kind of data decides which tools you can use. You can average temperatures, but averaging city names makes no sense.

python · try it yourself
import pandas as pd

students = pd.DataFrame({
    "age":       [19, 21, 20, 23],                 # numerical, discrete
    "height_m":  [1.71, 1.65, 1.80, 1.77],         # numerical, continuous
    "city":      ["Hanoi", "Lyon", "Lima", "Oslo"],  # categorical
    "shirt":     ["M", "S", "L", "M"],             # ordinal
})
print(students.dtypes)
print()
print("Average height:", students["height_m"].mean())
age           int64
height_m    float64
city         object
shirt        object
dtype: object

Average height: 1.7325

pandas reports numbers as int64/float64 and text as object. It cannot tell on its own that shirt has an order — that is knowledge you bring, and later lessons show how to encode it.

Your first model

To give you a feel for where this course is heading, here is a complete (very small) machine-learning program. It learns from the coffee data and predicts sales for a 10 °C weekday. Don't worry about the details: every line is explained in later lessons.

python · try it yourself
from sklearn.linear_model import LinearRegression

temperature = [[12], [15], [9], [22], [25], [18], [7]]
cups_sold = [140, 120, 175, 95, 70, 110, 160]

model = LinearRegression()
model.fit(temperature, cups_sold)          # learn from examples

prediction = model.predict([[10]])         # ask about a new day
print(f"Predicted cups at 10 C: {prediction[0]:.0f}")
Predicted cups at 10 C: 153

The pattern model.fit(X, y) then model.predict(new_X) is the heart of scikit-learn. You will use it in almost every lesson.

How this course is organised

  1. Statistics basics — mean, median, spread, percentiles and distributions: the language used to describe data.
  2. Regression — predicting numbers (linear, polynomial, multiple).
  3. Classification and clustering — decision trees, logistic regression, k-means, KNN and friends.
  4. Model evaluation and tuning — train/test splits, confusion matrices, cross validation, grid search, ROC curves.
  5. Extras — pipelines, feature engineering, neural networks, saving models and using ML responsibly.

After this course, the Machine Learning track takes every topic further, starting with ML Foundations: Classical ML Algorithms rebuilds these models from scratch in NumPy, and Deep Learning continues where the neural-network lessons stop. Lessons here end with a Go further pointer to the matching lesson there.

Tip: Change the numbers in the examples and run them again. Breaking an example on purpose is one of the fastest ways to learn what each line does.

Test yourself

In a typical machine-learning data set, what does one row represent?

  1. One feature
  2. One example or observation
  3. One model
  4. One prediction error

Which kind of data is a T-shirt size (S, M, L)?

  1. Continuous numerical
  2. Discrete numerical
  3. Ordinal
  4. Neither: it is not data

Which two scikit-learn methods form the basic learn-then-guess pattern?

  1. train() and guess()
  2. fit() and predict()
  3. load() and run()
  4. learn() and apply()