Concepts / Checking Library Versions

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.

  • Programming

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.

Version requirement0.18 or laterInstalledscikit-learnthe release you actuallyhaveImport statementresolves against thatreleaseCode that runsworks only if the importresolvedmust be met bydeterminesgates
What happens between the version requirement, the installed library, the import statement, and the code that runs, and where a mismatch breaks things?

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

Definition

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.

Key point

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
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.

Measurementsfour values in centimetersLabelthe species of this flowerClassessetosa, versicolor,virginicadescribes the flower, paired withis one of
How each measured flower maps to one species name, and how the label and the classes relate to each other.

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.

Worked example

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.

  1. 1
    Identify the features

    The four measurements of the new flower, two petal values and two sepal values in centimeters, are the features.

  2. 2
    Identify 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.

  3. 3
    Identify the classes

    The classes are every possible output: setosa, versicolor, and virginica. The model must answer with one of these three names.

Result

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.

Supervised learningtraining data with knownoutputsClassificationproblempredict one of severaloptionsIris speciesthree classescontainsapplied as
Which category contains which: classification is a kind of supervised learning, not the other way around.
TermWhat it describesQuestion it answersIris application
Supervised learningHow the model is trainedAre the correct outputs known during training?Yes, each flower comes with its species
ClassificationWhat kind of output is wantedWhich 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.

Find installedreleaseAt least 0.18?model_selectionimports resolveNewer than theauthors used?Within therecommendationAdjust imports tomatch releasecompare with 0.18yesnooptional checkyes
The steps and decisions in checking whether the installed scikit-learn meets the minimum version, and what happens if it does not.
Worked example

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.

  1. 1
    Find the release

    The installed release is below 0.18, so it is under the floor the material assumes.

  2. 2
    Apply the floor

    The floor is 0.18 or later. A release below it does not satisfy the requirement.

  3. 3
    Check the import

    The model_selection module was added in 0.18, so the import will not resolve as written on this release.

  4. 4
    Choose 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.

Result

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 fails

    The 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 instead

    Check 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 fails

    Different 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 instead

    Find the installed release before trusting an import line you copied from elsewhere.

  • Common mistake

    Confusing the labels with the measurements

    Why it fails

    The measurements describe the flower, while the label names what the flower is. They play different roles in training.

    Do this instead

    Keep 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

MEDIUM

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.
EASY

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_selection module 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.

Related concepts

More concepts starting with C