<!DOCTYPE html> <html lang="en" data-content_root="../" > <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" /> <meta property="og:title" content="9.1. Strategies to scale computationally: bigger data" /> <meta property="og:type" content="website" /> <meta property="og:url" content="https://scikit-learn/stable/computing/scaling_strategies.html" /> <meta property="og:site_name" content="scikit-learn" /> <meta property="og:description" content="For some applications the amount of examples, features (or both) and/or the speed at which they need to be processed are challenging for traditional approaches. In these cases scikit-learn has a nu..." /> <meta property="og:image" content="https://scikit-learn/stable/computing/auto_examples/applications/images/sphx_glr_plot_out_of_core_classification_001.png" /> <meta property="og:image:alt" content="accuracy_over_time" /> <meta name="description" content="For some applications the amount of examples, features (or both) and/or the speed at which they need to be processed are challenging for traditional approaches. In these cases scikit-learn has a nu..." /> <title>9.1. Strategies to scale computationally: bigger data — scikit-learn 1.7.dev0 documentation</title> <script data-cfasync="false"> document.documentElement.dataset.mode = localStorage.getItem("mode") || ""; document.documentElement.dataset.theme = localStorage.getItem("theme") || ""; </script> <!-- this give us a css class that will be invisible only if js is disabled --> <noscript> <style> .pst-js-only { display: none !important; } </style> </noscript> <!-- Loaded before other Sphinx assets --> <link href="../_static/styles/theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" /> <link href="../_static/styles/pydata-sphinx-theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" /> <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=8f2a1f02" /> <link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" /> <link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" /> <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Vibur" /> <link rel="stylesheet" type="text/css" href="../_static/jupyterlite_sphinx.css?v=2c9f8f05" /> <link rel="stylesheet" type="text/css" href="../_static/sg_gallery.css?v=d2d258e8" /> <link rel="stylesheet" type="text/css" href="../_static/sg_gallery-binder.css?v=f4aeca0c" /> <link rel="stylesheet" type="text/css" href="../_static/sg_gallery-dataframe.css?v=2082cf3c" /> <link rel="stylesheet" type="text/css" href="../_static/sg_gallery-rendered-html.css?v=1277b6f3" /> <link rel="stylesheet" type="text/css" href="../_static/sphinx-design.min.css?v=95c83b7e" /> <link rel="stylesheet" type="text/css" href="../_static/styles/colors.css?v=cc94ab7d" /> <link rel="stylesheet" type="text/css" href="../_static/styles/custom.css?v=8f525996" /> <!-- So that users can add custom icons --> <script src="../_static/scripts/fontawesome.js?digest=8878045cc6db502f8baf"></script> <!-- Pre-loaded scripts that we'll load fully later --> <link rel="preload" as="script" href="../_static/scripts/bootstrap.js?digest=8878045cc6db502f8baf" /> <link rel="preload" as="script" href="../_static/scripts/pydata-sphinx-theme.js?digest=8878045cc6db502f8baf" /> <script src="../_static/documentation_options.js?v=473747f4"></script> <script src="../_static/doctools.js?v=9bcbadda"></script> <script src="../_static/sphinx_highlight.js?v=dc90522c"></script> <script src="../_static/clipboard.min.js?v=a7894cd8"></script> <script src="../_static/copybutton.js?v=97f0b27d"></script> <script src="../_static/jupyterlite_sphinx.js?v=96e329c5"></script> <script src="../_static/design-tabs.js?v=f930bc37"></script> <script data-domain="scikit-learn.org" defer="defer" src="https://views.scientific-python.org/js/script.js"></script> <script>DOCUMENTATION_OPTIONS.pagename = 'computing/scaling_strategies';</script> <script> DOCUMENTATION_OPTIONS.theme_version = '0.16.1'; DOCUMENTATION_OPTIONS.theme_switcher_json_url = 'https://scikit-learn.org/dev/_static/versions.json'; DOCUMENTATION_OPTIONS.theme_switcher_version_match = '1.7.dev0'; DOCUMENTATION_OPTIONS.show_version_warning_banner = true; </script> <script src="../_static/scripts/dropdown.js?v=d6825577"></script> <script src="../_static/scripts/version-switcher.js?v=a6dd8357"></script> <script src="../_static/scripts/sg_plotly_resize.js?v=2167d4db"></script> <link rel="canonical" href="https://scikit-learn.org/stable/computing/scaling_strategies.html" /> <link rel="icon" href="../_static/favicon.ico"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="next" title="9.2. Computational Performance" href="computational_performance.html" /> <link rel="prev" title="9. Computing with scikit-learn" href="../computing.html" /> <meta name="viewport" content="width=device-width, initial-scale=1"/> <meta name="docsearch:language" content="en"/> <meta name="docsearch:version" content="1.7" /> </head> <body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode=""> <div id="pst-skip-link" class="skip-link d-print-none"><a href="#main-content">Skip to main content</a></div> <div id="pst-scroll-pixel-helper"></div> <button type="button" class="btn rounded-pill" id="pst-back-to-top"> <i class="fa-solid fa-arrow-up"></i>Back to top</button> <dialog id="pst-search-dialog"> <form class="bd-search d-flex align-items-center" action="../search.html" method="get"> <i class="fa-solid fa-magnifying-glass"></i> <input type="search" class="form-control" name="q" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span> </form> </dialog> <div class="pst-async-banner-revealer d-none"> <aside id="bd-header-version-warning" class="d-none d-print-none" aria-label="Version warning"></aside> </div> <header class="bd-header navbar navbar-expand-lg bd-navbar d-print-none"> <div class="bd-header__inner bd-page-width"> <button class="pst-navbar-icon sidebar-toggle primary-toggle" aria-label="Site navigation"> <span class="fa-solid fa-bars"></span> </button> <div class=" navbar-header-items__start"> <div class="navbar-item"> <a class="navbar-brand logo" href="../index.html"> <img src="../_static/scikit-learn-logo-small.png" class="logo__image only-light" alt="scikit-learn homepage"/> <img src="../_static/scikit-learn-logo-small.png" class="logo__image only-dark pst-js-only" alt="scikit-learn homepage"/> </a></div> </div> <div class=" navbar-header-items"> <div class="me-auto navbar-header-items__center"> <div class="navbar-item"> <nav> <ul class="bd-navbar-elements navbar-nav"> <li class="nav-item "> <a class="nav-link nav-internal" href="../install.html"> Install </a> </li> <li class="nav-item current active"> <a class="nav-link nav-internal" href="../user_guide.html"> User Guide </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../api/index.html"> API </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../auto_examples/index.html"> Examples </a> </li> <li class="nav-item "> <a class="nav-link nav-external" href="https://blog.scikit-learn.org/"> Community </a> </li> <li class="nav-item dropdown"> <button class="btn dropdown-toggle nav-item" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-controls="pst-nav-more-links"> More </button> <ul id="pst-nav-more-links" class="dropdown-menu"> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../getting_started.html"> Getting Started </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../whats_new.html"> Release History </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../glossary.html"> Glossary </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../developers/index.html"> Development </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../faq.html"> FAQ </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../support.html"> Support </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../related_projects.html"> Related Projects </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../roadmap.html"> Roadmap </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../governance.html"> Governance </a> </li> <li class=" "> <a class="nav-link dropdown-item nav-internal" href="../about.html"> About us </a> </li> </ul> </li> </ul> </nav></div> </div> <div class="navbar-header-items__end"> <div class="navbar-item navbar-persistent--container"> <button class="btn btn-sm pst-navbar-icon search-button search-button__button pst-js-only" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip"> <i class="fa-solid fa-magnifying-glass fa-lg"></i> </button> </div> <div class="navbar-item"> <button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="Color mode" data-bs-title="Color mode" data-bs-placement="bottom" data-bs-toggle="tooltip"> <i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light"></i> <i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark"></i> <i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings"></i> </button></div> <div class="navbar-item"><ul class="navbar-icon-links" aria-label="Icon Links"> <li class="nav-item"> <a href="https://github.com/scikit-learn/scikit-learn" title="GitHub" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-square-github fa-lg" aria-hidden="true"></i> <span class="sr-only">GitHub</span></a> </li> </ul></div> <div class="navbar-item"> <div class="version-switcher__container dropdown pst-js-only"> <button id="pst-version-switcher-button-2" type="button" class="version-switcher__button btn btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="listbox" aria-controls="pst-version-switcher-list-2" aria-label="Version switcher list" > Choose version <!-- this text may get changed later by javascript --> <span class="caret"></span> </button> <div id="pst-version-switcher-list-2" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="listbox" aria-labelledby="pst-version-switcher-button-2"> <!-- dropdown will be populated by javascript on page load --> </div> </div></div> </div> </div> <div class="navbar-persistent--mobile"> <button class="btn btn-sm pst-navbar-icon search-button search-button__button pst-js-only" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip"> <i class="fa-solid fa-magnifying-glass fa-lg"></i> </button> </div> <button class="pst-navbar-icon sidebar-toggle secondary-toggle" aria-label="On this page"> <span class="fa-solid fa-outdent"></span> </button> </div> </header> <div class="bd-container"> <div class="bd-container__inner bd-page-width"> <dialog id="pst-primary-sidebar-modal"></dialog> <div id="pst-primary-sidebar" class="bd-sidebar-primary bd-sidebar"> <div class="sidebar-header-items sidebar-primary__section"> <div class="sidebar-header-items__center"> <div class="navbar-item"> <nav> <ul class="bd-navbar-elements navbar-nav"> <li class="nav-item "> <a class="nav-link nav-internal" href="../install.html"> Install </a> </li> <li class="nav-item current active"> <a class="nav-link nav-internal" href="../user_guide.html"> User Guide </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../api/index.html"> API </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../auto_examples/index.html"> Examples </a> </li> <li class="nav-item "> <a class="nav-link nav-external" href="https://blog.scikit-learn.org/"> Community </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../getting_started.html"> Getting Started </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../whats_new.html"> Release History </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../glossary.html"> Glossary </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../developers/index.html"> Development </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../faq.html"> FAQ </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../support.html"> Support </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../related_projects.html"> Related Projects </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../roadmap.html"> Roadmap </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../governance.html"> Governance </a> </li> <li class="nav-item "> <a class="nav-link nav-internal" href="../about.html"> About us </a> </li> </ul> </nav></div> </div> <div class="sidebar-header-items__end"> <div class="navbar-item"> <button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="Color mode" data-bs-title="Color mode" data-bs-placement="bottom" data-bs-toggle="tooltip"> <i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light"></i> <i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark"></i> <i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings"></i> </button></div> <div class="navbar-item"><ul class="navbar-icon-links" aria-label="Icon Links"> <li class="nav-item"> <a href="https://github.com/scikit-learn/scikit-learn" title="GitHub" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-square-github fa-lg" aria-hidden="true"></i> <span class="sr-only">GitHub</span></a> </li> </ul></div> <div class="navbar-item"> <div class="version-switcher__container dropdown pst-js-only"> <button id="pst-version-switcher-button-3" type="button" class="version-switcher__button btn btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="listbox" aria-controls="pst-version-switcher-list-3" aria-label="Version switcher list" > Choose version <!-- this text may get changed later by javascript --> <span class="caret"></span> </button> <div id="pst-version-switcher-list-3" class="version-switcher__menu dropdown-menu list-group-flush py-0" role="listbox" aria-labelledby="pst-version-switcher-button-3"> <!-- dropdown will be populated by javascript on page load --> </div> </div></div> </div> </div> <div class="sidebar-primary-items__start sidebar-primary__section"> <div class="sidebar-primary-item"> <nav class="bd-docs-nav bd-links" aria-label="Section Navigation"> <p class="bd-links__title" role="heading" aria-level="1">Section Navigation</p> <div class="bd-toc-item navbar-nav"><ul class="current nav bd-sidenav"> <li class="toctree-l1 has-children"><a class="reference internal" href="../supervised_learning.html">1. Supervised learning</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul> <li class="toctree-l2"><a class="reference internal" href="../modules/linear_model.html">1.1. Linear Models</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/lda_qda.html">1.2. Linear and Quadratic Discriminant Analysis</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/kernel_ridge.html">1.3. Kernel ridge regression</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/svm.html">1.4. Support Vector Machines</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/sgd.html">1.5. Stochastic Gradient Descent</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/neighbors.html">1.6. Nearest Neighbors</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/gaussian_process.html">1.7. Gaussian Processes</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/cross_decomposition.html">1.8. Cross decomposition</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/naive_bayes.html">1.9. Naive Bayes</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/tree.html">1.10. Decision Trees</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/ensemble.html">1.11. Ensembles: Gradient boosting, random forests, bagging, voting, stacking</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/multiclass.html">1.12. Multiclass and multioutput algorithms</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/feature_selection.html">1.13. Feature selection</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/semi_supervised.html">1.14. Semi-supervised learning</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/isotonic.html">1.15. Isotonic regression</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/calibration.html">1.16. Probability calibration</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/neural_networks_supervised.html">1.17. Neural network models (supervised)</a></li> </ul> </details></li> <li class="toctree-l1 has-children"><a class="reference internal" href="../unsupervised_learning.html">2. Unsupervised learning</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul> <li class="toctree-l2"><a class="reference internal" href="../modules/mixture.html">2.1. Gaussian mixture models</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/manifold.html">2.2. Manifold learning</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/clustering.html">2.3. Clustering</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/biclustering.html">2.4. Biclustering</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/decomposition.html">2.5. Decomposing signals in components (matrix factorization problems)</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/covariance.html">2.6. Covariance estimation</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/outlier_detection.html">2.7. Novelty and Outlier Detection</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/density.html">2.8. Density Estimation</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/neural_networks_unsupervised.html">2.9. Neural network models (unsupervised)</a></li> </ul> </details></li> <li class="toctree-l1 has-children"><a class="reference internal" href="../model_selection.html">3. Model selection and evaluation</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul> <li class="toctree-l2"><a class="reference internal" href="../modules/cross_validation.html">3.1. Cross-validation: evaluating estimator performance</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/grid_search.html">3.2. Tuning the hyper-parameters of an estimator</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/classification_threshold.html">3.3. Tuning the decision threshold for class prediction</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/model_evaluation.html">3.4. Metrics and scoring: quantifying the quality of predictions</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/learning_curve.html">3.5. Validation curves: plotting scores to evaluate models</a></li> </ul> </details></li> <li class="toctree-l1"><a class="reference internal" href="../metadata_routing.html">4. Metadata Routing</a></li> <li class="toctree-l1 has-children"><a class="reference internal" href="../inspection.html">5. Inspection</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul> <li class="toctree-l2"><a class="reference internal" href="../modules/partial_dependence.html">5.1. Partial Dependence and Individual Conditional Expectation plots</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/permutation_importance.html">5.2. Permutation feature importance</a></li> </ul> </details></li> <li class="toctree-l1"><a class="reference internal" href="../visualizations.html">6. Visualizations</a></li> <li class="toctree-l1 has-children"><a class="reference internal" href="../data_transforms.html">7. Dataset transformations</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul> <li class="toctree-l2"><a class="reference internal" href="../modules/compose.html">7.1. Pipelines and composite estimators</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/feature_extraction.html">7.2. Feature extraction</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/preprocessing.html">7.3. Preprocessing data</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/impute.html">7.4. Imputation of missing values</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/unsupervised_reduction.html">7.5. Unsupervised dimensionality reduction</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/random_projection.html">7.6. Random Projection</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/kernel_approximation.html">7.7. Kernel Approximation</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/metrics.html">7.8. Pairwise metrics, Affinities and Kernels</a></li> <li class="toctree-l2"><a class="reference internal" href="../modules/preprocessing_targets.html">7.9. Transforming the prediction target (<code class="docutils literal notranslate"><span class="pre">y</span></code>)</a></li> </ul> </details></li> <li class="toctree-l1 has-children"><a class="reference internal" href="../datasets.html">8. Dataset loading utilities</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul> <li class="toctree-l2"><a class="reference internal" href="../datasets/toy_dataset.html">8.1. Toy datasets</a></li> <li class="toctree-l2"><a class="reference internal" href="../datasets/real_world.html">8.2. Real world datasets</a></li> <li class="toctree-l2"><a class="reference internal" href="../datasets/sample_generators.html">8.3. Generated datasets</a></li> <li class="toctree-l2"><a class="reference internal" href="../datasets/loading_other_datasets.html">8.4. Loading other datasets</a></li> </ul> </details></li> <li class="toctree-l1 current active has-children"><a class="reference internal" href="../computing.html">9. Computing with scikit-learn</a><details open="open"><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul class="current"> <li class="toctree-l2 current active"><a class="current reference internal" href="#">9.1. Strategies to scale computationally: bigger data</a></li> <li class="toctree-l2"><a class="reference internal" href="computational_performance.html">9.2. Computational Performance</a></li> <li class="toctree-l2"><a class="reference internal" href="parallelism.html">9.3. Parallelism, resource management, and configuration</a></li> </ul> </details></li> <li class="toctree-l1"><a class="reference internal" href="../model_persistence.html">10. Model persistence</a></li> <li class="toctree-l1"><a class="reference internal" href="../common_pitfalls.html">11. Common pitfalls and recommended practices</a></li> <li class="toctree-l1 has-children"><a class="reference internal" href="../dispatching.html">12. Dispatching</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul> <li class="toctree-l2"><a class="reference internal" href="../modules/array_api.html">12.1. Array API support (experimental)</a></li> </ul> </details></li> <li class="toctree-l1"><a class="reference internal" href="../machine_learning_map.html">13. Choosing the right estimator</a></li> <li class="toctree-l1"><a class="reference internal" href="../presentations.html">14. External Resources, Videos and Talks</a></li> </ul> </div> </nav></div> </div> <div class="sidebar-primary-items__end sidebar-primary__section"> </div> </div> <main id="main-content" class="bd-main" role="main"> <div class="bd-content"> <div class="bd-article-container"> <div class="bd-header-article d-print-none"> <div class="header-article-items header-article__inner"> <div class="header-article-items__start"> <div class="header-article-item"> <nav aria-label="Breadcrumb" class="d-print-none"> <ul class="bd-breadcrumbs"> <li class="breadcrumb-item breadcrumb-home"> <a href="../index.html" class="nav-link" aria-label="Home"> <i class="fa-solid fa-home"></i> </a> </li> <li class="breadcrumb-item"><a href="../user_guide.html" class="nav-link">User Guide</a></li> <li class="breadcrumb-item"><a href="../computing.html" class="nav-link"><span class="section-number">9. </span>Computing with scikit-learn</a></li> <li class="breadcrumb-item active" aria-current="page"><span class="ellipsis"><span class="section-number">9.1. </span>Strategies to scale computationally: bigger data</span></li> </ul> </nav> </div> </div> </div> </div> <div id="searchbox"></div> <article class="bd-article"> <section id="strategies-to-scale-computationally-bigger-data"> <span id="scaling-strategies"></span><h1><span class="section-number">9.1. </span>Strategies to scale computationally: bigger data<a class="headerlink" href="#strategies-to-scale-computationally-bigger-data" title="Link to this heading">#</a></h1> <p>For some applications the amount of examples, features (or both) and/or the speed at which they need to be processed are challenging for traditional approaches. In these cases scikit-learn has a number of options you can consider to make your system scale.</p> <section id="scaling-with-instances-using-out-of-core-learning"> <h2><span class="section-number">9.1.1. </span>Scaling with instances using out-of-core learning<a class="headerlink" href="#scaling-with-instances-using-out-of-core-learning" title="Link to this heading">#</a></h2> <p>Out-of-core (or “external memory”) learning is a technique used to learn from data that cannot fit in a computer’s main memory (RAM).</p> <p>Here is a sketch of a system designed to achieve this goal:</p> <ol class="arabic simple"> <li><p>a way to stream instances</p></li> <li><p>a way to extract features from instances</p></li> <li><p>an incremental algorithm</p></li> </ol> <section id="streaming-instances"> <h3><span class="section-number">9.1.1.1. </span>Streaming instances<a class="headerlink" href="#streaming-instances" title="Link to this heading">#</a></h3> <p>Basically, 1. may be a reader that yields instances from files on a hard drive, a database, from a network stream etc. However, details on how to achieve this are beyond the scope of this documentation.</p> </section> <section id="extracting-features"> <h3><span class="section-number">9.1.1.2. </span>Extracting features<a class="headerlink" href="#extracting-features" title="Link to this heading">#</a></h3> <p>2. could be any relevant way to extract features among the different <a class="reference internal" href="../modules/feature_extraction.html#feature-extraction"><span class="std std-ref">feature extraction</span></a> methods supported by scikit-learn. However, when working with data that needs vectorization and where the set of features or values is not known in advance one should take explicit care. A good example is text classification where unknown terms are likely to be found during training. It is possible to use a stateful vectorizer if making multiple passes over the data is reasonable from an application point of view. Otherwise, one can turn up the difficulty by using a stateless feature extractor. Currently the preferred way to do this is to use the so-called <a class="reference internal" href="../modules/feature_extraction.html#feature-hashing"><span class="std std-ref">hashing trick</span></a> as implemented by <a class="reference internal" href="../modules/generated/sklearn.feature_extraction.FeatureHasher.html#sklearn.feature_extraction.FeatureHasher" title="sklearn.feature_extraction.FeatureHasher"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.feature_extraction.FeatureHasher</span></code></a> for datasets with categorical variables represented as list of Python dicts or <a class="reference internal" href="../modules/generated/sklearn.feature_extraction.text.HashingVectorizer.html#sklearn.feature_extraction.text.HashingVectorizer" title="sklearn.feature_extraction.text.HashingVectorizer"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.feature_extraction.text.HashingVectorizer</span></code></a> for text documents.</p> </section> <section id="incremental-learning"> <h3><span class="section-number">9.1.1.3. </span>Incremental learning<a class="headerlink" href="#incremental-learning" title="Link to this heading">#</a></h3> <p>Finally, for 3. we have a number of options inside scikit-learn. Although not all algorithms can learn incrementally (i.e. without seeing all the instances at once), all estimators implementing the <code class="docutils literal notranslate"><span class="pre">partial_fit</span></code> API are candidates. Actually, the ability to learn incrementally from a mini-batch of instances (sometimes called “online learning”) is key to out-of-core learning as it guarantees that at any given time there will be only a small amount of instances in the main memory. Choosing a good size for the mini-batch that balances relevancy and memory footprint could involve some tuning <a class="footnote-reference brackets" href="#id2" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a>.</p> <p>Here is a list of incremental estimators for different tasks:</p> <ul class="simple"> <li><dl class="simple"> <dt>Classification</dt><dd><ul> <li><p><a class="reference internal" href="../modules/generated/sklearn.naive_bayes.MultinomialNB.html#sklearn.naive_bayes.MultinomialNB" title="sklearn.naive_bayes.MultinomialNB"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.naive_bayes.MultinomialNB</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.naive_bayes.BernoulliNB.html#sklearn.naive_bayes.BernoulliNB" title="sklearn.naive_bayes.BernoulliNB"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.naive_bayes.BernoulliNB</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.linear_model.Perceptron.html#sklearn.linear_model.Perceptron" title="sklearn.linear_model.Perceptron"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.linear_model.Perceptron</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.linear_model.SGDClassifier.html#sklearn.linear_model.SGDClassifier" title="sklearn.linear_model.SGDClassifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.linear_model.SGDClassifier</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.linear_model.PassiveAggressiveClassifier.html#sklearn.linear_model.PassiveAggressiveClassifier" title="sklearn.linear_model.PassiveAggressiveClassifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.linear_model.PassiveAggressiveClassifier</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.neural_network.MLPClassifier.html#sklearn.neural_network.MLPClassifier" title="sklearn.neural_network.MLPClassifier"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.neural_network.MLPClassifier</span></code></a></p></li> </ul> </dd> </dl> </li> <li><dl class="simple"> <dt>Regression</dt><dd><ul> <li><p><a class="reference internal" href="../modules/generated/sklearn.linear_model.SGDRegressor.html#sklearn.linear_model.SGDRegressor" title="sklearn.linear_model.SGDRegressor"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.linear_model.SGDRegressor</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.linear_model.PassiveAggressiveRegressor.html#sklearn.linear_model.PassiveAggressiveRegressor" title="sklearn.linear_model.PassiveAggressiveRegressor"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.linear_model.PassiveAggressiveRegressor</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.neural_network.MLPRegressor" title="sklearn.neural_network.MLPRegressor"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.neural_network.MLPRegressor</span></code></a></p></li> </ul> </dd> </dl> </li> <li><dl class="simple"> <dt>Clustering</dt><dd><ul> <li><p><a class="reference internal" href="../modules/generated/sklearn.cluster.MiniBatchKMeans.html#sklearn.cluster.MiniBatchKMeans" title="sklearn.cluster.MiniBatchKMeans"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.cluster.MiniBatchKMeans</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.cluster.Birch.html#sklearn.cluster.Birch" title="sklearn.cluster.Birch"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.cluster.Birch</span></code></a></p></li> </ul> </dd> </dl> </li> <li><dl class="simple"> <dt>Decomposition / feature Extraction</dt><dd><ul> <li><p><a class="reference internal" href="../modules/generated/sklearn.decomposition.MiniBatchDictionaryLearning.html#sklearn.decomposition.MiniBatchDictionaryLearning" title="sklearn.decomposition.MiniBatchDictionaryLearning"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.decomposition.MiniBatchDictionaryLearning</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.decomposition.IncrementalPCA.html#sklearn.decomposition.IncrementalPCA" title="sklearn.decomposition.IncrementalPCA"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.decomposition.IncrementalPCA</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.decomposition.LatentDirichletAllocation.html#sklearn.decomposition.LatentDirichletAllocation" title="sklearn.decomposition.LatentDirichletAllocation"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.decomposition.LatentDirichletAllocation</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.decomposition.MiniBatchNMF.html#sklearn.decomposition.MiniBatchNMF" title="sklearn.decomposition.MiniBatchNMF"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.decomposition.MiniBatchNMF</span></code></a></p></li> </ul> </dd> </dl> </li> <li><dl class="simple"> <dt>Preprocessing</dt><dd><ul> <li><p><a class="reference internal" href="../modules/generated/sklearn.preprocessing.StandardScaler.html#sklearn.preprocessing.StandardScaler" title="sklearn.preprocessing.StandardScaler"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.preprocessing.StandardScaler</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.preprocessing.MinMaxScaler.html#sklearn.preprocessing.MinMaxScaler" title="sklearn.preprocessing.MinMaxScaler"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.preprocessing.MinMaxScaler</span></code></a></p></li> <li><p><a class="reference internal" href="../modules/generated/sklearn.preprocessing.MaxAbsScaler.html#sklearn.preprocessing.MaxAbsScaler" title="sklearn.preprocessing.MaxAbsScaler"><code class="xref py py-class docutils literal notranslate"><span class="pre">sklearn.preprocessing.MaxAbsScaler</span></code></a></p></li> </ul> </dd> </dl> </li> </ul> <p>For classification, a somewhat important thing to note is that although a stateless feature extraction routine may be able to cope with new/unseen attributes, the incremental learner itself may be unable to cope with new/unseen targets classes. In this case you have to pass all the possible classes to the first <code class="docutils literal notranslate"><span class="pre">partial_fit</span></code> call using the <code class="docutils literal notranslate"><span class="pre">classes=</span></code> parameter.</p> <p>Another aspect to consider when choosing a proper algorithm is that not all of them put the same importance on each example over time. Namely, the <code class="docutils literal notranslate"><span class="pre">Perceptron</span></code> is still sensitive to badly labeled examples even after many examples whereas the <code class="docutils literal notranslate"><span class="pre">SGD*</span></code> and <code class="docutils literal notranslate"><span class="pre">PassiveAggressive*</span></code> families are more robust to this kind of artifacts. Conversely, the latter also tend to give less importance to remarkably different, yet properly labeled examples when they come late in the stream as their learning rate decreases over time.</p> </section> <section id="examples"> <h3><span class="section-number">9.1.1.4. </span>Examples<a class="headerlink" href="#examples" title="Link to this heading">#</a></h3> <p>Finally, we have a full-fledged example of <a class="reference internal" href="../auto_examples/applications/plot_out_of_core_classification.html#sphx-glr-auto-examples-applications-plot-out-of-core-classification-py"><span class="std std-ref">Out-of-core classification of text documents</span></a>. It is aimed at providing a starting point for people wanting to build out-of-core learning systems and demonstrates most of the notions discussed above.</p> <p>Furthermore, it also shows the evolution of the performance of different algorithms with the number of processed examples.</p> <p class="centered"> <strong><a class="reference external" href="../auto_examples/applications/plot_out_of_core_classification.html"><img alt="accuracy_over_time" src="../_images/sphx_glr_plot_out_of_core_classification_001.png" style="width: 512.0px; height: 384.0px;" /></a></strong></p><p>Now looking at the computation time of the different parts, we see that the vectorization is much more expensive than learning itself. From the different algorithms, <code class="docutils literal notranslate"><span class="pre">MultinomialNB</span></code> is the most expensive, but its overhead can be mitigated by increasing the size of the mini-batches (exercise: change <code class="docutils literal notranslate"><span class="pre">minibatch_size</span></code> to 100 and 10000 in the program and compare).</p> <p class="centered"> <strong><a class="reference external" href="../auto_examples/applications/plot_out_of_core_classification.html"><img alt="computation_time" src="../_images/sphx_glr_plot_out_of_core_classification_003.png" style="width: 512.0px; height: 384.0px;" /></a></strong></p></section> <section id="notes"> <h3><span class="section-number">9.1.1.5. </span>Notes<a class="headerlink" href="#notes" title="Link to this heading">#</a></h3> <aside class="footnote-list brackets"> <aside class="footnote brackets" id="id2" role="doc-footnote"> <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span> <p>Depending on the algorithm the mini-batch size can influence results or not. SGD*, PassiveAggressive*, and discrete NaiveBayes are truly online and are not affected by batch size. Conversely, MiniBatchKMeans convergence rate is affected by the batch size. Also, its memory footprint can vary dramatically with batch size.</p> </aside> </aside> </section> </section> </section> </article> <footer class="bd-footer-article"> <div class="footer-article-items footer-article__inner"> <div class="footer-article-item"> <div class="prev-next-area"> <a class="left-prev" href="../computing.html" title="previous page"> <i class="fa-solid fa-angle-left"></i> <div class="prev-next-info"> <p class="prev-next-subtitle">previous</p> <p class="prev-next-title"><span class="section-number">9. </span>Computing with scikit-learn</p> </div> </a> <a class="right-next" href="computational_performance.html" title="next page"> <div class="prev-next-info"> <p class="prev-next-subtitle">next</p> <p class="prev-next-title"><span class="section-number">9.2. </span>Computational Performance</p> </div> <i class="fa-solid fa-angle-right"></i> </a> </div></div> </div> </footer> </div> <dialog id="pst-secondary-sidebar-modal"></dialog> <div id="pst-secondary-sidebar" class="bd-sidebar-secondary bd-toc"><div class="sidebar-secondary-items sidebar-secondary__inner"> <div class="sidebar-secondary-item"> <div id="pst-page-navigation-heading-2" class="page-toc tocsection onthispage"> <i class="fa-solid fa-list"></i> On this page </div> <nav class="bd-toc-nav page-toc" aria-labelledby="pst-page-navigation-heading-2"> <ul class="visible nav section-nav flex-column"> <li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#scaling-with-instances-using-out-of-core-learning">9.1.1. Scaling with instances using out-of-core learning</a><ul class="nav section-nav flex-column"> <li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#streaming-instances">9.1.1.1. Streaming instances</a></li> <li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#extracting-features">9.1.1.2. Extracting features</a></li> <li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#incremental-learning">9.1.1.3. Incremental learning</a></li> <li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#examples">9.1.1.4. Examples</a></li> <li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#notes">9.1.1.5. Notes</a></li> </ul> </li> </ul> </nav></div> <div class="sidebar-secondary-item"> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/computing/scaling_strategies.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div></div> </div></div> </div> <footer class="bd-footer-content"> </footer> </main> </div> </div> <!-- Scripts loaded after <body> so the DOM is not blocked --> <script defer src="../_static/scripts/bootstrap.js?digest=8878045cc6db502f8baf"></script> <script defer src="../_static/scripts/pydata-sphinx-theme.js?digest=8878045cc6db502f8baf"></script> <footer class="bd-footer"> <div class="bd-footer__inner bd-page-width"> <div class="footer-items__start"> <div class="footer-item"> <p class="copyright"> © Copyright 2007 - 2025, scikit-learn developers (BSD License). <br/> </p> </div> </div> </div> </footer> </body> </html>