Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
scikit-learn Cookbook

You're reading from   scikit-learn Cookbook Over 80 recipes for machine learning in Python with scikit-learn

Arrow left icon
Product type Paperback
Published in Dec 2025
Publisher Packt
ISBN-13 9781836644453
Length 388 pages
Edition 3rd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
John Sukup John Sukup
Author Profile Icon John Sukup
John Sukup
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Chapter 1: Common Conventions and API Elements of scikit-learn 2. Chapter 2: Pre-Model Workflow and Data Preprocessing FREE CHAPTER 3. Chapter 3: Dimensionality Reduction Techniques 4. Chapter 4: Building Models with Distance Metrics and Nearest Neighbors 5. Chapter 5: Linear Models and Regularization 6. Chapter 6: Advanced Logistic Regression and Extensions 7. Chapter 7: Support Vector Machines and Kernel Methods 8. Chapter 8: Tree-Based Algorithms and Ensemble Methods 9. Chapter 9: Text Processing and Multiclass Classification 10. Chapter 10: Clustering Techniques 11. Chapter 11: Novelty and Outlier Detection 12. Chapter 12: Cross-Validation and Model Evaluation Techniques 13. Chapter 13: Deploying scikit-learn Models in Production 14. Chapter 14: Unlock Your Exclusive Benefits 15. Index 16. Other Books You May Enjoy

To get the most out of this book

This book is designed to provide basic examples of the most important features of scikit-learn v1.5. In order to maximize the effectiveness of your learning, in addition to completing the exercises in each chapter, we encourage you to try your own examples and explore additional function arguments beyond those presented. Additionally, combining your learning from different chapters is an effective way to coalesce your scikit-learning understanding holistically.

Software/hardware covered in the book

OS requirements

scikit-learn v1.5 or greater

Windows, macOS X, and Linux (any)

Git >=2.46.x

Python >=3.9.x

Each chapter reminds you of the GitHub repository where example code is stored and how to install it locally.

Installing Python libraries in virtual environments with requirements.txt

Installing Python packages from a requirements.txt file is a common practice for managing project dependencies. Here’s a step-by-step guide:

  1. Navigate to your project directory.
  2. Open your Terminal or Command Prompt and navigate to the root directory of your Python project, where the requirements.txt file is located:
    cd /path/to/your/project
  3. Using a virtual environment isolates your project’s dependencies from other Python projects on your system, preventing conflicts. Next, create the virtual environment:
    python -m venv venv_name

    (Replace venv_name with your desired name for the virtual environment, e.g., venv or scikitlearncookbook.)

  4. Activate the virtual environment:
    • On macOS/Linux, use the following:
      source venv_name/bin/activate
    • On Windows, use this:
      venv_name\Scripts\activate

Installing the packages

With your virtual environment activated (if you created one), use pip to install the packages listed in requirements.txt:

pip install -r requirements.txt

If you are not using a virtual environment or need to specify a particular Python executable, you might use pip3 instead of pip.

Verifying installation (optional)

You can verify that the packages are installed by running the following:

pip list

This command will list all the installed packages in your current environment, including those from requirements.txt.

When you are finished working on the project, you can deactivate the virtual environment:

deactivate

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/scikit-learn-Cookbook-Third-Edition.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and X/Twitter handles. For example: “Load KNeighborsClassifier from sklearn.neighbors.”

A block of code is set as follows:

from sklearn.model_selection import learning_curve
from sklearn.metrics import confusion_matrix
import seaborn as sns

Bold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: “Our single decision tree reported an accuracy of 0.867, while our random forest’s accuracy is 0.911.”

Tips or important notes

Appear like this.

lock icon The rest of the chapter is locked
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
scikit-learn Cookbook
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon