Building Custom Machine Learning Models
Many machine learning problems begin with a situation in which several factors influence an outcome.
Where Prediction Work Starts
Many machine learning problems begin with a situation in which several factors influence an outcome. If you want to predict that outcome, you cannot simply name the outcome and wait for an answer. You first have to describe the situation and your model of how the different factors work together. Only then does the question of computing a prediction from that model arise. This article focuses on that second question, which is handled by a family of tools called probabilistic programming languages.
What do you think happens?
In the order of work, which stage is responsible for computing predictions from your custom model?
Reveal answer
Using a probabilistic programming language
The source presents a three-step order: first you express the situation, then you model how the factors work together, and only after both are in place do you use a method that computes predictions from the custom model. Probabilistic programming languages belong to that third step.
The Three-Stage Order of Work
The source describes a clear sequence. The first stage is the expression of the situation, meaning a description of what is happening and which factors matter. The second stage is your model of how those factors work together. The third stage is the computation of predictions from the custom model you have built, and this is where probabilistic programming languages come in.
The order matters because each stage depends on the one before it. A computing tool cannot produce predictions from a model that has not been written down, and a model cannot be written down until the situation and its relevant factors have been described. The arrows in the diagram below show this order of work. They are not a loop.
Tracing a Delivery Forecast
The following example is an original illustration built on the three-stage order described in the source. It is not a specific program. Its purpose is to let you follow one situation through each stage and notice what each stage contributes. Imagine a small bakery that wants to estimate whether a delivery will arrive on time.
Forecasting an On-Time Delivery
The bakery wants a prediction for whether a morning delivery arrives on time, and the situation involves several factors that influence that outcome.
- 1Stage 1: Express the situation
You describe what is happening. Here the situation is a morning delivery run. The factors that matter might include the distance to the customer, the traffic conditions, and the weather. Choosing these factors is your decision as the modeler.
- 2Stage 2: Model how the factors work together
You write down your model of how the factors combine to affect the outcome. For example, you might assume that heavy traffic and longer distances both make a late arrival more likely, and that the two effects can add up. This model is the custom model you have built, and it is still a description, not a computed result.
- 3Stage 3: Compute predictions
Only now do you use a probabilistic programming language. It works with the model you wrote down and computes predictions about whether the delivery will be on time. The language does not decide that traffic or weather matter. Those choices came from you in Stage 1 and Stage 2.
Each stage contributes something different. The situation and factors are your description, the model is your statement of how the factors interact, and the probabilistic programming language performs the computation that produces the prediction.
What the Language Actually Does
The source describes probabilistic programming languages as methods that compute predictions directly from a custom model. It presents them as the most general methods for this purpose. Their main value is that they let you express a learning problem in a very elegant and compact way. In other words, the language is the part that turns your written model into predictions, while you remain responsible for the description and the model itself.
Two Languages Named in the Source
The source names two popular probabilistic programming languages. Both serve the same general purpose of computing predictions from a custom model, but the source describes them in different ways. The source's emphasis is on how each one connects to Python. The table below summarizes only what the source states, and the source does not compare their performance or features, so no conclusions beyond this scope should be drawn.
| Language | Relationship to Python, as stated in the source |
|---|---|
| PyMC | Can be used in Python |
| Stan | A framework that can be used from several languages, including Python |
What the source states about how PyMC and Stan relate to Python
Prerequisites Before the Tools Simplify Work
Probabilistic programming languages significantly simplify the creation of new models, but they do not remove the need for foundational understanding. The source states that these tools still require some understanding of probability theory. Before the tools can make model creation easier, you need to be able to describe a situation, reason about how several factors combine to influence an outcome, and understand the probability ideas that the model is built on.
- Describing a real situation and deciding which factors matter
- Reasoning about how several factors work together to influence an outcome
- Understanding enough probability theory to read and write a probabilistic model
- Knowing how to use a probabilistic programming language to compute predictions once the model exists
Common Confusions About the Process
Common mistake Expecting the language to decide which factors matter
What it looks likeRunning a probabilistic programming language on a delivery situation and assuming it will find out whether traffic affects on-time arrival by itself.
Why it failsThe source says the language does not decide what the situation is or which factors are included. Those choices come from the modeler.
Do this insteadChoose and describe the factors yourself in the first two stages, then use the language to compute predictions from the model you wrote.
Common mistake Skipping straight to computing predictions
Why it failsThe source presents a clear order in which the situation and model come before the computation. The computation step works on a model, so there is nothing to compute until the model exists.
Do this insteadFollow the order: express the situation, model how the factors work together, and only then compute predictions.
Common mistake Treating PyMC and Stan as the same kind of tool
Why it failsThe source describes PyMC as usable in Python and Stan as a framework usable from several languages, with Python as one option.
Do this insteadKeep the scope difference in mind: PyMC is described as a Python tool, while Stan is described as a multi-language framework.
Common mistake Assuming the tools remove the need to learn probability
Why it failsThe source states that these tools still require some understanding of probability theory.
Do this insteadBuild the probability foundations first so that you can read, check, and write the models the tools help you compute.
Sorting the Stages of a Prediction
A team wants to predict whether a customer will renew a subscription. They list the customer's usage, the number of support requests, and the time since the last purchase as relevant factors, and they write down how these factors combine to affect renewal. Using the three-stage order from the source, say which stage each of these actions belongs to: listing the factors, writing down how they combine, and running a probabilistic programming language to compute the renewal predictions.
Hints
- The first stage is expressing the situation, which includes deciding which factors matter.
- The second stage is the model of how the factors work together.
- The third stage is where a probabilistic programming language computes predictions from the model.
Key Takeaways
- Building a custom model is a three-stage process: express the situation, model how the factors work together, then compute predictions.
- Probabilistic programming languages handle the third stage. They compute predictions directly from the custom model you have described.
- The modeler chooses the situation, the factors, and the model. The language does not make those choices.
- PyMC can be used in Python, while Stan is a framework that can be used from several languages, including Python.
- These tools significantly simplify model creation but still require some understanding of probability theory.