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:
- Navigate to your
projectdirectory. - Open your Terminal or Command Prompt and navigate to the root directory of your Python project, where the
requirements.txtfile is located:cd /path/to/your/project
- 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_namewith your desired name for the virtual environment, e.g.,venvorscikitlearncookbook.) - Activate the virtual environment:
- On macOS/Linux, use the following:
source venv_name/bin/activate
- On Windows, use this:
venv_name\Scripts\activate
- On macOS/Linux, use the following:
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.