Machine Learning Fundamentals with scikit-learn

Lesson 1 of 8

Setup and Your First Model

scikit-learn is Python's most widely used library for classical machine learning: classification, regression, clustering, and everything around evaluating and tuning those models. Unlike this course's quantum computing or game-development siblings, scikit-learn (along with numpy and pandas) actually runs directly in this course's browser sandbox, every lesson here is genuinely runnable, no local install required.

What "machine learning" actually means

A traditional program is a set of rules a human writes by hand: "if the email contains these words, mark it as spam." A machine learning model instead learns those rules from examples: show it thousands of emails already labeled spam/not-spam, and it figures out the patterns itself. scikit-learn's entire API is built around two verbs that capture this idea:

  • fit(X, y), learn patterns from labeled training data (X = inputs, y = correct answers).
  • predict(X), apply what was learned to new, unseen inputs.

Your first model

Pythonshares state with other Python blocks
  • load_iris() loads a small, classic dataset (bundled with scikit-learn, no download needed) of 150 flowers, each described by 4 measurements (.data) and labeled with one of 3 species (.target).
  • train_test_split(...) splits the data into a chunk for training and a chunk held back for testing, covered in depth next lesson.
  • DecisionTreeClassifier() creates an untrained model, a decision tree specifically, but every scikit-learn model shares this same fit/predict shape regardless of what's happening internally.
  • model.fit(X_train, y_train) is where the actual learning happens, before this line, model knows nothing about flowers.
  • model.predict(X_test) asks the now-trained model to guess the species of flowers it has never seen, comparing its guesses to the real answers is exactly how you'll judge whether it learned anything useful.

NOTE

The first time any lesson in this course imports sklearn, numpy, or pandas, your browser downloads those packages (compiled to WebAssembly), which can take a little while, subsequent runs on the same page are instant. No pip install needed, this is genuinely different from the Kivy, Qiskit, and Cirq courses.

📝 Setup and Your First Model Quiz

Passing score: 70%
  1. 1.What is the core difference between a traditional program and a machine learning model?

  2. 2.Every scikit-learn model shares the same fit()/predict() interface, regardless of what algorithm it uses internally.

  3. 3.model.____(X_train, y_train) is the method call where a scikit-learn model actually learns from training data.