| |
| <!DOCTYPE html> |
| <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> |
| <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> |
| <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> |
| <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| <title>MLlib: Main Guide - Spark 3.2.0 Documentation</title> |
| |
| |
| |
| |
| <link rel="stylesheet" href="css/bootstrap.min.css"> |
| <style> |
| body { |
| padding-top: 60px; |
| padding-bottom: 40px; |
| } |
| </style> |
| <meta name="viewport" content="width=device-width"> |
| <link rel="stylesheet" href="css/main.css"> |
| |
| <script src="js/vendor/modernizr-2.6.1-respond-1.1.0.min.js"></script> |
| |
| <link rel="stylesheet" href="css/pygments-default.css"> |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" /> |
| <link rel="stylesheet" href="css/docsearch.css"> |
| |
| |
| <!-- Google analytics script --> |
| <script type="text/javascript"> |
| var _gaq = _gaq || []; |
| _gaq.push(['_setAccount', 'UA-32518208-2']); |
| _gaq.push(['_trackPageview']); |
| |
| (function() { |
| var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; |
| ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); |
| })(); |
| </script> |
| |
| |
| </head> |
| <body> |
| <!--[if lt IE 7]> |
| <p class="chromeframe">You are using an outdated browser. <a href="https://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p> |
| <![endif]--> |
| |
| <!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html --> |
| |
| <nav class="navbar fixed-top navbar-expand-md navbar-light bg-light" id="topbar"> |
| <div class="container"> |
| <div class="navbar-header"> |
| <div class="navbar-brand"><a href="index.html"> |
| <img src="img/spark-logo-hd.png" style="height:50px;"/></a><span class="version">3.2.0</span> |
| </div> |
| </div> |
| <button class="navbar-toggler" type="button" data-toggle="collapse" |
| data-target="#navbarCollapse" aria-controls="navbarCollapse" |
| aria-expanded="false" aria-label="Toggle navigation"> |
| <span class="navbar-toggler-icon"></span> |
| </button> |
| <div class="collapse navbar-collapse" id="navbarCollapse"> |
| <ul class="navbar-nav"> |
| <!--TODO(andyk): Add class="active" attribute to li some how.--> |
| <li class="nav-item"><a href="index.html" class="nav-link">Overview</a></li> |
| |
| <li class="nav-item dropdown"> |
| <a href="#" class="nav-link dropdown-toggle" id="navbarQuickStart" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Programming Guides</a> |
| <div class="dropdown-menu" aria-labelledby="navbarQuickStart"> |
| <a class="dropdown-item" href="quick-start.html">Quick Start</a> |
| <a class="dropdown-item" href="rdd-programming-guide.html">RDDs, Accumulators, Broadcasts Vars</a> |
| <a class="dropdown-item" href="sql-programming-guide.html">SQL, DataFrames, and Datasets</a> |
| <a class="dropdown-item" href="structured-streaming-programming-guide.html">Structured Streaming</a> |
| <a class="dropdown-item" href="streaming-programming-guide.html">Spark Streaming (DStreams)</a> |
| <a class="dropdown-item" href="ml-guide.html">MLlib (Machine Learning)</a> |
| <a class="dropdown-item" href="graphx-programming-guide.html">GraphX (Graph Processing)</a> |
| <a class="dropdown-item" href="sparkr.html">SparkR (R on Spark)</a> |
| <a class="dropdown-item" href="api/python/getting_started/index.html">PySpark (Python on Spark)</a> |
| </div> |
| </li> |
| |
| <li class="nav-item dropdown"> |
| <a href="#" class="nav-link dropdown-toggle" id="navbarAPIDocs" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">API Docs</a> |
| <div class="dropdown-menu" aria-labelledby="navbarAPIDocs"> |
| <a class="dropdown-item" href="api/scala/org/apache/spark/index.html">Scala</a> |
| <a class="dropdown-item" href="api/java/index.html">Java</a> |
| <a class="dropdown-item" href="api/python/index.html">Python</a> |
| <a class="dropdown-item" href="api/R/index.html">R</a> |
| <a class="dropdown-item" href="api/sql/index.html">SQL, Built-in Functions</a> |
| </div> |
| </li> |
| |
| <li class="nav-item dropdown"> |
| <a href="#" class="nav-link dropdown-toggle" id="navbarDeploying" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Deploying</a> |
| <div class="dropdown-menu" aria-labelledby="navbarDeploying"> |
| <a class="dropdown-item" href="cluster-overview.html">Overview</a> |
| <a class="dropdown-item" href="submitting-applications.html">Submitting Applications</a> |
| <div class="dropdown-divider"></div> |
| <a class="dropdown-item" href="spark-standalone.html">Spark Standalone</a> |
| <a class="dropdown-item" href="running-on-mesos.html">Mesos</a> |
| <a class="dropdown-item" href="running-on-yarn.html">YARN</a> |
| <a class="dropdown-item" href="running-on-kubernetes.html">Kubernetes</a> |
| </div> |
| </li> |
| |
| <li class="nav-item dropdown"> |
| <a href="#" class="nav-link dropdown-toggle" id="navbarMore" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">More</a> |
| <div class="dropdown-menu" aria-labelledby="navbarMore"> |
| <a class="dropdown-item" href="configuration.html">Configuration</a> |
| <a class="dropdown-item" href="monitoring.html">Monitoring</a> |
| <a class="dropdown-item" href="tuning.html">Tuning Guide</a> |
| <a class="dropdown-item" href="job-scheduling.html">Job Scheduling</a> |
| <a class="dropdown-item" href="security.html">Security</a> |
| <a class="dropdown-item" href="hardware-provisioning.html">Hardware Provisioning</a> |
| <a class="dropdown-item" href="migration-guide.html">Migration Guide</a> |
| <div class="dropdown-divider"></div> |
| <a class="dropdown-item" href="building-spark.html">Building Spark</a> |
| <a class="dropdown-item" href="https://spark.apache.org/contributing.html">Contributing to Spark</a> |
| <a class="dropdown-item" href="https://spark.apache.org/third-party-projects.html">Third Party Projects</a> |
| </div> |
| </li> |
| |
| <li class="nav-item"> |
| <input type="text" id="docsearch-input" placeholder="Search the docs…"> |
| </li> |
| </ul> |
| <!--<span class="navbar-text navbar-right"><span class="version-text">v3.2.0</span></span>--> |
| </div> |
| </div> |
| </nav> |
| |
| <div class="container-wrapper"> |
| |
| |
| |
| <div class="left-menu-wrapper"> |
| <div class="left-menu"> |
| <h3><a href="ml-guide.html">MLlib: Main Guide</a></h3> |
| |
| <ul> |
| |
| <li> |
| <a href="ml-statistics.html"> |
| |
| Basic statistics |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-datasource.html"> |
| |
| Data sources |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-pipeline.html"> |
| |
| Pipelines |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-features.html"> |
| |
| Extracting, transforming and selecting features |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-classification-regression.html"> |
| |
| Classification and Regression |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-clustering.html"> |
| |
| Clustering |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-collaborative-filtering.html"> |
| |
| Collaborative filtering |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-frequent-pattern-mining.html"> |
| |
| Frequent Pattern Mining |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-tuning.html"> |
| |
| Model selection and tuning |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="ml-advanced.html"> |
| |
| Advanced topics |
| |
| </a> |
| </li> |
| |
| |
| |
| </ul> |
| |
| <h3><a href="mllib-guide.html">MLlib: RDD-based API Guide</a></h3> |
| |
| <ul> |
| |
| <li> |
| <a href="mllib-data-types.html"> |
| |
| Data types |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-statistics.html"> |
| |
| Basic statistics |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-classification-regression.html"> |
| |
| Classification and regression |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-collaborative-filtering.html"> |
| |
| Collaborative filtering |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-clustering.html"> |
| |
| Clustering |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-dimensionality-reduction.html"> |
| |
| Dimensionality reduction |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-feature-extraction.html"> |
| |
| Feature extraction and transformation |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-frequent-pattern-mining.html"> |
| |
| Frequent pattern mining |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-evaluation-metrics.html"> |
| |
| Evaluation metrics |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-pmml-model-export.html"> |
| |
| PMML model export |
| |
| </a> |
| </li> |
| |
| |
| |
| <li> |
| <a href="mllib-optimization.html"> |
| |
| Optimization (developer) |
| |
| </a> |
| </li> |
| |
| |
| |
| </ul> |
| |
| </div> |
| </div> |
| |
| <input id="nav-trigger" class="nav-trigger" checked type="checkbox"> |
| <label for="nav-trigger"></label> |
| <div class="content-with-sidebar mr-3" id="content"> |
| |
| <h1 class="title">Machine Learning Library (MLlib) Guide</h1> |
| |
| |
| <p>MLlib is Spark’s machine learning (ML) library. |
| Its goal is to make practical machine learning scalable and easy. |
| At a high level, it provides tools such as:</p> |
| |
| <ul> |
| <li>ML Algorithms: common learning algorithms such as classification, regression, clustering, and collaborative filtering</li> |
| <li>Featurization: feature extraction, transformation, dimensionality reduction, and selection</li> |
| <li>Pipelines: tools for constructing, evaluating, and tuning ML Pipelines</li> |
| <li>Persistence: saving and load algorithms, models, and Pipelines</li> |
| <li>Utilities: linear algebra, statistics, data handling, etc.</li> |
| </ul> |
| |
| <h1 id="announcement-dataframe-based-api-is-primary-api">Announcement: DataFrame-based API is primary API</h1> |
| |
| <p><strong>The MLlib RDD-based API is now in maintenance mode.</strong></p> |
| |
| <p>As of Spark 2.0, the <a href="rdd-programming-guide.html#resilient-distributed-datasets-rdds">RDD</a>-based APIs in the <code class="language-plaintext highlighter-rouge">spark.mllib</code> package have entered maintenance mode. |
| The primary Machine Learning API for Spark is now the <a href="sql-programming-guide.html">DataFrame</a>-based API in the <code class="language-plaintext highlighter-rouge">spark.ml</code> package.</p> |
| |
| <p><em>What are the implications?</em></p> |
| |
| <ul> |
| <li>MLlib will still support the RDD-based API in <code class="language-plaintext highlighter-rouge">spark.mllib</code> with bug fixes.</li> |
| <li>MLlib will not add new features to the RDD-based API.</li> |
| <li>In the Spark 2.x releases, MLlib will add features to the DataFrames-based API to reach feature parity with the RDD-based API.</li> |
| </ul> |
| |
| <p><em>Why is MLlib switching to the DataFrame-based API?</em></p> |
| |
| <ul> |
| <li>DataFrames provide a more user-friendly API than RDDs. The many benefits of DataFrames include Spark Datasources, SQL/DataFrame queries, Tungsten and Catalyst optimizations, and uniform APIs across languages.</li> |
| <li>The DataFrame-based API for MLlib provides a uniform API across ML algorithms and across multiple languages.</li> |
| <li>DataFrames facilitate practical ML Pipelines, particularly feature transformations. See the <a href="ml-pipeline.html">Pipelines guide</a> for details.</li> |
| </ul> |
| |
| <p><em>What is “Spark ML”?</em></p> |
| |
| <ul> |
| <li>“Spark ML” is not an official name but occasionally used to refer to the MLlib DataFrame-based API. |
| This is majorly due to the <code class="language-plaintext highlighter-rouge">org.apache.spark.ml</code> Scala package name used by the DataFrame-based API, |
| and the “Spark ML Pipelines” term we used initially to emphasize the pipeline concept.</li> |
| </ul> |
| |
| <p><em>Is MLlib deprecated?</em></p> |
| |
| <ul> |
| <li>No. MLlib includes both the RDD-based API and the DataFrame-based API. |
| The RDD-based API is now in maintenance mode. |
| But neither API is deprecated, nor MLlib as a whole.</li> |
| </ul> |
| |
| <h1 id="dependencies">Dependencies</h1> |
| |
| <p>MLlib uses linear algebra packages <a href="http://www.scalanlp.org/">Breeze</a>, <a href="https://github.com/luhenry/netlib">dev.ludovic.netlib</a>, and <a href="https://github.com/fommil/netlib-java">netlib-java</a> for optimised numerical processing<sup id="fnref:1" role="doc-noteref"><a href="#fn:1" class="footnote">1</a></sup>. Those packages may call native acceleration libraries such as <a href="https://software.intel.com/content/www/us/en/develop/tools/math-kernel-library.html">Intel MKL</a> or <a href="http://www.openblas.net">OpenBLAS</a> if they are available as system libraries or in runtime library paths.</p> |
| |
| <p>However, native acceleration libraries can’t be distributed with Spark. See <a href="ml-linalg-guide.html">MLlib Linear Algebra Acceleration Guide</a> for how to enable accelerated linear algebra processing. If accelerated native libraries are not enabled, you will see a warning message like below and a pure JVM implementation will be used instead:</p> |
| <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>WARN BLAS: Failed to load implementation from:dev.ludovic.netlib.blas.JNIBLAS |
| </code></pre></div></div> |
| |
| <p>To use MLlib in Python, you will need <a href="http://www.numpy.org">NumPy</a> version 1.4 or newer.</p> |
| |
| <h1 id="highlights-in-30">Highlights in 3.0</h1> |
| |
| <p>The list below highlights some of the new features and enhancements added to MLlib in the <code class="language-plaintext highlighter-rouge">3.0</code> |
| release of Spark:</p> |
| |
| <ul> |
| <li>Multiple columns support was added to <code class="language-plaintext highlighter-rouge">Binarizer</code> (<a href="https://issues.apache.org/jira/browse/SPARK-23578">SPARK-23578</a>), <code class="language-plaintext highlighter-rouge">StringIndexer</code> (<a href="https://issues.apache.org/jira/browse/SPARK-11215">SPARK-11215</a>), <code class="language-plaintext highlighter-rouge">StopWordsRemover</code> (<a href="https://issues.apache.org/jira/browse/SPARK-29808">SPARK-29808</a>) and PySpark <code class="language-plaintext highlighter-rouge">QuantileDiscretizer</code> (<a href="https://issues.apache.org/jira/browse/SPARK-22796">SPARK-22796</a>).</li> |
| <li>Tree-Based Feature Transformation was added |
| (<a href="https://issues.apache.org/jira/browse/SPARK-13677">SPARK-13677</a>).</li> |
| <li>Two new evaluators <code class="language-plaintext highlighter-rouge">MultilabelClassificationEvaluator</code> (<a href="https://issues.apache.org/jira/browse/SPARK-16692">SPARK-16692</a>) and <code class="language-plaintext highlighter-rouge">RankingEvaluator</code> (<a href="https://issues.apache.org/jira/browse/SPARK-28045">SPARK-28045</a>) were added.</li> |
| <li>Sample weights support was added in <code class="language-plaintext highlighter-rouge">DecisionTreeClassifier/Regressor</code> (<a href="https://issues.apache.org/jira/browse/SPARK-19591">SPARK-19591</a>), <code class="language-plaintext highlighter-rouge">RandomForestClassifier/Regressor</code> (<a href="https://issues.apache.org/jira/browse/SPARK-9478">SPARK-9478</a>), <code class="language-plaintext highlighter-rouge">GBTClassifier/Regressor</code> (<a href="https://issues.apache.org/jira/browse/SPARK-9612">SPARK-9612</a>), <code class="language-plaintext highlighter-rouge">MulticlassClassificationEvaluator</code> (<a href="https://issues.apache.org/jira/browse/SPARK-24101">SPARK-24101</a>), <code class="language-plaintext highlighter-rouge">RegressionEvaluator</code> (<a href="https://issues.apache.org/jira/browse/SPARK-24102">SPARK-24102</a>), <code class="language-plaintext highlighter-rouge">BinaryClassificationEvaluator</code> (<a href="https://issues.apache.org/jira/browse/SPARK-24103">SPARK-24103</a>), <code class="language-plaintext highlighter-rouge">BisectingKMeans</code> (<a href="https://issues.apache.org/jira/browse/SPARK-30351">SPARK-30351</a>), <code class="language-plaintext highlighter-rouge">KMeans</code> (<a href="https://issues.apache.org/jira/browse/SPARK-29967">SPARK-29967</a>) and <code class="language-plaintext highlighter-rouge">GaussianMixture</code> (<a href="https://issues.apache.org/jira/browse/SPARK-30102">SPARK-30102</a>).</li> |
| <li>R API for <code class="language-plaintext highlighter-rouge">PowerIterationClustering</code> was added |
| (<a href="https://issues.apache.org/jira/browse/SPARK-19827">SPARK-19827</a>).</li> |
| <li>Added Spark ML listener for tracking ML pipeline status |
| (<a href="https://issues.apache.org/jira/browse/SPARK-23674">SPARK-23674</a>).</li> |
| <li>Fit with validation set was added to Gradient Boosted Trees in Python |
| (<a href="https://issues.apache.org/jira/browse/SPARK-24333">SPARK-24333</a>).</li> |
| <li><a href="ml-features.html#robustscaler"><code class="language-plaintext highlighter-rouge">RobustScaler</code></a> transformer was added |
| (<a href="https://issues.apache.org/jira/browse/SPARK-28399">SPARK-28399</a>).</li> |
| <li><a href="ml-classification-regression.html#factorization-machines"><code class="language-plaintext highlighter-rouge">Factorization Machines</code></a> classifier and regressor were added |
| (<a href="https://issues.apache.org/jira/browse/SPARK-29224">SPARK-29224</a>).</li> |
| <li>Gaussian Naive Bayes Classifier (<a href="https://issues.apache.org/jira/browse/SPARK-16872">SPARK-16872</a>) and Complement Naive Bayes Classifier (<a href="https://issues.apache.org/jira/browse/SPARK-29942">SPARK-29942</a>) were added.</li> |
| <li>ML function parity between Scala and Python |
| (<a href="https://issues.apache.org/jira/browse/SPARK-28958">SPARK-28958</a>).</li> |
| <li><code class="language-plaintext highlighter-rouge">predictRaw</code> is made public in all the Classification models. <code class="language-plaintext highlighter-rouge">predictProbability</code> is made public in all the Classification models except <code class="language-plaintext highlighter-rouge">LinearSVCModel</code> |
| (<a href="https://issues.apache.org/jira/browse/SPARK-30358">SPARK-30358</a>).</li> |
| </ul> |
| |
| <h1 id="migration-guide">Migration Guide</h1> |
| |
| <p>The migration guide is now archived <a href="ml-migration-guide.html">on this page</a>.</p> |
| |
| <div class="footnotes" role="doc-endnotes"> |
| <ol> |
| <li id="fn:1" role="doc-endnote"> |
| <p>To learn more about the benefits and background of system optimised natives, you may wish to |
| watch Sam Halliday’s ScalaX talk on <a href="http://fommil.github.io/scalax14/#/">High Performance Linear Algebra in Scala</a>. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">↩</a></p> |
| </li> |
| </ol> |
| </div> |
| |
| |
| </div> |
| |
| <!-- /container --> |
| </div> |
| |
| <script src="js/vendor/jquery-3.5.1.min.js"></script> |
| <script src="js/vendor/bootstrap.bundle.min.js"></script> |
| <script src="js/vendor/anchor.min.js"></script> |
| <script src="js/main.js"></script> |
| <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script> |
| <script type="text/javascript"> |
| // DocSearch is entirely free and automated. DocSearch is built in two parts: |
| // 1. a crawler which we run on our own infrastructure every 24 hours. It follows every link |
| // in your website and extract content from every page it traverses. It then pushes this |
| // content to an Algolia index. |
| // 2. a JavaScript snippet to be inserted in your website that will bind this Algolia index |
| // to your search input and display its results in a dropdown UI. If you want to find more |
| // details on how works DocSearch, check the docs of DocSearch. |
| docsearch({ |
| apiKey: 'b18ca3732c502995563043aa17bc6ecb', |
| indexName: 'apache_spark', |
| inputSelector: '#docsearch-input', |
| enhancedSearchInput: true, |
| algoliaOptions: { |
| 'facetFilters': ["version:3.2.0"] |
| }, |
| debug: false // Set debug to true if you want to inspect the dropdown |
| }); |
| |
| </script> |
| |
| <!-- MathJax Section --> |
| <script type="text/x-mathjax-config"> |
| MathJax.Hub.Config({ |
| TeX: { equationNumbers: { autoNumber: "AMS" } } |
| }); |
| </script> |
| <script> |
| // Note that we load MathJax this way to work with local file (file://), HTTP and HTTPS. |
| // We could use "//cdn.mathjax...", but that won't support "file://". |
| (function(d, script) { |
| script = d.createElement('script'); |
| script.type = 'text/javascript'; |
| script.async = true; |
| script.onload = function(){ |
| MathJax.Hub.Config({ |
| tex2jax: { |
| inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], |
| displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], |
| processEscapes: true, |
| skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'] |
| } |
| }); |
| }; |
| script.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + |
| 'cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js' + |
| '?config=TeX-AMS-MML_HTMLorMML'; |
| d.getElementsByTagName('head')[0].appendChild(script); |
| }(document)); |
| </script> |
| </body> |
| </html> |