Project: Apache Spark (App Definition and Development / Streaming & Messaging)
File: ml-guide.md

layout: global title: "MLlib: Main Guide" displayTitle: "Machine Learning Library (MLlib) Guide" license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 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: ML Algorithms: common learning algorithms such as classification, regression, clustering, and collaborative filtering Featurization: feature extraction, transformation, dimensionality reduction, and selection Pipelines: tools for constructing, evaluating, and tuning ML Pipelines Persistence: saving and load algorithms, models, and Pipelines Utilities: linear algebra, statistics, data handling, etc. The MLlib RDD-based API is now in maintenance mode. As of Spark 2.0, the -based APIs in the `spark.mllib` package have entered maintenance mode. The primary Machine Learning API for Spark is now the -based API in the `spark.ml` package. What are the implications? MLlib will still support the RDD-based API in `spark.mllib` with bug fixes. MLlib will not add new features to the RDD-based API. In the Spark 2.x releases, MLlib will add features to the DataFrames-based API to reach feature parity with the RDD-based API. Why is MLlib switching to the DataFrame-based API? 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. The DataFrame-based API for MLlib provides a uniform API across ML algorithms and across multiple languages. DataFrames facilitate practical ML Pipelines, particularly feature

See the for details. What is "Spark ML"? "Spark ML" is not an official name but occasionally used to refer to the MLlib DataFrame-based API. This is majorly due to the `org.apache.spark.ml` Scala package name used by the DataFrame-based API, and the "Spark ML Pipelines" term we used initially to emphasize the pipeline concept. Is MLlib deprecated? 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. MLlib uses linear algebra packages and for optimised numerical processing or if they are available as system libraries or in runtime library paths. However, native acceleration libraries can't be distributed with Spark. See 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: ``` WARNING: Failed to load implementation from:dev.ludovic.netlib.blas.JNIBLAS ``` To use MLlib in Python, you will need version 1.4 or newer. watch Sam Halliday's ScalaX talk on . The list below highlights some of the new features and enhancements added to MLlib in the `3.0` release of Spark: Multiple columns support was added to `Binarizer` (), `StringIndexer` (), `StopWordsRemover` () and PySpark `QuantileDiscretizer` (). Tree-Based Feature Transformation was added (). Two new evaluators `MultilabelClassificationEvaluator` () and `RankingEvaluator` () were added. Sample weights support was added in `DecisionTreeClassifier/Regressor` (), `RandomForestClassifier/Regressor` (), `GBTClassifier/Regressor` (), `MulticlassClassificationEvaluator` (), `RegressionEvaluator` (), `BinaryClassificationEvaluator` (), `BisectingKMeans` (), `KMeans` () and `GaussianMixture` (). R API for `PowerIterationClustering` was added (). Added Spark ML listener for tracking ML pipeline status (). Fit with validation set was added to Gradient Boosted Trees in Python (). transformer was added (). classifier and regressor were added (). Gaussian Naive Bayes Classifier () and Complement Naive Bayes Classifier () were added. ML function parity between Scala and Python (). `predictRaw` is made public in all the Classification models. `predictProbability` is made public in all the Classification models except `LinearSVCModel` (). The migration guide is now archived .