MLlib
| Developer | Apache Software Foundation (Apache Spark project) |
|---|---|
| Initial release | Spark 0.8.0 (RDD-based API); spark.ml previewed in Spark 1.2.0
|
| Latest release | Spark 4.3.0 (2026-10-30) |
| Written in | Scala, with Python, Java and R APIs |
| Type | Machine learning library |
| License | Apache License 2.0 |
| Website | MLlib Main Guide |
| Repository | github.com/apache/spark (mllib/) |
| Related | spark.mllib (RDD-based API), Apache Spark, Spark Connect |
spark.mllib package has been in maintenance mode since Spark 2.0; the DataFrame-based spark.ml package is the primary API.[1]MLlib is the machine learning library of Apache Spark. It provides distributed learning algorithms (classification, regression, clustering, collaborative filtering), feature transformations, ML Pipelines, model persistence and utilities such as linear algebra and statistics.[1] MLlib has two APIs: the DataFrame-based API in the spark.ml package, which is the primary API, and the older RDD-based API in the spark.mllib package, which has been in maintenance mode since Spark 2.0.[1] Neither API, and not MLlib as a whole, is deprecated.[1]
Two APIs
spark.ml (DataFrame-based) |
spark.mllib (RDD-based)
| |
|---|---|---|
| Status in Spark 4.3.0 | Primary API; new features go here | Maintenance mode since Spark 2.0: bug fixes only, no new features |
| Data type | DataFrame with feature vector columns | RDD of objects such as LabeledPoint
|
| Building blocks | Estimators, transformers, evaluators and pipelines | Algorithm objects with train methods
|
| Linear algebra types | org.apache.spark.ml.linalg
|
org.apache.spark.mllib.linalg
|
| Spark Connect | Supported from Spark 4.0.0 (Python) | Not supported, because Connect has no RDD API |
Sources: the MLlib guide and migration guide,[1][2] the Spark Connect overview[3] and SPARK-50812.[4]
The MLlib guide gives the reasons for the move to DataFrames: a friendlier API, Spark data sources, SQL queries, the Catalyst and Tungsten optimizations, one API across languages, and practical ML Pipelines, especially for feature transformations.[1]
What "Spark ML" means
"Spark ML" is not an official name. The MLlib guide says it is sometimes used for the DataFrame-based API, because of the org.apache.spark.ml package name and the early term "Spark ML Pipelines". The official name of the library, covering both APIs, is MLlib.[1] In code, pyspark.ml is the DataFrame-based API and pyspark.mllib is the RDD-based one.
History
MLlib was introduced in Spark 0.8.0 as a library of machine learning and optimization algorithms, developed with the UC Berkeley MLbase project.[5] Spark 1.2.0 previewed a new set of machine learning APIs in a package called spark.ml, built around learning pipelines and using Spark SQL's SchemaRDD (the predecessor of the DataFrame) to represent datasets.[6] In Spark 2.0.0 the DataFrame-based API became the primary API and the RDD-based API entered maintenance mode.[7] The Spark 2.x versions of the MLlib guide said the RDD-based API was expected to be removed in Spark 3.0; that sentence was dropped from the guide for the 3.0 release, and the RDD-based API is still part of Spark 4.3.0.[8][9] See spark.mllib (RDD-based API) for what was removed from that package.
MLlib and Spark Connect
Spark has had two attempts at machine learning over Spark Connect.
pyspark.ml.connect(Spark 3.5.0). Spark 3.5.0 added a separate package,pyspark.ml.connect, with its own estimators, transformers, pipelines and cross-validation for Connect clients.[10] This package was deprecated in Spark 4.0.0 (SPARK-50828); its classes carry adeprecated:: 4.0.0note at the v4.3.0 tag.[11][12]pyspark.mlon Connect (Spark 4.0.0). Spark 4.0.0 made the regularpyspark.mlAPI work on Spark Connect (SPARK-50812), listed as "ML on Spark Connect" in the release highlights.[13][4] When the session is remote,pyspark.mlsends fit and transform calls to the Connect server, which runs the Scala implementation in its ML handler.[14][15]
The RDD-based spark.mllib API cannot run over Connect, because Connect does not support RDDs or the SparkContext.[3]
Example
A DataFrame-based pipeline in PySpark. The same code runs in a classic session and, from Spark 4.0.0, in a Spark Connect session.
from pyspark.ml import Pipeline
from pyspark.ml.classification import LogisticRegression
from pyspark.ml.feature import VectorAssembler
train = spark.createDataFrame(
[(0.0, 1.1, 0.1), (1.0, 2.0, 1.0), (0.0, 1.3, -0.5), (1.0, 2.2, 1.5)],
["label", "x1", "x2"])
pipeline = Pipeline(stages=[
VectorAssembler(inputCols=["x1", "x2"], outputCol="features"),
LogisticRegression(maxIter=10),
])
model = pipeline.fit(train)
model.transform(train).select("label", "prediction").show()
See also
References
- ↑ 1.0 1.1 1.2 1.3 1.4 1.5 1.6 MLlib: Main Guide (docs/ml-guide.md at v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Migration Guide: MLlib (docs/ml-migration-guide.md at v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ 3.0 3.1 Spark Connect Overview (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ 4.0 4.1 SPARK-50812: Support pyspark.ml on Connect. Apache Software Foundation JIRA.Retrieved 2026-11-22.
- ↑ Spark Release 0.8.0. Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Spark Release 1.2.0. Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Spark Release 2.0.0. Apache Software Foundation.Retrieved 2026-11-22.
- ↑ MLlib: Main Guide (docs/ml-guide.md at v2.4.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ SPARK-30934: ML, GraphX 3.0 QA: Programming guide update and migration guide. Apache Software Foundation JIRA.Retrieved 2026-11-22.
- ↑ Spark Release 3.5.0. Apache Software Foundation.Retrieved 2026-11-22.
- ↑ SPARK-50828: Deprecate pyspark.ml.connect. Apache Software Foundation JIRA.Retrieved 2026-11-22.
- ↑ python/pyspark/ml/connect/base.py (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Spark Release 4.0.0. Apache Software Foundation.Retrieved 2026-11-22.
- ↑ python/pyspark/ml/util.py (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ sql/connect/server/.../connect/ml (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.