Why spark.ml don't implement any of spark.mllib algorithms?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Apache Spark is a powerful open-source data processing engine that supports a wide array of data analysis, machine learning, and graph processing tasks. Within Spark, two main modules provide machine learning functionalities: `spark.mllib` (the original Machine Learning library) and `spark.ml` (the DataFrame-based API). Over time, Spark has shifted its focus towards enhancing `spark.ml` instead of extending `spark.mllib`, which has prompted questions as to why `spark.ml` doesn't implement all algorithms from `spark.mllib`.
Differences Between `spark.mllib` and `spark.ml`
Before diving into the reasons, it’s important to grasp the differences between these two modules.
- Underlying Data Structures:
- spark.mllib: Utilizes RDDs (Resilient Distributed Datasets) for its computations. Although RDDs provide strong fault tolerance and elasticity, they are not as optimized for performance or ease of use as DataFrames.
- spark.ml: Leverages DataFrames and Datasets, which offer a more compact and efficient representation of data. DataFrames simplify ETL and ML workflows and improve runtime performance by utilizing Catalyst for query optimization and Tungsten for efficient code generation.
- API Design:
- spark.mllib: Offers a functional approach that operates directly on RDDs, lacking a structured way to compose machine learning pipelines.
- spark.ml: Provides a high-level API designed for pipeline configurations, which improves reusability and maintainability, supporting better encapsulation of data processing steps.
- Feature Richness:
- spark.ml: Comes with enhanced algorithms which are often improved versions of those in `spark.mllib`, harnessing the benefits of DataFrames to deliver more scalable solutions.
Why `spark.ml` Doesn’t Implement All `spark.mllib` Algorithms
- Evolution Towards DataFrames: As the Spark community observed the performance benefits and usability improvements of DataFrames, there was a shift in focus towards `spark.ml`. The newer DataFrame-based APIs provide better optimization and are easier to integrate with Spark SQL for ETL processes, motivating developers to prioritize DataFrame-compatible features over native RDD implementations.
- Cohesive API Design: The design of `spark.ml` promotes building, tuning, and deploying ML pipelines more effectively with the abstraction of stages (such as Transformers and Estimators). Implementing certain RDD-based algorithms in this pipeline-centric paradigm is challenging due to their incompatible design philosophies.
- Focus on Core Algorithms: Instead of directly porting all algorithms from `spark.mllib`, `spark.ml` focuses on a core set of widely-used, highly-optimized algorithms while ensuring they work seamlessly within pipelines. This strategic focus allows for maintaining robust and high-performance implementations.
- Legacy Considerations: Some algorithms in `spark.mllib` are legacy systems that, while effective in specific scenarios, are not warranted investment when newer, more efficient algorithms exist. Additionally, the RDD-centric nature of these algorithms might offer less value given the advantages of the DataFrame approach.
- Community and Resource Allocation: Open-source projects like Spark depend heavily on community contributions and resource allocation. Prioritizing and allocating limited resources to enhance a more promising platform (`spark.ml`) simply aligns with strategic goals for broader community impact.
Example Code
To illustrate the divergent approaches, consider a simple workflow involving linear regression in both `spark.mllib` and `spark.ml`.
`spark.mllib` Example Using RDDs
Related reading
- Why TensorBoard summary is not updating?
- Why tensorflow GPU memory usage decreasing when I increasing the batch size?
- Why Tensorflow is unable to compute the gradient wrt the reshaped parameters?
- why tensorflow just outputs killed
- Why using apache kafka in real-time processing
- Why we require Apache Kafka with NoSQL databases?
- Why the tree resulting from Kruskal is different from Dijkstra?
- Why there is no stdcopy_if algorithm?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.