Skip to content
AI|Course
← Machine Learning Basics

Lesson 1 of 7 · 1 hr

Machine learning in practice

Machine learning is the part of AI that learns patterns from examples instead of following rules you wrote by hand. Most of the AI products you use, from spam filters to fraud alerts to the language models in stage 2, rest on the same ideas you will meet here. This course teaches those ideas with small, honest experiments, using the Python and pandas skills you already have.

Watch

A seven-minute explanation of the two main families of machine learning. Watch it before the lesson, then compare it with the table below.

Watch on YouTube (opens in a new tab)Video by IBM Technology. The player loads only when you press play.

What "learning from examples" means

A traditional program is rules plus data in, answers out. A machine learning program flips that: you give it data with the answers and it works out the rules.

  • Rules approach: "If disk use is over 90 percent and the error rate is above 3, raise an alert." You wrote the rule and you must keep it up to date.
  • Learning approach: you show the system thousands of past servers and whether each one failed. It finds which patterns predict failure, including combinations you did not think of.

The learned rules live in a model: a set of numbers produced by training that you can use to make predictions on new data.

The main kinds of learning

KindYou provideThe model learns toExample
SupervisedInputs and the correct answers (labels)Predict the answer for new inputsWill this server fail? Is this ticket urgent?
UnsupervisedInputs onlyFind structure on its ownGroup similar servers, spot odd behavior
ReinforcementA goal and feedback (rewards)Choose actions that earn reward over timeA game player, a robot, part of how chat models are tuned

Most business machine learning is supervised, and that is where this course spends most of its time. Within supervised learning, there are two kinds of answer:

  • Classification: the answer is a category (failed or not, spam or not spam, which team should get this ticket).
  • Regression: the answer is a number (response time, disk space needed next month, ticket count).

Problems IT teams actually solve

ProblemTypeData needed
Predict which servers will fail soonClassificationPast metrics and outage history
Route a ticket to the right teamClassificationPast tickets with the team that resolved them
Forecast storage or trafficRegressionHistory over time
Estimate how long an incident will takeRegressionPast incidents
Find unusual logins or trafficAnomaly detection (unsupervised)Normal behavior over time
Group users or services by behaviorClustering (unsupervised)Usage data

The workflow

Almost every project follows the same loop, and most of the effort goes into steps 1 to 3 and 6, not the model itself:

  1. Frame the problem. What exactly will you predict, and what will someone do with the prediction?
  2. Get and understand the data. Where it comes from, what each column means, what is missing.
  3. Build a simple baseline. A rule of thumb or a trivial model that any real model must beat.
  4. Train a model on part of the data.
  5. Evaluate it on data it has not seen, with measures that match the cost of mistakes.
  6. Deploy and monitor, because the world changes and models go stale.

You will practice steps 1 to 5 in this course.

When not to use machine learning

  • A clear rule works. If you can write the rule, write it. It is cheaper, exact and explainable.
  • You have no reliable labeled data, or too little of it.
  • Mistakes are very costly and you cannot review the output.
  • You need to explain every decision and a simple rule table would do.
  • The thing you want to predict is not in the data you have.

A good habit: always ask "what would a clever person with a spreadsheet and an hour do?" That is your baseline.

Classic machine learning and language models

You now know language models. They are one kind of machine learning, trained on text at huge scale. Classic machine learning is still often the better tool when:

  • Your data is tables of numbers and categories (metrics, transactions, sensor readings).
  • You need fast, cheap, private predictions on your own servers.
  • You have plenty of labeled examples of the exact question you care about.
  • You want measurable, repeatable accuracy.

Language models are the better tool when the input is free text, images or documents, when you have few or no labeled examples, or when you need flexible language output. Many real systems use both.

Your first model in ten lines

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier

X, y = load_iris(return_X_y=True)          # flower measurements and species
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.25, random_state=0
)

model = DecisionTreeClassifier(max_depth=3, random_state=0)
model.fit(X_train, y_train)                # learn from the training examples
print("accuracy on unseen data:", round(model.score(X_test, y_test), 2))
print("prediction for one flower:", model.predict(X_test[:1]))

Install the library first with pip install scikit-learn. The pattern is the same for almost every model in this course:

  1. Load data into X (the inputs, also called features) and y (the answers, also called labels).
  2. Split it, so you can test on examples the model never saw.
  3. Fit the model on the training part.
  4. Predict and score on the held-out part.

Vocabulary

TermMeaning
FeatureOne input column the model uses
Label or targetThe answer you want to predict
Training dataExamples used to learn
Test dataExamples held back to check the result
ModelThe learned pattern
Fit or trainLearn from data
Predict or inferUse the model on new data
OverfittingMemorizing training data instead of learning the pattern
The idea that carries the whole course

A model is only useful if it works on data it has not seen. Everything in the next lessons, from splitting data to measuring errors, is about protecting that honest test.

Resources

Docsscikit-learn
Getting started with scikit-learn (opens in a new tab)

The official quick tour of fitting, predicting, pipelines and model selection.

Free courseGoogle for Developers
Machine Learning Crash Course (opens in a new tab)

A free, self-paced course with videos, readings and exercises. Use it as a second voice alongside this one.

Free courseKaggle
Kaggle Learn: Intro to Machine Learning (opens in a new tab)

Short free lessons with exercises that run in your browser.

CodeMicrosoft on GitHub
Machine Learning for Beginners (opens in a new tab)

A free 12-week curriculum with lessons, quizzes and projects.

DocsGoogle for Developers
Machine Learning Glossary (opens in a new tab)

Precise definitions for the terms you will keep meeting.

Check yourself

  1. Name three problems from your own workplace. For each, say whether it is classification, regression, clustering or anomaly detection.
  2. For one of them, describe the baseline: what would a clever person with a spreadsheet do?
  3. Run the ten-line example. Change max_depth to 1 and then to 10. What happens to the accuracy, and what do you think is going on?

Found a broken link or a mistake? Report it (opens in a new tab).