Unit 4
Unit 4
What is System ML? And Spark ML Context - Explain the purpose and the origin of System
ML, List the alternatives to System ML, compare performances of System ML with the
alternatives, Use ML Context to interact with System ML (in Scala), Describe and use a number
of System ML algorithms.
Differences
Aspect Machine Learning System Machine Learning
Encompasses the entire
Focuses on algorithms and system including ML
Scope data-driven learning components
Integration, deployment, and
Model development and operationalization of ML
Emphasis training models
Data pipelines, infrastructure,
Components Algorithms, models, datasets model management
Specific tasks (e.g., End-to-end solutions in
Applications classification, regression) operational settings
System machine learning refers to the combination of machine learning techniques with system-
level problems. In general, it can involve using machine learning to optimize, improve, or automate
the performance of computing systems, infrastructure, or software systems.
Here's how it could be interpreted in different contexts:
1. Machine Learning for Systems Optimization
• Resource Allocation: Using ML models to predict and optimize resource usage (e.g., CPU,
memory, storage, etc.) in systems like cloud computing environments or distributed
systems.
• Load Balancing: Applying ML to improve load balancing algorithms by predicting the
workload distribution or making decisions based on past traffic patterns or system state.
2. Machine Learning as a Part of System Design
• Self-Managing Systems: Some systems (like autonomous systems or self-healing
networks) use machine learning to adapt and optimize their operation without human
intervention. For example, systems that automatically detect and correct failures, or that
learn optimal operating conditions over time.
• Adaptive Systems: Systems that can dynamically adapt their behavior based on
environmental changes or workload. For example, data centers that adjust cooling systems
based on server utilization, or smart grids that optimize energy distribution.
3. Integrated System Design for Machine Learning Applications
• ML Hardware Systems: Designing specialized hardware or systems for machine learning
applications. This could include chips like GPUs or TPUs that accelerate ML workloads,
or edge devices that perform local ML inference.
• ML System Pipelines: Refers to building end-to-end ML pipelines for data ingestion,
training, deployment, and monitoring, where system-level engineering ensures the overall
ML system runs efficiently at scale.
4. ML for Software Engineering Systems
• Bug Detection and Code Analysis: Using machine learning to automatically analyze
source code for bugs, security vulnerabilities, or inefficiencies, thereby assisting software
development systems.
• Automated Software Testing: ML-based techniques can help automate the process of
testing software by learning patterns from previous testing datasets and predicting which
areas of the code are more likely to contain defects.
Example Technologies and Fields Involved
• Reinforcement Learning for optimizing system performance in environments where trial-
and-error can be employed (e.g., network traffic management, cloud resource scheduling).
• Deep Learning models can be embedded in systems like robotics, autonomous vehicles,
and IoT devices.
• Anomaly Detection systems in infrastructure, using ML to identify unusual behavior that
could indicate system failures or security breaches.
Below are some Examples of system machine learning:-
1. Cloud Resource Management (Auto-Scaling)
Example: Auto-Scaling in Cloud Computing
• Problem: Cloud systems often need to dynamically adjust resources (e.g., compute
instances, storage) based on fluctuating demand. This requires accurate prediction of
resource needs to ensure optimal performance without over-provisioning or under-
provisioning.
• Solution: Machine learning models can be used to predict future resource requirements
based on historical usage patterns. For instance, using time series forecasting or
regression models, a system can predict traffic spikes or compute demands in real-time
and automatically adjust the number of cloud instances, virtual machines, or containers
needed to handle the load.
2. Self-Healing Systems (Fault Detection and Recovery)
Example: Self-Healing IT Infrastructure
• Problem: In large-scale IT infrastructure (e.g., data centers), hardware failures, software
bugs, or performance degradation can lead to downtime or degraded service. Detecting
and resolving issues quickly is crucial.
• Solution: A system can leverage machine learning for anomaly detection to identify
unusual behavior in system logs, network traffic, or resource usage. Once an anomaly is
detected, the system can take automated actions (e.g., restart services, migrate workloads,
or adjust configurations) to recover from the failure.
3. Network Traffic Optimization (SDN and QoS)
Example: Machine Learning in Software-Defined Networking (SDN) for Traffic Routing
• Problem: In large-scale networking environments, managing Quality of Service (QoS)
and optimizing traffic routing can be complex, especially when the network traffic is
unpredictable.
• Solution: Machine learning can be used to dynamically adjust network traffic flows by
analyzing historical traffic patterns, detecting anomalies, and predicting congestion
points. Reinforcement learning, for example, could help optimize traffic routing by
adjusting weights in network paths in real time.
4. Smart Databases (Query Optimization)
Example: Machine Learning for Query Optimization in Databases
• Problem: Traditional database query optimizers rely on static rules and heuristics to
decide how to execute SQL queries. However, this approach may not adapt well to
evolving data patterns or workloads.
• Solution: Machine learning models, such as neural networks or reinforcement
learning, can be trained to predict the most efficient query execution plans based on past
query patterns, data distribution, and system performance metrics. This allows databases
to automatically choose the best plan for executing complex queries.
5. Automated Software Testing (Code Coverage and Bug Detection)
Example: Machine Learning for Software Testing
• Problem: Writing test cases and ensuring complete code coverage in complex software
systems can be a labor-intensive and error-prone process. Additionally, detecting bugs
early in the development cycle is challenging.
• Solution: ML can be used to automatically generate or prioritize test cases, analyze
source code for potential vulnerabilities, or predict which parts of the code are most
likely to contain bugs based on past patterns. Techniques like neural networks can help
generate new test cases based on previous ones, while supervised learning can be
applied to predict code sections prone to errors.
6. Autonomous Systems (Robotics and IoT)
Example: Autonomous Vehicles and Drones
• Problem: Autonomous vehicles or drones need to adapt to changing environments, make
real-time decisions, and optimize their actions based on sensor data, all while interacting
with a complex system of hardware and software components.
• Solution: ML techniques such as reinforcement learning, deep learning, and computer
vision can be used to train systems to navigate environments, recognize obstacles,
optimize flight paths, or respond to sensor inputs. These systems can continually improve
by learning from past interactions and feedback.
7. Energy Management in Smart Grids
Example: Predictive Load Forecasting and Energy Distribution
• Problem: In smart grids, the demand for electricity can vary dramatically, and efficient
distribution is crucial to avoid blackouts or wastage of resources. Predicting energy
demand and dynamically adjusting energy flow is a complex task.
• Solution: Machine learning models can analyze patterns in electricity consumption,
weather data, and other external factors to predict energy demand more accurately. These
models can also help optimize energy storage and distribution, ensuring that power is
available where it’s needed most while minimizing waste.
8. Predictive Maintenance in Manufacturing
Example: Machine Learning for Predictive Maintenance of Industrial Equipment
• Problem: In manufacturing and other industrial sectors, equipment failure can result in
costly downtime and repairs. Predicting when machines are likely to fail allows
companies to perform maintenance proactively, reducing costs and increasing
productivity.
• Solution: Sensors installed on equipment collect data on various metrics (e.g.,
temperature, vibration, pressure). Machine learning models can analyze this data to detect
early signs of wear or failure, such as unusual vibrations or temperature changes, and
predict when maintenance is needed before a failure occurs.
Some Real-life Examples of system machine Learning
• Email Spam Filters
Email providers like Gmail use machine learning to automatically detect spam emails.
The system learns from millions of emails, analyzing factors like keywords, sender
reputation, and user behavior (like marking emails as spam). Over time, the spam filter
gets better at keeping unwanted emails out of your inbox.
• Streaming Recommendations
Services like Netflix, YouTube, and Spotify use machine learning to recommend shows,
videos, or songs based on your past choices. Their system collects data on what you
watch or listen to, learns your preferences, and suggests new content you might enjoy.
Each time you interact, the system learns more, making its recommendations more
accurate.
• Smart Assistants
Assistants like Siri, Alexa, and Google Assistant rely on machine learning to understand
spoken language and respond accurately. When you ask a question, the system processes
your words and matches them with possible answers. As it interacts with more users, it
improves its ability to understand different accents, languages, and queries.
• Navigation and Traffic Predictions
Apps like Google Maps or Waze use machine learning to predict traffic and provide real-
time route suggestions. The system gathers data from drivers, like speed and location, and
combines it with historical traffic patterns. It learns to predict the best routes, estimate
travel times, and even detect accidents or slowdowns.
• Fraud Detection in Banking
Banks use machine learning to detect unusual transactions that could be fraudulent. The
system learns what normal spending patterns look like and can flag unusual behavior, like
a large overseas transaction. This helps prevent fraud by notifying customers or blocking
suspicious activity in real-time.
• Social Media Feeds
Platforms like Facebook, Instagram, and Twitter use machine learning to personalize your
feed. The system learns which types of posts, pages, or friends you interact with the most
and uses this information to show you content it thinks you’ll like. This makes your feed
more engaging by prioritizing content that aligns with your preferences.
• Online Shopping Recommendations
E-commerce sites like Amazon use machine learning to suggest products based on your
browsing and purchase history. The system learns which items are often bought together
and tailors recommendations for each user, increasing the chances that you’ll find
something relevant to buy.
Machine learning systems are both trained and operated using cleaned and processed data (called
features), created by a program called a feature pipeline. The feature pipeline writes its output
feature data to a feature store that feeds data to both the training pipeline (that trains the model)
and the inference pipeline. The inference pipeline makes predictions on new data that comes from
the feature pipeline. Real-time, interactive ML systems also take new data as input from the user.
Feature pipelines and inference pipelines are operational services - part of the operational ML
system. In contrast, a ML system also has an offline component - model training. The training of
models is typically not an operational part of a ML system. Training pipelines can be run on
separate systems using separate resources (e.g., GPUs). Models are sometimes retrained on a
schedule (e.g., once day/week/etc), but are often retrained when a new improved model becomes
available, e.g., because new training data is available or the existing model’s performance has
degraded and the model needed to be retrained on more recent data.
The origins of Machine Learning (ML) and Artificial Intelligence (AI) are deeply rooted in
the fields of mathematics, statistics, computer science, and cognitive science. The development
of ML as we know it today is the result of centuries of intellectual advancement, with key
milestones spanning many decades. Here's a brief history of the origin of Machine Learning:
1. Early Foundations (Pre-1950s):
• Mathematics & Statistics: Many machine learning algorithms rely on mathematical
principles, such as probability theory, linear algebra, and optimization. Early work in
statistics, especially around regression and classification, laid the groundwork for modern
ML techniques.
• Turing and the Concept of Machines: In the 1930s, Alan Turing proposed the concept
of the Turing Machine, which was the theoretical foundation for modern computing. In
1950, he published the Turing Test, a measure of a machine's ability to exhibit intelligent
behavior equivalent to, or indistinguishable from, that of a human.
2. 1950s: The Birth of Artificial Intelligence:
• Alan Turing: Turing's 1950 paper, "Computing Machinery and Intelligence," is often
considered the first work in AI, where he introduced the concept of machines being able
to simulate human intelligence.
• Cybernetics and Early AI: Researchers like Norbert Wiener in the 1940s and 1950s
laid the groundwork for feedback systems (which later influenced reinforcement
learning). The focus was on systems that could "learn" from feedback and adapt.
3. 1950s-1960s: The Advent of Early Machine Learning Algorithms:
• Perceptron (1958): The Perceptron, introduced by Frank Rosenblatt, is often
considered one of the earliest artificial neural networks. It could learn to classify objects
(based on inputs like image pixels) into two categories.
• Arthur Samuel (1959): Arthur Samuel, an American computer scientist, is credited with
coining the term "machine learning." He worked on developing a checkers-playing
program that could learn to improve its performance over time. This is one of the first
examples of a machine learning algorithm that could improve with experience.
4. 1970s-1980s: Rise of Statistical Learning and Neural Networks:
• The AI Winter (1970s-1980s): After early successes, the hype around AI and machine
learning dwindled during the 1970s and early 1980s. This period, known as the AI
Winter, was marked by a slowdown in research funding and progress due to unmet
expectations.
• Neural Networks: Interest in neural networks revived in the 1980s with the invention of
the Backpropagation algorithm by Geoffrey Hinton, David Rumelhart, and Ronald
Williams. Backpropagation allowed multi-layer neural networks to be trained more
efficiently and led to the development of deep learning techniques in later years.
5. 1990s: The Emergence of Machine Learning as a Field:
• Support Vector Machines (SVM): In the 1990s, Vladimir Vapnik and colleagues
developed Support Vector Machines, a powerful algorithm for classification tasks.
SVMs became one of the most popular algorithms for text classification, image
recognition, and other tasks.
• Random Forests and Boosting: The development of Random Forests (by Leo
Breiman in 1995) and Boosting algorithms (such as AdaBoost, developed by Yoav
Freund and Robert Schapire) significantly improved the performance of machine
learning models by combining the predictions of multiple models.
6. 2000s: Data-Driven ML and the Big Data Era:
• Data Explosion: The growth of the internet and the digitization of data in the 2000s led
to an explosion in available data. Machine learning algorithms became increasingly
effective as they were able to learn from large datasets.
• Deep Learning: In the 2000s, Geoffrey Hinton and his colleagues began to work on
deep learning, using neural networks with many layers (also known as deep neural
networks). This research laid the foundation for many breakthroughs in speech
recognition, image classification, and natural language processing.
• Google's DeepMind: In 2006, Geoffrey Hinton and others revived deep learning with
the invention of more efficient methods for training deep networks, including the use of
Restricted Boltzmann Machines (RBM). DeepMind, founded by Demis Hassabis and
others in 2010, became a leader in AI, especially after its AlphaGo program defeated
human champions in the game of Go in 2016.
7. 2010s-Present: The Modern Age of Machine Learning:
• Big Data and Cloud Computing: The 2010s saw the growth of cloud computing
platforms (like Amazon Web Services, Google Cloud, and Microsoft Azure) which
allowed businesses and researchers to process large-scale data and train machine learning
models.
• Revolution in Deep Learning: Breakthroughs in deep learning, particularly with
Convolutional Neural Networks (CNNs) for image processing, and Recurrent Neural
Networks (RNNs) for sequential data, transformed industries such as computer vision,
natural language processing, and autonomous driving.
• Transformers and NLP: The development of the Transformer architecture in 2017, by
researchers at Google, revolutionized natural language processing. Models like BERT
(Bidirectional Encoder Representations from Transformers) and GPT (Generative
Pretrained Transformers) became state-of-the-art in tasks such as text generation,
translation, and sentiment analysis.
Alternatives to System ML
While machine learning (ML) is one of the most popular methods for building intelligent systems,
there are alternative approaches to designing systems that can achieve similar goals without relying
solely on ML. Here are some notable alternatives and complementary methods:
1. Rule-Based Systems
Description: Rule-based systems use pre-defined rules, logic, and conditions set by human experts
to make decisions. These systems rely on "if-then" statements to operate and can be highly
effective for well-defined, narrow tasks.
Applications: Diagnostic systems, expert systems, and certain recommendation engines where
outcomes are predictable.
Advantages: Explainable and transparent; can be easier to debug.
Limitations: Not scalable for complex, data-driven problems; difficult to maintain and update.
Example: Spam Filters: Rule-based email spam filters look for specific keywords or patterns (e.g.,
"FREE", "WINNER") and use predefined rules to classify emails as spam or not. Such systems
operate without learning from data but rely on rules manually set by experts.
Transfer learning:
Transfer learning is a technique in machine learning where a model developed for one task is
reused (or "transferred") as the starting point for a model on a new task. This is particularly useful
when you have a limited amount of data for the new task but have access to a model trained on a
large dataset for a similar task. Here’s an easy way to understand it:
1. Pre-trained Model: Start with a model that's already been trained on a big, similar dataset.
For example, image recognition models like ResNet or VGG, trained on millions of images,
are common starting points.
2. Re-use Layers: Keep the earlier layers of the model, as these often capture general patterns
(like edges and textures for images or common phrases for text) that are useful across
different tasks.
3. Fine-tuning Layers: Add new layers to adapt the model for your specific task, or "fine-
tune" some of the existing layers by re-training them on your smaller dataset.
4. Training on New Task: Train the adapted model on your new, smaller dataset. Since the
model has already "learned" a lot from the original large dataset, it doesn't need much new
data or training time to adapt to the new task.
Edge AI:-
Edge AI is when artificial intelligence (AI) works right on your local device—like your phone,
camera, or smartwatch—rather than sending data to distant servers or the "cloud" for processing.
Autonomous Vehicles
1) Tesla's Full Self-Driving (FSD) System: Tesla uses Edge AI to process data from
cameras, radar, and LIDAR sensors in real-time on the vehicle itself. The onboard AI
system makes instant decisions for tasks like lane-keeping, adaptive cruise control, object
detection, and collision avoidance.
2) Apple Watch uses Edge AI to monitor users' heart health. The watch processes
electrocardiogram (ECG) data locally, detecting irregularities such as atrial fibrillation
(AFib) in real-time. It sends alerts to the user if any abnormality is detected.
Federated Learning
It is a way for devices (like your phone, tablet, or computer) to work together to improve a machine
learning model without sharing any of your private data with a central server.
Here’s how it works in simple terms:
1. Training Locally: Imagine your phone is part of a group working to make a predictive text
model better (the type of model that suggests words while you type). Instead of sending
your personal typing data to a central server, the model is trained on your phone using only
your data.
2. Sending Only Updates: After training, your phone sends just the "learning updates"
(information about how the model improved based on your data) to a central server, not the
actual data itself. These updates are anonymous and don’t contain personal information.
3. Combining Updates: The central server takes updates from many devices and combines
them to improve the overall model. It’s like everyone contributing a little piece of
knowledge without sharing private details.
4. Improved Model for Everyone: Once the model is improved, the updated version is sent
back to everyone’s device. This way, everyone benefits from the improved model without
compromising privacy.
Why Use Federated Learning?
• Privacy: Your data stays on your device, keeping it safe and private.
• Less Data Transfer: Since only updates (not raw data) are shared, it uses less bandwidth.
• Personalized Learning: The model can learn from your data specifically, making it more
accurate and useful for you.
Real-Life Example
Predictive Text and Autocorrect on Smartphones: - How Federated Learning Helps: The keyboard
learns from each user's typing patterns individually and only sends updates (not actual words or
messages) to a central model, which combines the learning from thousands of users. This way,
everyone’s typing experience improves while keeping personal messages private.
Scala: -
Scala is a high-level, general-purpose programming language that is designed to be concise,
elegant, and highly expressive. It is a functional and object-oriented programming language that
runs on the Java Virtual Machine (JVM), which means it can easily integrate with Java libraries
and frameworks. Scala was created by Martin Odersky and was first released in 2003.
Key Features of Scala:
1. Object-Oriented: Scala supports object-oriented concepts such as classes, inheritance, and
polymorphism.
2. Functional Programming: It treats functions as first-class citizens, allowing higher-order
functions, immutability, and lazy evaluation.
3. Type Safety: Scala is statically typed, meaning errors are caught at compile-time, and it
includes advanced type inference.
4. Interoperability with Java: Scala can directly use Java libraries, frameworks, and tools,
making it easy to integrate into existing Java projects.
5. Scalability: Its name reflects its ability to scale from small scripts to large, complex
applications.
6. Concise Syntax: Scala’s syntax is more concise than Java, reducing boilerplate code.
Use Scala in Machine Learning?
1. Integration with Apache Spark:
✓ Spark's MLlib and ML libraries are designed for machine learning tasks such as
classification, regression, clustering, and collaborative filtering. These APIs are
natively written in Scala, providing the most seamless experience when using the
language.
2. Scalability:
✓ Scala excels in handling distributed datasets, making it ideal for big data machine
learning workflows.
3. Conciseness and Performance:
✓ Compared to Java, Scala provides concise syntax and high performance for
distributed tasks.
4. Functional Programming:
✓ Scala’s functional programming paradigm makes it easier to write transformations
and operations on data, which is common in machine learning workflows.
5. Interoperability:
✓ Scala can work alongside Python or R for prototyping while allowing deployment
in production environments.
Advantages of Scala:
• Combines functional and object-oriented programming.
• Reduces code verbosity compared to Java.
• High performance in distributed systems.
• Strong support for concurrent and parallel programming.
Disadvantages:
• Steeper learning curve for beginners.
• Slower compilation times compared to Java.
• Fewer learning resources compared to Java or Python.