Checking Library Versions
A version floor is a lower bound. Any installed release at or above the floor satisfies it. Any release below the floor does not.
A Botanist, Four Measurements, and a Version Number
Before you write any machine learning code, you need the right tools installed. The first real application in this material is built around a hobby botanist who has found some iris flowers and wants to tell their species apart. For every iris she has measured, she has recorded four quantities in centimeters: the length and width of the petals, and the length and width of the sepals. Those four numbers describe one flower.
The application comes with a version requirement attached. The requirement is short, but it teaches a lesson that applies to every library you will use: the version of a library you have installed determines which functions and import paths your code can rely on. This article uses that one requirement to show how to check any version requirement you meet in the same way.
Watching the Version Floor Work
Start with the library itself. scikit-learn is a Python library for machine learning. Different releases of it do not always offer the same modules or the same import paths. A program that runs cleanly on one release can fail on an older one, because a function or module it depends on was not yet available.
Read the chain from left to right. The requirement says what release the material expects. The installed release is what your Python environment actually provides. An import statement is resolved against the installed release, not against the requirement written in the text. So the code that runs depends on the installed release, and a gap between the two shows up as a failed import rather than as a subtle wrong answer.
What 0.18 Means as a Floor
The material assumes scikit-learn 0.18 or later. A version at least as recent as the one the authors used is recommended rather than an exact match.
The number 0.18 is a floor, not a target. Anything at 0.18 or above is what the material expects. You are not being asked to install one exact release. The material also recommends a release at least as recent as the authors used, so a newer release is a safe choice, while an older one below 0.18 is not.
A version floor is a lower bound. Any installed release at or above the floor satisfies it. Any release below the floor does not.
Why model_selection Sets the Floor
The reason the floor sits at 0.18 is the model_selection module. That module was added in version 0.18. Any code that imports from model_selection depends on the release that contains it. This is what makes the version number concrete: it is not an arbitrary cutoff, but the first release in which a specific module exists.
Consider what happens on an earlier release. If you install a version below 0.18, imports from model_selection will not resolve as written. You will then need to adjust those imports so they match what your installed version provides. The underlying idea is the same one shown in the pipeline above: the import is only as good as the release it is resolved against.
What do you think happens?
Suppose your installed scikit-learn is older than 0.18, and your code begins with an import from model_selection. What do you think happens?
Reveal answer
The import will not resolve as written, because the model_selection module was added in 0.18 and an earlier release does not contain it. You would need to adjust the import to match what the installed version provides.
The module is only available from 0.18 onward, so a release below that floor cannot satisfy an import that depends on it.
Measurements, Labels, and Known Answers
The botanist's situation is a supervised learning problem. In supervised learning, we have measurements for which we already know the correct output. The known correct outputs are what set this setting apart: the model is given examples together with their answers and learns the relationship between them.
The idea of a label is simple, but it is easy to confuse with the measurements. The measurements describe the flower. The label names what the flower is. The botanist wants a model that learns from measurements whose species is already known, so that it can predict the species of a new iris from its measurements alone.
Read the diagram as a mapping. One flower's four measurements are the features. Each flower carries exactly one label, which is its species. The label must be one of the classes, which are the full set of allowed answers. The measurements tell the model what to look at, and the label tells it what the right answer was for that flower.
Three Classes of Iris
Within supervised learning, this application is a classification problem. In a classification problem, we want to predict one of several options. Here the options are the species of iris, and the possible outputs are called classes.
Every iris in the dataset belongs to one of three classes: setosa, versicolor, or virginica. Because there are exactly three possible outputs, the problem is described as a three-class classification problem. The number of classes is a property of the problem, and it tells you how many distinct answers the model is allowed to give.
Naming the parts of one iris prediction
A new iris is measured, and the botanist wants the model to name its species. Identify the features, the label, and the classes.
- 1Identify the features
The four measurements of the new flower, two petal values and two sepal values in centimeters, are the features.
- 2Identify the label
The species name is the desired output for this one data point. For training flowers, the label is already known. For the new flower, it is what the model must predict.
- 3Identify the classes
The classes are every possible output: setosa, versicolor, and virginica. The model must answer with one of these three names.
Features: four measurements. Label: the species of this flower. Classes: setosa, versicolor, virginica, making this a three-class problem.
Supervised Learning Versus Classification
The two terms in this article are easy to mix up because they describe the same problem from different angles. Supervised learning describes how the model is trained: it learns from data where the correct outputs are known. Classification describes what kind of output is wanted: one option out of several named categories. The iris application is both at once.
| Term | What it describes | Question it answers | Iris application |
|---|---|---|---|
| Supervised learning | How the model is trained | Are the correct outputs known during training? | Yes, each flower comes with its species |
| Classification | What kind of output is wanted | Which of several named categories applies? | Yes, one species out of three |
Two terms, one problem, viewed from two angles
Checking a Version Requirement Step by Step
The method you learn here works for any version requirement. Start by finding out which release is installed, then compare it with the floor the material states. The decisions below follow that order, and each branch tells you what to do next.
Deciding whether a release is enough
A learner's installed scikit-learn is below 0.18, and their code imports from model_selection. Decide what they should do.
- 1Find the release
The installed release is below 0.18, so it is under the floor the material assumes.
- 2Apply the floor
The floor is 0.18 or later. A release below it does not satisfy the requirement.
- 3Check the import
The
model_selectionmodule was added in 0.18, so the import will not resolve as written on this release. - 4Choose a response
The learner must either adjust the imports to match what the installed release provides, or update to a release at or above the floor.
The release is below the floor, so the imports from model_selection need adjusting or the library needs updating before the code can run as written.
Mistakes With Version Floors
Common mistake Treating 0.18 as an exact version to install
Why it failsThe material calls 0.18 a floor. Anything at 0.18 or above is what it expects, and a more recent release is recommended.
Do this insteadCheck that the installed release is at or above 0.18, and prefer a release at least as recent as the authors used.
Common mistake Assuming all releases expose the same modules
Why it failsDifferent releases do not always offer the same modules or import paths, so code that runs on one release can fail on an older one.
Do this insteadFind the installed release before trusting an import line you copied from elsewhere.
Common mistake Confusing the labels with the measurements
Why it failsThe measurements describe the flower, while the label names what the flower is. They play different roles in training.
Do this insteadKeep features and label separate: the four measurements are inputs, and the species name is the known output.
Common mistake Using the words supervised learning and classification as if they were the same thing when they describe different angles of one problem
Practice Checking Your Own Setup
Suppose a tutorial you are following says it needs the model_selection module, and the material's requirement is scikit-learn 0.18 or later. Describe the three checks you would make before running the code, and say what you would do if the installed release failed the first check.
Hints
- Start with the installed release, not with the tutorial.
- Compare the installed release with the floor of 0.18.
- If the release is too old, think about whether the imports or the library should change.
For a new flower in the botanist's dataset, name its features, its label, and the classes it could belong to. Then say whether the problem is a supervised learning problem, a classification problem, or both, and why.
Hints
- The four measurements are features.
- The label is the species for that flower.
- Both terms describe the same iris problem from different angles.
Key Takeaways
- The material assumes scikit-learn 0.18 or later, treating 0.18 as a floor and recommending a release at least as recent as the authors used.
- The
model_selectionmodule was added in 0.18, so earlier releases require adjusting imports from that module. - In supervised learning, the data includes known correct outputs. Each flower's four measurements are features, and its species is the label.
- Classification is a kind of supervised learning in which the output is one of several named classes, here setosa, versicolor, and virginica.
- Any version requirement can be checked the same way: identify the installed release, compare it with the floor, and fix imports when the release is too old.