"A model trapped in a notebook helps no one. The magic happens when a real person, on a real website, gets an answer from it."
Learning Objectives
By the end of this module, you will be able to:
- Explain why a trained model needs to be "deployed" to be useful
- Understand how a model is saved to a file and loaded later
- Describe how a web app serves predictions to real users
- Follow the flow from a user's click to a model's answer
- Recognize this pattern in the apps you use every day
1. The Last Mile
You've trained a model. It makes great predictions — inside your notebook. But your customers don't have your notebook. This final step, getting a model out of your hands and into theirs, is often called the "last mile" of machine learning, and it's where a science project becomes a real product.
In this module we'll use a genuinely fun example from the source curriculum: a model trained on UFO sighting reports. Give it a few numbers — how many seconds the sighting lasted, plus a latitude and longitude — and it predicts which country the sighting was reported from. Silly? A little. But the exact same steps deploy a fraud detector or a price estimator.

Concept: "Deployment" simply means making your model available for others to use — usually behind a website or app — so that anyone can send it new data and get a prediction back, without ever seeing the code.
2. Freezing a Trained Brain: Saving the Model
Training can take minutes or hours, so we don't want to redo it every time someone visits our site. Instead, once a model is trained, we save it to a file — a process often called pickling in Python (the file "pickles" the model, preserving it for later, like jam in a jar).
[object Object], pickle
,[object Object],
pickle.dump(model, ,[object Object],(,[object Object],, ,[object Object],))
,[object Object],
model = pickle.load(,[object Object],(,[object Object],, ,[object Object],))Concept: A saved model file is a frozen brain. All the patterns the model learned are stored inside. Load the file and it's instantly ready to predict — no studying required a second time.
3. Serving Predictions With a Web App
Now we need something that listens for a user's input, feeds it to the model, and shows the answer. A lightweight Python tool called Flask is perfect for this. The idea:
- The user fills in a simple form (seconds, latitude, longitude) and clicks a button.
- The web server catches those numbers.
- It hands them to the loaded model, which predicts a country.
- The answer is sent back and displayed on the page.
Here's the heart of it — readable, not scary:
[object Object],
,[object Object], ,[object Object],():
features = [,[object Object],(x) ,[object Object], x ,[object Object], request.form.values()] ,[object Object],
prediction = model.predict([features]) ,[object Object],
,[object Object], render_template(,[object Object],, result=prediction) ,[object Object],Pro Tip: Notice the model doesn't care that it's inside a website now. It still just does model.predict(...), exactly like in your notebook. Deployment is mostly about plumbing — connecting a form to the model and the answer back to the screen.
4. How the Pieces Fit Together
It helps to picture the whole round trip:
| Step | Where it happens | What moves |
|---|---|---|
| 1. User enters data | Their browser | Numbers typed into a form |
| 2. Request sent | Internet | Form data → your server |
| 3. Prediction made | Your Flask server | Data → frozen model → answer |
| 4. Answer shown | Their browser | Prediction → back on screen |
That loop — input → server → model → answer — is the beating heart of every ML-powered app, from spam filters to recommendation feeds.
5. Why This Matters
This is the module that connects everything to the real world. All the accuracy in the world means nothing if the model can't reach the people it's meant to help. Every time an app autocompletes your sentence, flags a payment, or recommends a song, some version of this pattern is running: a saved model, loaded on a server, answering requests in milliseconds.
Try This! Think of an app you used today that gave you a "smart" answer (a recommendation, a translation, a search result). Sketch its round trip using the four-step table above. What was the input? What was the prediction? You're now seeing software the way an ML engineer does.
Key Takeaway: A model only creates value once it's deployed. We save a trained model to a file ("pickling") so it never has to relearn, then use a web framework like Flask to catch user input, run model.predict, and return the answer. The universal loop — input → server → model → answer — powers every ML product you use.
This module is adapted from Microsoft's open-source ML-For-Beginners curriculum (MIT License). The web-app lesson and UFO example were written by Jen Looper.