Python Libraries for Machine Learning

An interactive learning atlas by mindal.app

Launch Interactive Atlas

Python for ML — NumPy · pandas · scikit-learn

A foundational understanding of Python for Machine Learning (ML) invariably centers on three core libraries: NumPy, pandas, and scikit-learn. These libraries form the backbone of most traditional ML workflows, each serving distinct yet interconnected purposes. Their true power emerges from their seamless integration, where data flows from pandas for initial handling, to NumPy for numerical efficiency, and finally to scikit-learn for model building.

Key Facts:

  • NumPy is essential for efficient multi-dimensional array manipulation and mathematical computations that underpin machine learning algorithms.
  • Pandas is crucial for handling, cleaning, transforming, and structuring data into DataFrames, making it ready for modeling.
  • Scikit-learn provides a wide array of algorithms for classification, regression, clustering, and tools for model selection, evaluation, and streamlining workflows.
  • The synergistic relationship between these libraries involves data flowing from pandas for initial handling, to NumPy for numerical efficiency, and finally to scikit-learn for model building.
  • Scikit-learn Pipelines allow chaining data preprocessing steps and modeling into a single, cohesive process, ensuring consistency and reproducibility.

Integrated Machine Learning Workflow

The Integrated Machine Learning Workflow describes the synergistic relationship and seamless flow of data between NumPy, Pandas, and Scikit-learn to build robust ML solutions. Data typically moves from Pandas for initial handling, to NumPy for numerical efficiency, and finally to Scikit-learn for model building and evaluation.

Key Facts:

  • Data is often initially loaded and preprocessed using Pandas, where it's cleaned, transformed, and structured into DataFrames.
  • Processed data from Pandas is efficiently converted into NumPy arrays, which are the preferred input format for many Scikit-learn algorithms due to NumPy's numerical efficiency.
  • Scikit-learn then utilizes these prepared NumPy arrays to train models, evaluate their performance, and facilitate deployment.
  • This integrated approach allows data scientists to leverage the distinct strengths of each library.
  • The true power of these libraries emerges from their seamless integration within a typical ML workflow, creating robust and efficient machine learning solutions.

Data Ingestion and Initial Handling

Data Ingestion and Initial Handling refers to the critical first stage in an ML workflow where raw data is loaded, cleaned, transformed, and structured, primarily using Pandas DataFrames. This process prepares the data for subsequent numerical processing and model building.

Key Facts:

  • Data is often initially loaded, cleaned, transformed, and structured into DataFrames using Pandas.
  • This step involves tasks such as handling missing data, duplicates, and formatting issues.
  • Pandas provides tools for efficient data manipulation and preparation, making it easier to work with structured datasets.
  • It's a foundational step that precedes numerical efficiency improvements provided by NumPy.
  • Proper initial data handling directly impacts the quality and reliability of downstream machine learning models.

Machine Learning Pipelines

Machine Learning Pipelines represent a structured approach to automate and streamline the entire ML workflow, from data preprocessing to model training and evaluation. Scikit-learn's `Pipeline` object is a key tool for creating consistent and reproducible workflows, combining multiple steps into a single, sequential process.

Key Facts:

  • Building end-to-end pipelines using Scikit-learn's `Pipeline` and `ColumnTransformer` ensures consistent and reproducible workflows.
  • Pipelines help in managing the sequence of data transformations and model training.
  • They are essential for easy experimentation with different preprocessing steps and models.
  • Scikit-learn Pipelines streamline the process from raw data to predictions, reducing errors and improving efficiency.
  • This approach aids in automating tasks like feature scaling before feeding data into a model.

Model Building and Evaluation with Scikit-learn

Model Building and Evaluation with Scikit-learn involves utilizing prepared NumPy arrays to train machine learning models, assess their performance, and facilitate deployment. Scikit-learn offers a consistent interface for various algorithms and comprehensive tools for evaluation and hyperparameter tuning.

Key Facts:

  • Scikit-learn utilizes prepared NumPy arrays to train models, evaluate their performance, and facilitate deployment.
  • It provides a consistent interface for various machine learning algorithms, including classification, regression, and clustering.
  • Scikit-learn offers model evaluation metrics, cross-validation strategies, and hyperparameter tuning tools.
  • The `Pipeline` object in Scikit-learn is crucial for streamlining the workflow, combining preprocessing steps and model training.
  • This stage is where the core machine learning algorithms are applied to solve specific predictive tasks.

Model Deployment and Monitoring

Model Deployment and Monitoring focuses on the practical application of trained machine learning models in production environments and the continuous observation of their performance. This final stage ensures that models remain effective and are retrained when necessary.

Key Facts:

  • Model Serving involves integrating the trained ML model into existing software or production environments.
  • Monitoring Model Performance means continuously observing model performance based on live data and tracking key metrics.
  • Retraining Pipelines are triggered automatically or manually when model performance degrades.
  • This stage is crucial for realizing the business value of machine learning solutions.
  • Ensuring model reliability and fairness in real-world scenarios is a primary goal of this phase.

Numerical Efficiency and Preprocessing with NumPy

Numerical Efficiency and Preprocessing with NumPy focuses on the conversion of processed Pandas DataFrames into NumPy arrays, which are essential for many Scikit-learn algorithms. NumPy provides optimized performance for mathematical operations, crucial for tasks like scaling and normalization.

Key Facts:

  • Processed data from Pandas is efficiently converted into NumPy arrays.
  • NumPy's multidimensional array object is the preferred input format for many Scikit-learn algorithms.
  • NumPy arrays offer numerical efficiency and optimized performance for mathematical operations.
  • This stage is used for tasks like scaling, normalization, and other numerical data processing.
  • The seamless transition from Pandas to NumPy is a cornerstone of the integrated ML workflow.

NumPy

NumPy, or Numerical Python, is a fundamental library for scientific computing in Python, providing support for efficient multi-dimensional array objects and a collection of routines for mathematical operations on these arrays. It serves as the bedrock for many other Python ML libraries, including scikit-learn and deep learning frameworks.

Key Facts:

  • NumPy's primary contribution is the `ndarray` (n-dimensional array) object, which allows for efficient storage and manipulation of large datasets.
  • It offers significant speed and memory optimizations compared to standard Python lists for numerical data.
  • NumPy provides powerful functionalities for mathematical and logical operations on arrays, linear algebra, and random number generation.
  • It is used for data preprocessing tasks such as scaling and normalization, which are crucial for machine learning algorithms.
  • NumPy forms a foundational component for other Python ML libraries, making it essential for efficient data handling.

Advanced Array Manipulation

NumPy provides extensive functionalities for manipulating array structures, including transposing, reshaping, and sorting. These operations are essential for preparing and transforming data to meet the specific input requirements of various machine learning algorithms.

Key Facts:

  • NumPy offers functions for transposing arrays, which rearranges dimensions and is crucial for linear algebra and data analysis.
  • Reshaping arrays allows for changing their structure, often necessary for data preprocessing in machine learning.
  • Sorting array elements along specified axes is useful for data analysis and identifying extreme values.
  • Structured arrays allow for storing heterogeneous data types within a single array, akin to spreadsheet-like data.
  • These manipulation techniques are vital for transforming raw data into formats compatible with ML libraries like scikit-learn.

Linear Algebra

NumPy's `numpy.linalg` module provides a comprehensive suite of tools for performing linear algebra operations. These operations are fundamental to many machine learning algorithms, enabling tasks such as matrix multiplication, solving systems of equations, and computing vector norms.

Key Facts:

  • NumPy represents vectors and matrices as `ndarray` objects, which are crucial for machine learning algorithms.
  • The library supports essential operations like dot product and matrix multiplication (using `@` operator or `np.matmul()`), vital for linear regression and other ML models.
  • NumPy's linear algebra toolbox facilitates solving complex systems of equations and performing decompositions (e.g., LU, SVD), important for model optimization.
  • It enables the calculation of vector norms (e.g., L1 and L2 norms), which measure the size or length of vectors.
  • Linear algebra operations within NumPy form a foundational component for understanding and implementing a wide range of machine learning techniques.

ndarray Object

The `ndarray` object is the fundamental data structure in NumPy, representing an n-dimensional array. It is significantly more efficient than standard Python lists for numerical operations, forming the core of NumPy's performance advantages.

Key Facts:

  • The `ndarray` is NumPy's core object for efficient storage and manipulation of large datasets.
  • Unlike Python lists, NumPy arrays are homogeneous, meaning all elements must be of the same data type, which enhances efficiency.
  • It allows for efficient handling of multi-dimensional arrays, crucial for machine learning and data science.
  • The `ndarray` object is the primary contribution of NumPy for scientific computing.
  • Its efficiency over Python lists is due to its homogeneous nature and optimized underlying implementation.

Performance Optimization

NumPy achieves significant performance improvements over standard Python through techniques like vectorization, broadcasting, efficient indexing, and memory management. These optimizations are critical for handling the large datasets prevalent in machine learning.

Key Facts:

  • Vectorization involves replacing explicit Python loops with optimized NumPy functions, bypassing interpreter overhead.
  • Broadcasting enables arithmetic operations on arrays of different shapes without explicit reshaping, saving memory and improving performance.
  • Efficient indexing and slicing often create 'views' of arrays, which are memory-efficient as they avoid copying data.
  • Choosing appropriate data types (e.g., `np.float32`) and utilizing contiguous memory storage significantly optimize memory usage and performance.
  • In-place operations modify arrays directly, avoiding temporary array allocation and saving memory.

Pandas

Pandas is a crucial library for data manipulation and analysis, particularly with tabular data, using its DataFrame object. It streamlines the process of loading, cleaning, transforming, and structuring datasets, making raw data suitable for machine learning models.

Key Facts:

  • The DataFrame is Pandas' key data structure, simplifying the handling of structured datasets.
  • Pandas excels at tasks like handling missing data, identifying and removing duplications, and addressing formatting issues.
  • It provides built-in methods for data preparation, including scaling and one-hot encoding categorical variables.
  • Pandas is essential for exploratory data analysis and cleaning, transforming raw data into a model-ready format.
  • It facilitates split-apply-combine operations for fast data transformation, a common pattern in data preprocessing.

Advanced Data Transformation and Feature Engineering

Pandas is instrumental in advanced data transformation and feature engineering, enabling the creation of new, more informative features from existing data. These methods are crucial for enhancing the predictive power of machine learning models.

Key Facts:

  • The `.apply()` and `.transform()` methods enable the application of custom functions across Series or DataFrames for flexible data manipulation.
  • Categorical encoding techniques, such as one-hot encoding with `pd.get_dummies()`, convert non-numerical data into a format suitable for machine learning algorithms.
  • Grouping and aggregation operations via `groupby()` allow for efficient summarization and statistical analysis of data based on specific categories.
  • Reshaping functions like `pivot()`, `melt()`, `stack()`, and `unstack()` provide flexibility in restructuring DataFrames for different analytical needs.
  • Merging (`df.merge()`) and concatenating (`pd.concat()`) DataFrames facilitate combining data from multiple sources.

Data Cleaning and Preprocessing Techniques

Pandas offers a comprehensive suite of methods for cleaning and preprocessing raw data, which is a critical step in preparing data for machine learning models. These techniques address common issues such as missing values, duplicates, and data type inconsistencies.

Key Facts:

  • Initial data exploration uses functions like `df.head()`, `df.info()`, and `df.describe()` to understand data structure and summary statistics.
  • Missing data can be identified using `df.isnull()` and handled by removal (`df.dropna()`) or imputation (`df.fillna()`).
  • Duplicate records are detected with `.duplicated()` and removed using `.drop_duplicates()`.
  • Data type conversion is essential for consistency and accuracy, ensuring numerical columns are numeric and categorical are categorical.
  • Filtering and sorting data allow for extracting relevant subsets and organizing data based on specific conditions.

Integration with NumPy

Pandas leverages NumPy as its foundation, benefiting from NumPy's efficient array operations and numerical computation capabilities. This integration ensures fast and memory-efficient data processing, especially for large datasets, and facilitates seamless data flow between the two libraries.

Key Facts:

  • Pandas is built on NumPy arrays, utilizing its performance advantages for underlying numerical operations.
  • DataFrames can be easily converted to NumPy arrays using `.to_numpy()` or `.values` attribute, a common requirement for machine learning libraries.
  • Both Pandas and NumPy support vectorized operations, enabling computations on entire arrays or Series without explicit Python loops for speed.
  • NumPy's universal functions (ufuncs) and extensive mathematical library can be directly applied to Pandas Series and DataFrame columns.
  • The seamless integration means that data processed and manipulated in Pandas can be readily used by NumPy-based libraries, such as scikit-learn.

Integration with Scikit-learn

Pandas plays a crucial role in the machine learning workflow by integrating seamlessly with scikit-learn. It serves as the primary tool for data loading, exploration, and cleaning, preparing data to be transformed into the NumPy array format expected by scikit-learn models.

Key Facts:

  • Pandas is used for the initial stages of the machine learning pipeline: loading, exploring, and cleaning raw data.
  • Data processed by Pandas is typically converted into NumPy arrays, which is the standard input format for scikit-learn algorithms.
  • Pandas facilitates feature engineering, creating suitable inputs for scikit-learn models.
  • The robust data structures of Pandas help manage and organize data effectively before it enters the scikit-learn ecosystem.
  • This integration forms a cohesive and efficient workflow for building and deploying machine learning solutions.

Pandas Data Structures

Pandas provides flexible data structures like DataFrames and Series that are fundamental for handling tabular data. These structures allow for easy loading, exploration, and manipulation of datasets, forming the backbone of data processing in Python.

Key Facts:

  • DataFrame is Pandas' primary two-dimensional data structure, similar to a spreadsheet or SQL table, with labeled axes (rows and columns).
  • Each column in a DataFrame can hold different data types, providing flexibility for diverse datasets.
  • Series is a one-dimensional labeled array, functioning like a single column in a DataFrame.
  • These data structures enable easy loading of data from various formats like CSV, Excel, and SQL databases.
  • The DataFrame and Series objects are optimized for efficient data operations, leveraging NumPy's capabilities.

Scikit-learn

Scikit-learn is a comprehensive library providing a consistent interface for building, evaluating, and deploying a wide range of machine learning models. It includes algorithms for classification, regression, clustering, and tools for model selection, evaluation, and streamlining workflows.

Key Facts:

  • Scikit-learn offers a wide array of algorithms for supervised learning (classification, regression) and unsupervised learning (clustering, dimensionality reduction).
  • It provides essential tools for model evaluation metrics, cross-validation strategies, and hyperparameter tuning.
  • The library maintains a consistent API for all models, simplifying the process of trying different algorithms.
  • Scikit-learn's Pipeline utility is significant for chaining data transformations and modeling processes, ensuring data consistency.
  • It helps prevent data leakage and makes machine learning code cleaner, more readable, and easier to maintain.

Consistent API

A cornerstone of Scikit-learn's design is its consistent API, often referred to as the 'Estimator API', which provides a uniform interface across all its models. This consistency significantly simplifies the process of experimenting with and switching between different machine learning algorithms, reducing the learning curve and improving development efficiency.

Key Facts:

  • The 'Estimator API' provides a uniform interface for all models within Scikit-learn.
  • This consistency allows for easier experimentation and comparison of different algorithms for a given task.
  • Key methods like `fit()` for training and `predict()` for making predictions are standard across all estimators.
  • The consistent API enhances code readability and maintainability by providing a predictable interaction pattern.
  • This design choice abstracts away the internal complexities of individual algorithms, allowing users to focus on model application rather than implementation details.

Data Preprocessing and Feature Engineering

Scikit-learn provides comprehensive modules for data preprocessing and feature engineering, which are crucial steps in preparing raw data for machine learning models. These tools enable tasks such as scaling, normalization, handling categorical variables, imputing missing values, and generating new features to improve model performance.

Key Facts:

  • Scikit-learn includes modules for data preprocessing tasks like scaling (e.g., StandardScaler, MinMaxScaler) and normalization.
  • It offers functionalities for encoding categorical variables (e.g., OneHotEncoder, LabelEncoder) to convert them into a numerical format.
  • The library provides tools for handling missing values through various imputation strategies (e.g., SimpleImputer).
  • Scikit-learn supports generating polynomial features to capture non-linear relationships in data.
  • It also offers tools for feature extraction and selection, which are vital for reducing dimensionality and improving model efficiency.

Model Selection and Evaluation

Scikit-learn offers essential tools and functionalities for selecting the most appropriate machine learning model and rigorously evaluating its performance. This involves using various metrics, employing cross-validation strategies, and optimizing model hyperparameters to ensure generalizability and prevent overfitting.

Key Facts:

  • The library provides diverse metrics for classification (accuracy, precision, recall, F1-score, AUC, ROC curves) and regression (R-squared, Mean Squared Error, Mean Absolute Error).
  • Selecting appropriate evaluation metrics is critical and must align with specific project goals and business objectives.
  • Scikit-learn facilitates robust cross-validation techniques to ensure a model's generalizability and guard against overfitting.
  • Tools like GridSearchCV and RandomizedSearchCV are available for systematic hyperparameter tuning to optimize model performance.
  • Proper model selection and evaluation are crucial steps in the machine learning workflow to build reliable and effective models.

Pipelines

Scikit-learn's Pipeline utility is a critical feature for creating streamlined, end-to-end machine learning workflows by chaining together data transformations and modeling processes. This approach automates repetitive tasks, enhances data consistency, prevents data leakage, and significantly improves the modularity, readability, and reproducibility of machine learning code.

Key Facts:

  • Pipelines chain various data transformations (e.g., preprocessing, feature engineering) and modeling processes into a single, sequential workflow.
  • The utility automates repetitive tasks, ensuring data consistency throughout the machine learning process.
  • Pipelines are crucial for preventing data leakage by correctly applying data preparation steps only to the training data or within cross-validation folds.
  • They promote modular, readable, and maintainable code, enhancing the reproducibility and scalability of ML projects.
  • The `Pipeline` utility seamlessly integrates with Scikit-learn's consistent API, allowing for easy hyperparameter tuning across the entire workflow.
Custom Transformers

Custom Transformers allow users to integrate bespoke data manipulation logic into Scikit-learn Pipelines, extending the library's capabilities. To ensure seamless integration, custom transformers must adhere to the Scikit-learn API by inheriting from `BaseEstimator` and `TransformerMixin` and implementing the `fit` and `transform` methods.

Key Facts:

  • Custom transformers are needed for unique data transformations not covered by built-in Scikit-learn tools.
  • They must inherit from `BaseEstimator` for parameter management and `TransformerMixin` for the `fit_transform()` convenience method.
  • The `fit(self, X, y=None)` method is where the transformer learns from the data, if necessary.
  • The `transform(self, X, y=None)` method applies the actual data manipulation.
  • The `__init__` method defines and sets parameters for the custom transformer.
Data Leakage Prevention

Data leakage prevention is a critical aspect of machine learning workflow design, especially when preprocessing data. Scikit-learn Pipelines are instrumental in preventing data leakage by ensuring that data transformations are learned exclusively from the training data and then consistently applied to both training and test sets, avoiding the inadvertent use of test set information during training.

Key Facts:

  • Data leakage occurs when information from the test set influences the training process, leading to inflated performance estimates.
  • Scikit-learn transformers utilize separate `fit` and `transform` steps; `fit` learns transformations only on training data.
  • Pipelines encapsulate `fit` and `transform` calls, ensuring transformations are learned from training data and applied correctly.
  • When combined with cross-validation, pipelines fit transformations solely on temporary training sets within each fold, further preventing leakage.
Hyperparameter Tuning with GridSearchCV

Scikit-learn Pipelines enhance hyperparameter tuning by allowing the simultaneous optimization of parameters for both preprocessing steps and the final estimator. Tools like `GridSearchCV` and `RandomizedSearchCV` can exhaustively or randomly search through parameter combinations across the entire pipeline, using a double underscore (`__`) syntax to specify parameters for specific pipeline steps.

Key Facts:

  • Pipelines integrate seamlessly with Scikit-learn's hyperparameter tuning tools such as `GridSearchCV`.
  • Hyperparameter tuning can optimize parameters for both preprocessing steps and the final estimator concurrently.
  • A double underscore (`__`) syntax is used to define parameters for specific pipeline steps (e.g., `svm__C`).
  • `GridSearchCV` performs an exhaustive search over all specified parameter combinations.
  • `RandomizedSearchCV` samples a given number of candidates from the parameter space, often more efficient for large search spaces.

Supervised Learning Algorithms

Scikit-learn offers a comprehensive suite of supervised learning algorithms, covering both classification for discrete output variables (e.g., spam detection) and regression for continuous output variables (e.g., stock price prediction). These algorithms are fundamental for predictive modeling tasks where the output variable is known.

Key Facts:

  • Scikit-learn includes classification algorithms such as logistic regression, decision trees, random forests, support vector machines, naive Bayes, gradient boosting, and k-nearest neighbors.
  • Common applications for classification include spam detection and image recognition.
  • Regression algorithms in Scikit-learn comprise linear regression, polynomial regression, decision trees, support vector machines, gradient boosting, and ridge regression.
  • Regression tasks aim to predict continuous output variables, exemplified by drug response or stock prices.
  • These algorithms require labeled datasets for training, where input features are mapped to known output values.

Unsupervised Learning Algorithms

Scikit-learn provides a robust collection of unsupervised learning algorithms designed to discover hidden patterns and structures within unlabeled data. This includes techniques for grouping similar data points (clustering) and reducing the number of input features while retaining crucial information (dimensionality reduction).

Key Facts:

  • Scikit-learn features clustering algorithms like k-means, hierarchical clustering, and density-based clustering.
  • Clustering is used to group similar data points together without prior knowledge of labels.
  • Dimensionality reduction algorithms such as Principal Component Analysis (PCA) and t-distributed stochastic neighbor embedding (t-SNE) are available.
  • Dimensionality reduction aims to reduce the number of features in a dataset while preserving important information.
  • These algorithms are particularly useful for exploratory data analysis, pattern discovery, and preparing data for supervised learning models.

Pipelines

Scikit-learn's Pipeline utility is a critical feature for creating streamlined, end-to-end machine learning workflows by chaining together data transformations and modeling processes. This approach automates repetitive tasks, enhances data consistency, prevents data leakage, and significantly improves the modularity, readability, and reproducibility of machine learning code.

Key Facts:

  • Pipelines chain various data transformations (e.g., preprocessing, feature engineering) and modeling processes into a single, sequential workflow.
  • The utility automates repetitive tasks, ensuring data consistency throughout the machine learning process.
  • Pipelines are crucial for preventing data leakage by correctly applying data preparation steps only to the training data or within cross-validation folds.
  • They promote modular, readable, and maintainable code, enhancing the reproducibility and scalability of ML projects.
  • The `Pipeline` utility seamlessly integrates with Scikit-learn's consistent API, allowing for easy hyperparameter tuning across the entire workflow.

Custom Transformers

Custom Transformers allow users to integrate bespoke data manipulation logic into Scikit-learn Pipelines, extending the library's capabilities. To ensure seamless integration, custom transformers must adhere to the Scikit-learn API by inheriting from `BaseEstimator` and `TransformerMixin` and implementing the `fit` and `transform` methods.

Key Facts:

  • Custom transformers are needed for unique data transformations not covered by built-in Scikit-learn tools.
  • They must inherit from `BaseEstimator` for parameter management and `TransformerMixin` for the `fit_transform()` convenience method.
  • The `fit(self, X, y=None)` method is where the transformer learns from the data, if necessary.
  • The `transform(self, X, y=None)` method applies the actual data manipulation.
  • The `__init__` method defines and sets parameters for the custom transformer.

Data Leakage Prevention

Data leakage prevention is a critical aspect of machine learning workflow design, especially when preprocessing data. Scikit-learn Pipelines are instrumental in preventing data leakage by ensuring that data transformations are learned exclusively from the training data and then consistently applied to both training and test sets, avoiding the inadvertent use of test set information during training.

Key Facts:

  • Data leakage occurs when information from the test set influences the training process, leading to inflated performance estimates.
  • Scikit-learn transformers utilize separate `fit` and `transform` steps; `fit` learns transformations only on training data.
  • Pipelines encapsulate `fit` and `transform` calls, ensuring transformations are learned from training data and applied correctly.
  • When combined with cross-validation, pipelines fit transformations solely on temporary training sets within each fold, further preventing leakage.

Hyperparameter Tuning with GridSearchCV

Scikit-learn Pipelines enhance hyperparameter tuning by allowing the simultaneous optimization of parameters for both preprocessing steps and the final estimator. Tools like `GridSearchCV` and `RandomizedSearchCV` can exhaustively or randomly search through parameter combinations across the entire pipeline, using a double underscore (`__`) syntax to specify parameters for specific pipeline steps.

Key Facts:

  • Pipelines integrate seamlessly with Scikit-learn's hyperparameter tuning tools such as `GridSearchCV`.
  • Hyperparameter tuning can optimize parameters for both preprocessing steps and the final estimator concurrently.
  • A double underscore (`__`) syntax is used to define parameters for specific pipeline steps (e.g., `svm__C`).
  • `GridSearchCV` performs an exhaustive search over all specified parameter combinations.
  • `RandomizedSearchCV` samples a given number of candidates from the parameter space, often more efficient for large search spaces.