Concepts / Working with scikit-learn's machine learning algorithms

Working with scikit-learn's machine learning algorithms

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 Use 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. For that reason, practitioners usually rely on a library: a collection of tested, reusable tools that someone else has already built.

scikit-learn is one such library. It is an open source Python library for machine learning, and it is free to use and distribute. 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.

What scikit-learn Contains

scikit-learn offers two main things, and they belong together. The first is a set of state-of-the-art machine learning algorithms. The second is comprehensive documentation for each of those algorithms. The algorithms give you working tools, and the documentation explains what each tool is for and what options it offers.

scikit-learnopen source Python libraryMachine learningalgorithmsstate-of-the-art toolsUser guidethorough resourceDocumentationone entry per algorithmAPI documentationthorough resourcecontainscontainsincludesincludes
Which parts sit inside the one scikit-learn project, and which resources belong to the documentation side?

Notice what the source does not do. It describes the algorithms only as state-of-the-art and does not list which specific algorithms the library contains. For that level of detail, the documentation is the right place to look. This division of labor is why the source recommends the documentation so strongly.

What Open Source Means for You

Definition

Open source describes access, not only cost. For scikit-learn, the source code is available to anyone who wants to obtain and examine it, and the library is free to use and distribute.

Because the source code is available, 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 only call functions that return results.

Open source projects of this kind are also 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.

What do you think happens?

If a step inside scikit-learn produces a result you do not understand, can you look at the code that performs that step?

Reveal answer
Answer:

Yes, in principle. Because the source code is available to anyone, the code behind a step can be read.

Open source gives you access to the implementation, so you can move past treating the library as a black box.

Reading the Chapter with the Documentation

The source gives a concrete instruction for reading this material. While you read the chapter, you should also 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 two resources are meant to be used together, not one after the other.

Read a section ofthe chapterBrowse the user guideand API documentationfor detail on the algorithmNote the options eachalgorithm offersContinue the chapteralongsidethenreturn to
In what order should a learner read the chapter and consult the documentation?
Worked example

Planning one study session

You are about to study a section of the chapter that introduces a scikit-learn algorithm. How should you use the chapter and the documentation together in one session?

  1. 1
    Start with the chapter

    Read the section first so you know the idea the algorithm serves and the prerequisite concepts it assumes.

  2. 2
    Open the documentation for that algorithm

    Browse the user guide or API documentation to find the detail the chapter does not give, such as the options available for that algorithm.

  3. 3
    Compare the two

    Match what the chapter says about the algorithm with what the documentation lists. The chapter explains purpose; the documentation adds breadth.

  4. 4
    Return to the chapter

    Continue reading with the options in mind, so the next section makes more sense.

Result

The chapter supplies the understanding and the documentation supplies the detail. Used together, they cover more than either does alone.

Why scikit-learn Stands Out

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, and it works well with a number of other scientific Python tools, which the chapter discusses later.

Those two settings have different goals. Companies usually want models that solve business problems. 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. The combination of state-of-the-art algorithms, thorough documentation, and open source access is what allows one library to serve both.

Misreadings of the Library's Role

  • Common mistake

    Treating scikit-learn as a complete working environment by itself

    Why it fails

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

    Do this instead

    Think of scikit-learn as one component you will combine with other tools.

  • Common mistake

    Expecting the chapter to list every algorithm the library contains

    Why it fails

    The source describes the algorithms only as state-of-the-art and sends readers to the documentation for specifics.

    Do this instead

    Use the user guide and API documentation to find which algorithms exist and what options each one offers.

  • Common mistake

    Assuming open source only means the software is free

    Why it fails

    The phrase describes access to the source code, not only cost. It lets you examine how a step works.

    Do this instead

    Remember that you can read the code behind a step, which supports understanding rather than only calling functions.

  • Common mistake

    Reading the documentation only after finishing the chapter

Checking Your Understanding

EASY

A classmate says, "scikit-learn is a free tool, so there is nothing more to learn about it." Using what this article describes, explain what is missing from that claim and name the two resources a learner should use to fill the gap.

Hints
  • Think about what the phrase open source tells you beyond cost.
  • The source names the user guide and the API documentation as the place to find algorithm-level detail.

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 that belong together: state-of-the-art machine learning algorithms and comprehensive documentation for each one.
  • Read the chapter while browsing the user guide and API documentation, since the documentation supplies the detail and options the chapter does not list.
  • scikit-learn is very popular in industry and academia and works well with other scientific Python tools, which is why it is considered a prominent Python machine learning library.
  • Installing scikit-learn is a separate step that must be completed before the library can be used.

Related concepts

More concepts starting with W