Concepts / Overview of scikit-learn

Overview of scikit-learn

scikit-learn is an open source Python library for machine learning, free to use and distribute, with source code that anyone can obtain and examine.

  • Programming

Why Practitioners Reach for a Library

Suppose you want to apply machine learning to a problem in Python. You need algorithms that learn patterns from data, and you need to understand how each of those algorithms is meant to be used. Writing every algorithm yourself is slow and error-prone, so practitioners usually rely on a library: a collection of tested, reusable tools that someone else has already built.

scikit-learn is one such library. This article answers three questions before you go further into the chapter: what scikit-learn is, what it provides, and why it is worth knowing about. Keep the first question in mind as you read, because the answer shapes how you should approach everything else.

Open Source as Visible Code

Definition

scikit-learn is an open source Python library for machine learning. It is free to use and distribute, and its source code is something anyone can obtain and examine.

The phrase open source tells you something about access, not only about cost. Because the source code is available to anyone, you are not limited to trusting a black box. If you want to know what a particular step is doing behind the scenes, the code that performs that step can, in principle, be read. This transparency is one of the features that makes the library valuable to people who want to understand machine learning rather than just call functions that produce results.

What do you think happens?

If you want to know what a particular step inside scikit-learn is doing, can you look at the code that performs it?

  • No, the internals are hidden and you can only use the results

  • Yes, in principle, because the source code is available to anyone

Reveal answer
Answer:

Yes, in principle, because the source code is available to anyone.

Open source describes access. Anyone can obtain and examine the code, so the step you are curious about can be read rather than taken on trust.

Open source also means the project is not frozen at one moment in time. The source describes scikit-learn as constantly being developed and improved, with a very active user community. Improvements arrive continually, and the people who use the library also take part in shaping it.

Tracing a Question to a Working Tool

Worked example

Following one machine learning need through scikit-learn

You have a machine learning problem in Python and want to know what scikit-learn can do for you, and in what order you should take the steps.

  1. 1
    Start with the need

    You need an algorithm that learns patterns from data. Writing one from scratch is slow and error-prone, so you look for a library that already contains tested tools.

  2. 2
    Find the algorithms

    scikit-learn contains a number of state-of-the-art machine learning algorithms. These give you working tools rather than a blank page.

  3. 3
    Consult the documentation for each one

    Each algorithm comes with comprehensive documentation describing what it is for and what options it offers. The algorithms and their documentation belong together.

  4. 4
    Go deeper in the user guide and API documentation

    For more detail and for the many options available for each algorithm, browse the user guide and API documentation while you work through the chapter.

  5. 5
    Put the library on your own system

    Installing scikit-learn is a separate step. It is the step that makes the library usable on your machine. Learning what the library offers comes first in this chapter.

Result

The sequence is: recognize the need, find the algorithm, understand its documentation, then install the library so it can be used. Each step builds on the one before it.

Two Things the Library Offers

scikit-learn gives you two main things: machine learning algorithms and documentation. They are linked. The algorithms give you working tools, and the documentation explains what each tool is for and what options it offers. A diagram of this relationship follows.

scikit-learnopen source Python libraryMachine learningalgorithmsstate-of-the-art toolsUser guidebroader guidanceDocumentationexplains each toolAPI documentationoptions for each algorithmoffersofferseach accompanied byincludesincludes
How the algorithms and the documentation relate to each other inside the library

Learning Resources and How to Use Them

The source gives a concrete instruction for reading this material. While you read the chapter, browse the scikit-learn user guide and API documentation for more detail and for the many options available for each algorithm. The online documentation is very thorough, and the chapter supplies the machine learning prerequisites needed to understand it in depth. The flowchart below shows how these resources fit into your working sequence.

Read this chapterlearn what the libraryoffersBrowse user guidewhile readingInstall scikit-learnseparate stepUse the libraryonce it is on your systemCheck APIdocumentationoptions for each algorithmalongsidealongsidethenthenmakes usable
Which resources to consult as you move through the chapter, and where installation fits

Why scikit-learn Is Prominent in Python

The source describes scikit-learn as a very popular tool and as the most prominent Python library for machine learning. It is widely used in both industry and academia. These two settings have different goals. Companies usually want models that solve business problems, while universities and research groups often want to study and compare methods.

A library that serves both audiences has to be accurate, well documented, and easy to learn from. Its documentation for each algorithm, its open source code that can be examined, and its continuing development together account for much of its appeal.

scikit-learn also works well with a number of other scientific Python tools. Keep this in mind as you learn: scikit-learn is usually one piece of a larger working setup rather than a complete environment by itself. The chapter discusses those other tools later.

Mistakes Learners Make With the Library

  • Common mistake

    Treating scikit-learn as a complete environment by itself

    What it looks like

    Assuming that installing the library is enough to cover every part of a working setup.

    Why it fails

    The source notes that scikit-learn works with other scientific Python tools and is usually one piece of a larger setup.

    Do this instead

    Think of scikit-learn as one component, and expect to learn how it connects to the other tools the chapter covers.

  • Common mistake

    Expecting this overview to list every algorithm

    What it looks like

    Looking for a full catalogue of algorithms in this article and feeling that something is missing.

    Why it fails

    The source describes the algorithms only as state-of-the-art and does not name them. Detailed lists belong to the documentation.

    Do this instead

    Use the user guide and API documentation to find the specific algorithms and their options.

  • Common mistake

    Reading the algorithms without their documentation

    What it looks like

    Choosing an algorithm and guessing its options from its name alone.

    Why it fails

    Each algorithm is accompanied by documentation that explains what it is for and what options it offers.

    Do this instead

    Pair every algorithm you use with its documentation before relying on it.

  • Common mistake

    Assuming open source only means the software is free of charge

Check Your Understanding

EASY

Name the two main things scikit-learn offers. Then say which one you would consult to find the options available for a specific algorithm, and explain why.

Hints
  • One offering is a set of machine learning algorithms and the other is documentation.
  • The documentation explains what each algorithm is for and what options it offers.
  • The API documentation and user guide are the resources the chapter recommends browsing.

Key Takeaways

  • scikit-learn is an open source Python library for machine learning. It is free to use and distribute, and its source code can be obtained and examined by anyone.
  • The library offers two main things: a number of state-of-the-art machine learning algorithms, and comprehensive documentation that accompanies each algorithm.
  • While you read this chapter, browse the user guide and API documentation for more detail and for the options available for each algorithm. Installation is a separate step that makes the library usable on your system.
  • scikit-learn is very popular in industry and academia, works well with other scientific Python tools, and is usually one piece of a larger working setup.

Related concepts

More concepts starting with O