# What Is scikit-learn?

scikit-learn is a machine learning (ML) library for the [Python](https://www.python.org/) programming language that has a large number of algorithms that can be readily deployed by programmers and data scientists in machine learning models.

## Overview of scikit-learn

scikit-learn is a widely used open-source library in the Python ecosystem, designed specifically for machine learning-related tasks. Built on top of NumPy, SciPy, and Matplotlib, it provides a robust suite of tools and algorithms for machine learning tasks like data analysis, preprocessing, model development, and evaluation.

At the core of scikit-learn is its well-designed API, which ensures consistency and simplicity across various machine learning workflows. This makes it easy for developers and data scientists to implement tasks like regression, classification, clustering, and dimensionality reduction, all using a similar API. The library provides efficient implementations of popular algorithms, such as support vector machines, random forests, XGBoost, gradient boosting, k-means clustering, and DBSCAN.

scikit-learn also integrates with other data processing and analysis Python libraries, such as pandas for handling structured datasets and Matplotlib for creating visualizations. Its integration with the NumPy ecosystem allows for efficient numerical computations, while its integration with SciPy ensures access to advanced scientific computing functions.

scikit-learn is written primarily in Python, while Cython and C/C++ are used for implementing the most computationally intensive operations to achieve high performance. scikit-learn is inherently not multi-threaded, which can limit its ability to process large datasets efficiently and take advantage of modern multi-threaded computing platforms. New libraries and techniques can be used to achieve higher performance while balancing ease of use.

scikit-learn, as an open-source library, is built from contributions from a large community of developers and researchers, with its source code hosted on [GitHub](https://github.com/scikit-learn/scikit-learn). Comprehensive documentation and tutorials are created using tools like Sphinx, which has a familiar documentation layout that makes it easier for users to learn the library and apply it to real-world problems, especially if they have encountered these types of documents before.

Compatible with popular operating systems like Linux, macOS, and Windows, scikit-learn has become a de facto machine learning framework for data scientists using Python. Its simple, repeatable Python API, coupled with its extensive collection of tools and algorithms, makes it easy to learn and adopt for beginners and experts.

## Why scikit-learn?

scikit-learn is a robust Python library and a de facto standard for implementing machine learning models. Known for its ease of use, well-designed API, and active community, scikit-learn provides an extensive suite of tools for machine learning operation tasks, such as data preparation, preprocessing, model building, evaluation, inference, and optimization.

Key modules in scikit-learn support a wide range of machine learning techniques, including:

1. Preprocessing: Tools for feature extraction, scaling, and normalization prepare data for effective analysis and modeling. These steps are critical for ensuring consistent performance across models in both supervised and unsupervised learning.
2. Dimensionality Reduction: scikit-learn provides tools for reducing the number of variables in a dataset, enhancing efficiency and clarity, particularly for visualizations or computationally expensive models.
3. Classification: scikit-learn offers a variety of classifiers, including logistic regression, decision trees, random forests, and gradient boosting, to predict categorical outcomes. For example, these tools can classify emails as spam or legitimate, or they can predict customer segmentation categories.
4. Regression: Regression tools model relationships between input and output variables, enabling predictions of continuous values, such as stock prices and housing costs.
5. Clustering: In unsupervised learning, clustering methods automatically group data points with similar characteristics, such as grouping customer data based on purchasing behavior or geographic location.
6. Model Selection and Metrics: scikit-learn offers algorithms and utilities to compare, validate, and tune models. Using appropriate metrics, these tools help identify the best models and parameters for specific machine learning tasks.
7. Pipeline Utilities: Pipelines in scikit-learn streamline workflows by chaining together multiple steps, from preprocessing to model fitting and evaluation, ensuring efficient and reproducible machine learning pipelines.
8. Visualizations: scikit-learn supports quick plotting and visualization of data and models, aiding in model interpretation and adjustment.

With its support for tools like logistic regression, decision trees, random forests, and dimensionality reduction, scikit-learn has become a standard Python library for addressing machine learning tasks.

## How Does scikit-learn Work?

scikit-learn is a versatile Python library built on NumPy, optimized for high-performance linear algebra and array operations. To enhance performance, core scikit-learn algorithms are often implemented in Cython. It provides an efficient, high-level framework for building, training, and evaluating machine learning models with minimal code.

At its core, scikit-learn offers a consistent API for constructing machine learning workflows, emphasizing modularity and ease of use. Its documentation provides detailed guidance for each function, ensuring clarity and usability for developers.

### Key Components of scikit-learn Workflows

* Input Data and Transformers  
   In a scikit-learn workflow, input data, often organized in a dataframe, is passed through transformers to preprocess and extract features. Transformers apply algorithms to clean or reshape the training data before it is fed into a model. For example, feature scaling or encoding categorical variables prepares the subset of input data for optimal performance.
* Dimensionality Reduction  
   For datasets with many features, dimensionality reduction techniques, such as PCA, can simplify the input data by reducing the number of variables while retaining meaningful patterns. This is particularly useful in workflows involving large dataframes.
* Iterators for Data Handling  
   To handle large datasets efficiently, scikit-learn supports iterators, which allow batch processing of input data without loading the entire dataset into memory.
* Estimators and Model Training  
   An estimator is the core machine learning algorithm that fits the training data to produce a model. Estimators handle tasks ranging from regression to clustering, such as k-means or classification.
* Pipelines  
   Pipelines in scikit-learn chain transformers and estimators into a cohesive workflow, ensuring consistent preprocessing, training, and prediction steps. This eliminates redundancy and streamlines experimentation.
* Model Selection and Hyperparameter Tuning  
   For effective model selection, scikit-learn incorporates tools like grid search and cross-validation to identify the best hyperparameters and evaluate model performance. Cross-validation splits the training data into multiple subsets, allowing iterative testing and validation. Grid search further automates hyperparameter optimization, testing various configurations for improved accuracy.

By chaining transformers, estimators, and evaluators through pipelines, scikit-learn ensures reproducible and efficient machine learning workflows. From preprocessing input data to fine-tuning with grid search, the library provides a comprehensive suite of tools to empower data scientists.

## What Are Real-World Applications of scikit-learn?

scikit-learn is a versatile tool widely used in machine learning and data analysis across industries. Its full set of algorithms, metrics, and utilities supports both supervised learning and unsupervised learning, making it valuable for solving real-world problems in Python.

* Predictive Analytics With Regression and Classification Models  
   In industries like finance and healthcare, regression models are used to predict continuous outcomes, such as stock prices, patient recovery times, and energy consumption. scikit-learn’s classifier estimators help with tasks like predicting customer churn and email spam detection.
* Decision Trees and Ensemble Methods  
   scikit-learn provides robust implementations of decision trees, random forests, and gradient boosting for handling complex datasets. These algorithms are frequently employed in fraud detection, credit scoring, and recommendation systems, offering interpretable and high-performance models.
* Dimensionality Reduction for Big Data  
   Techniques like PCA and t-SNE, available in scikit-learn, simplify large datasets by reducing the number of features without losing critical information. This is especially beneficial in fields like genomics or image processing, where datasets often contain thousands of variables.
* Unsupervised Learning for Clustering and Connectivity  
   scikit-learn’s unsupervised learning algorithms, such as k-means clustering, are commonly used in customer segmentation, anomaly detection, and network analysis. Applications involving connectivity, like social network analysis and supply chain optimization, rely heavily on clustering techniques.
* Metrics for Model Evaluation  
   scikit-learn offers a comprehensive set of metrics to evaluate model performance, from accuracy and F1 scores for classifiers to mean squared error for regression tasks. These tools ensure models meet the necessary standards for deployment in production environments.
* Integration With Neural Networks and Deep Learning  
   While scikit-learn specializes in classical machine learning algorithms, it integrates seamlessly with deep learning frameworks like TensorFlow and PyTorch. This allows data scientists to use scikit-learn for data analysis, preprocessing, and model evaluation while leveraging the power of neural networks for more complex tasks.

With its versatility and ease of use, scikit-learn offers practical solutions for dimensionality reduction, classification, and advanced machine learning tasks.

### GPU-Accelerated scikit-learn APIs and End-to-End Data Science

GPUs are revolutionizing data science by providing massively parallel architectures optimized for handling thousands of threads simultaneously. These are in contrast to CPUs, which have fewer cores and are optimized for sequential processing. NVIDIA’s cuML library enables data scientists and machine learning engineers familiar with scikit-learn to take advantage of GPUs.

cuML is a suite of fast, GPU-accelerated machine learning algorithms designed for data science and analytical tasks that mirrors scikit-learn’s APIs. It is part of the NVIDIA RAPIDS™ suite of open-source libraries that offers a scalable platform for executing end-to-end data science pipelines on GPUs. This GPU advantage enables faster optimization of data science workflows, particularly for tasks like data processing, machine learning, deep learning, dimensionality reduction, and neural network training and inference.

NVIDIA cuML leverages NVIDIA® CUDA® primitives to deliver low-level compute optimization while exposing GPU power through Python-friendly scikit-learn APIs. cuML is available on GitHub, providing practitioners with the easy fit-predict-transform paradigm without ever having to program on a GPU.

### Key Features of RAPIDS With scikit-learn-Like APIs

1. Familiar scikit-learn APIs for Machine Learning  
    RAPIDS provides GPU-accelerated implementations of popular libraries and algorithms like pandas, scikit-learn, and XGBoost. These libraries and algorithms follow a scikit-learn-like API, enabling seamless integration for users familiar with traditional machine learning workflows implemented in scikit-learn.
2. Data Loading With GPU DataFrames  
    RAPIDS introduces a GPU-based DataFrame with a pandas-like interface, allowing data to be loaded and processed entirely on GPUs. This facilitates routing data through connected machine learning and graph analytics workflows without transferring data between GPU and host memory.
3. End-to-End Data Science Pipelines  
    By integrating dimensionality reduction, feature extraction, and deep learning, RAPIDS supports acceleration for complete data science pipelines. Users can preprocess data, build machine learning models, and even train neural networks without leaving the GPU.
4. Device Memory Sharing  
    RAPIDS enables shared device memory across popular libraries, reducing the overhead of data transfers. This ensures efficient routing of data between tools, avoiding costly back-and-forth copying between host and GPU memory.
5. Optimized Performance for Large Datasets  
    GPU-accelerated algorithms in NVIDIA RAPIDS can process large datasets 5–50X faster than CPU-based implementations. This speedup is crucial for tasks like dimensionality reduction, model training, and graph analytics.

### Transforming Data Science With RAPIDS

The NVIDIA RAPIDS ecosystem, combined with its scikit-learn-like API, enables data scientists to handle compute-intensive machine learning and deep learning tasks with higher efficiency.

## How to Get Started With Accelerated scikit-learn Using cuML?

Content adapted from: [cuML on GPU and CPU](https://docs.rapids.ai/api/cuml/stable/execution_device_interoperability/#Installation)

All installation documentation can be found in the [RAPIDS Installation Guide](https://docs.rapids.ai/install). NVIDIA RAPIDS cuML can run on CPU and GPU systems. For GPU systems, cuML follows the [RAPIDS requirements](https://rapids.ai/#quick-start). There are two main ways to use the CPU capabilities of cuML. The CPU package, cuml-cpu, is a subset of the cuML package, so there are zero code changes required to run the code when using a CPU-only system. In addition to allowing zero-code-change execution in CPU systems, users can also manually control which device executes parts of the code when using a system with the full cuML. By default, cuML will execute estimators on the GPU/device. But it also allows a global configuration option to change the default device, which could be useful in shared systems where cuML is running alongside deep learning frameworks that are occupying most of a GPU. This can be accomplished with the set\_global\_device\_type function.

A full table of accelerated functions, like the table below, can be found in the [cuMl 24.12.00 Documentation](https://docs.rapids.ai/api/cuml/stable/execution_device_interoperability/#Installation).

|  |  |  |  |
| --- | --- | --- | --- |
| **Category** | **Algorithm** | **Supports Execution on CPU** | **Supports Exporting between CPU and GPU** |
| **Clustering** | Density-Based Spatial Clustering of Applications With Noise (DBSCAN) | Yes | No |
|  | Hierarchical Density-Based Spatial Clustering of Applications With Noise (HDBSCAN) | Yes | Partial |
|  | K-Means | Yes | No |
|  | Single-Linkage Agglomerative Clustering | No | No |
| **Dimensionality Reduction** | Principal Components Analysis (PCA) | Yes | Yes |
|  | Incremental PCA | No | No |
|  | Truncated Singular Value Decomposition (tSVD) | Yes | Yes |
|  | Uniform Manifold Approximation and Projection (UMAP) | Yes | Partial |
|  | Random Projection | No | No |
|  | t-Distributed Stochastic Neighbor Embedding (TSNE) | No | No |
| **Linear Models for Regression or Classification** | Linear Regression (OLS) | Yes | Yes |

## Next Steps

### See How to Get Started With RAPIDS

Learn how to accelerate scikit-learn with [RAPIDS cuML](https://docs.rapids.ai/api/cuml/stable/?_gl=1*89j8uj*_ga*MTQ3Nzk2NDcwMi4xNzI1NDAzNDg3*_ga_RKXFW6CM42*MTczNzc0OTQ3OS4xOC4xLjE3Mzc3NTAzMzguNjAuMC4w) and seamlessly integrate GPU-acceleration into your data science workflows.

[Visit RAPIDS Get Started Page](https://developer.nvidia.com/rapids/get-started)

### Dive Deeper Into RAPIDS cuML

Learn more about how RAPIDS cuML accelerates scikit-learn on the NVIDIA Technical Blog, and explore the source code on [Github](https://github.com/rapidsai/cuml).

[Read RAPIDS cuML Blogs](https://developer.nvidia.com/blog/search-posts/?q=rapids+cuML)

### Watch RAPIDS cuML Videos and Tutorials on Demand

Watch videos and tutorials on accelerating scikit-learn with RAPIDS cuML.

[Watch RAPIDS cuML Videos](https://www.nvidia.com/en-us/on-demand/search/?facet.mimetype%5B%5D=event%20session&layout=list&page=1&q=cuML&sort=relevance&sortDir=desc)