Courses · Artificial intelligence

Machine learning with Python: your first models

Build real machine learning in plain Python, with no special software: turn data into features and labels, fit a line that predicts prices, measure its error honestly on test data, classify with nearest neighbours, and judge a model with accuracy, precision and recall.

Level: Intermediate, after Programming with Python: first steps

  1. 1Data, features and labelsName the features and the label in a data set. Tell a prediction of a number (regression) from a choice of category (classification). Store a small data set in Python lists.Free to read · 4 practice questions
  2. 2Your first model: fitting a straight linePredict with a line: prediction = intercept + slope × feature. Find the best-fitting line from data with least squares in Python. Explain what the slope means in real terms.Members · 4 practice questions
  3. 3How good is it? Measuring error honestlyCompute the mean absolute error of a model in Python. Explain why we test on data the model never saw. Recognise overfitting.Members · 4 practice questions
  4. 4Classification with nearest neighboursMeasure the distance between two examples. Classify a new example by a vote of its k nearest neighbours. Write a k-nearest-neighbours classifier in Python.Members · 4 practice questions
  5. 5Judging a classifier, and what comes nextFill in a confusion matrix. Compute accuracy, precision and recall. Choose which measure matters for a real problem.Members · 4 practice questions

Textbook for this course

  • A Byte of Python

    Swaroop C H. Swaroop C H, via LibreTexts, updated November 2020. Read it in full in the WorldClass library.

    Licence CC-BY-SA-4.0, checked 2026-10-30.

  • WorldClass Statistics

    David M Diez, Mine Çetinkaya-Rundel, Christopher D Barr. Derivative of OpenIntro Statistics, Fourth Edition, updated December 2024. Read it in full in the WorldClass library.

    Licence CC-BY-SA-3.0, checked 2026-10-30.

Build status · Flash Infinity AI™ is a trademark of AI-Flash Inc. WorldClass is not affiliated with, approved or accredited by any exam board, curriculum provider or university unless a page says so.