Lesson 8: Software Automation

Machine Learning & Artificial Intelligence

⏱️ 60 minutes 🤖 Year 12 Priority 🎯 HSC Critical 🧠 AI/ML Focus

📖 Introduction

Software automation uses Machine Learning (ML) and Artificial Intelligence (AI) to automate repetitive tasks, make predictions, and enable intelligent decision-making.

Core Concepts:
  • Automation: DevOps, RPA, BPA
  • AI: Broad concept of intelligent machines
  • ML: Subset of AI that learns from data
  • Training: Supervised, unsupervised, reinforcement learning

🔧 How ML Supports Automation

1. DevOps (Development + Operations)

ML automates integration between software development and IT operations.

📖 DevOps ML Applications
  • Continuous Integration/Deployment (CI/CD): Automated testing, build processes, deployment
  • Anomaly Detection: Identify system failures before they occur
  • Log Analysis: Parse millions of log entries to find errors
  • Resource Optimization: Predict server load, auto-scale infrastructure
  • Code Review: ML models suggest improvements, detect bugs

Example: GitHub Copilot uses ML to suggest code completions based on context.

2. RPA (Robotic Process Automation)

Software "robots" automate repetitive, rule-based tasks.

📖 RPA Use Cases
  • Data Entry: Extract data from invoices, enter into databases
  • Email Processing: Read emails, categorize, send automated responses
  • Report Generation: Compile data from multiple sources, create reports
  • Customer Onboarding: Verify documents, create accounts, send welcome emails
  • Payroll Processing: Calculate wages, deductions, generate payslips

Tools: UiPath, Automation Anywhere, Blue Prism

3. BPA (Business Process Automation)

Automates complex business workflows involving multiple systems and decisions.

Aspect RPA BPA
Scope Individual repetitive tasks End-to-end business processes
Complexity Simple, rule-based Complex workflows with decision logic
Example Copy data from email to spreadsheet Complete order fulfillment (order → payment → shipping → notification)
Integration Surface-level (UI interaction) Deep (API, database integration)

🤖 Artificial Intelligence vs Machine Learning

Key Distinction:
  • AI (Artificial Intelligence): Broad concept of machines performing tasks that typically require human intelligence (reasoning, learning, problem-solving)
  • ML (Machine Learning): Subset of AI where machines learn from data without explicit programming

Analogy: AI is the goal (intelligent machines), ML is the method (learning from data to achieve intelligence).

AI vs ML vs Deep Learning - Nested circles showing AI as the outermost concept, ML as a subset, and Deep Learning as a subset of ML

Visual Hierarchy: AI encompasses ML, which encompasses Deep Learning.
Source: Edureka

📖 AI vs ML Examples

AI (broader category):

  • Chess-playing program (rule-based AI, not necessarily ML)
  • Self-driving cars (combines ML, computer vision, robotics)
  • Virtual assistants (Siri, Alexa) - combines ML, NLP, speech recognition

ML (specific technique within AI):

  • Spam email filter (learns from labeled spam/not spam examples)
  • Product recommendations (learns from purchase history)
  • Image recognition (learns from labeled images)
Aspect Traditional Programming Machine Learning
Approach Programmer writes explicit rules Algorithm learns patterns from data
Adaptability Fixed rules, must manually update Adapts as new data arrives
Example "If email contains 'FREE MONEY', mark as spam" "Learn which patterns indicate spam from 10,000 examples"
Limitation Cannot handle unpredictable inputs Requires large datasets, may be biased

🎓 Training Machine Learning Models

ML models learn by analyzing data. Training method depends on data type and problem.

1. Supervised Learning

Learn from labeled data (input-output pairs). Model learns mapping from inputs to outputs.

📖 Supervised Learning Example: Email Spam Classification

Training Data (labeled):

  • "Congratulations! You won $1M!" → Spam
  • "Meeting tomorrow at 2pm" → Not Spam
  • "Click here for FREE iPhone!" → Spam
  • "Your order #12345 has shipped" → Not Spam

Process:

  1. Feed 10,000 labeled emails to model
  2. Model learns patterns (e.g., "FREE", "Click here", excessive punctuation = likely spam)
  3. Test on new, unseen emails
  4. Model predicts: spam or not spam

Common Applications: Image classification, fraud detection, medical diagnosis, price prediction

2. Unsupervised Learning

Learn from unlabeled data. Model finds hidden patterns without being told what to look for.

📖 Unsupervised Learning Example: Customer Segmentation

Training Data (unlabeled):

  • Customer 1: Age 25, Income $40K, Buys tech gadgets
  • Customer 2: Age 55, Income $80K, Buys gardening tools
  • Customer 3: Age 28, Income $45K, Buys tech gadgets
  • Customer 4: Age 60, Income $75K, Buys gardening tools

Process:

  1. Feed customer data (no labels like "Group A" or "Group B")
  2. Model clusters similar customers together
  3. Discovers: Group 1 (young, tech-focused), Group 2 (older, gardening-focused)
  4. Business uses segments for targeted marketing

Common Applications: Market segmentation, anomaly detection, data compression, recommendation systems

3. Semi-Supervised Learning

Mix of labeled (small amount) and unlabeled (large amount) data.

Why Semi-Supervised?

Labeling data is expensive and time-consuming. Semi-supervised uses small labeled dataset to guide learning on large unlabeled dataset.

Example: You have 100 labeled medical images (cancer/not cancer) and 10,000 unlabeled images. Model uses the 100 labeled to learn patterns, then applies to 10,000 unlabeled.

4. Reinforcement Learning

Learn through trial and error with rewards/penalties. Agent takes actions in environment, receives feedback.

📖 Reinforcement Learning Example: Game AI

Scenario: Training AI to play chess

  • Agent: AI chess player
  • Environment: Chess board and game rules
  • Actions: Legal chess moves
  • Reward: +1 for winning, -1 for losing, 0 for draw

Process:

  1. AI makes random moves initially (exploration)
  2. Receives rewards based on outcomes
  3. Learns which moves lead to wins (exploitation)
  4. Over thousands of games, improves strategy

Real-World Applications: Self-driving cars, robotics, game AI (AlphaGo), resource management

Learning Type Data Type Use Case Example
Supervised Labeled (input + output) Prediction, classification Email spam filter
Unsupervised Unlabeled (input only) Pattern discovery, clustering Customer segmentation
Semi-Supervised Small labeled + large unlabeled When labeling is expensive Medical image analysis
Reinforcement Feedback from actions Sequential decision-making Game AI, robotics

📱 Common Machine Learning Applications

1. Data Analysis and Forecasting

2. Virtual Personal Assistants

3. Image Recognition

📖 Real-World Example: Self-Driving Cars

Combines multiple ML techniques:

  • Computer Vision: Identify pedestrians, lanes, traffic lights
  • Sensor Fusion: Combine camera, LIDAR, radar data
  • Path Planning: Determine optimal route
  • Decision Making: When to brake, accelerate, change lanes
  • Reinforcement Learning: Improve driving through simulation

Companies: Tesla, Waymo, Cruise

🌳 Machine Learning Design Models

1. Decision Trees

Flowchart-like structure for making decisions based on feature values.

📖 Decision Tree Example: Should I Play Tennis?
Is it raining?
├── Yes → Don't play tennis
└── No → Is it windy?
    ├── Yes → Is temperature > 25°C?
    │   ├── Yes → Play tennis
    │   └── No → Don't play tennis
    └── No → Play tennis
                    

How it works:

  1. Start at root (top question)
  2. Follow branches based on answers
  3. Reach leaf node (final decision)

Advantages: Easy to understand, visualize, explain to non-technical people

Disadvantages: Can overfit (memorize training data), unstable (small data changes = big tree changes)

2. Neural Networks

Brain-inspired networks of interconnected nodes (neurons) that process information in layers.

📖 Neural Network Structure

Layers:

  • Input Layer: Receives raw data (e.g., pixel values of image)
  • Hidden Layers: Process and transform data (multiple layers = "deep learning")
  • Output Layer: Produces final prediction (e.g., "cat" or "dog")

How it learns:

  1. Feed training data through network
  2. Compare output to correct answer
  3. Adjust connection weights (backpropagation)
  4. Repeat thousands of times until accurate

Use Cases: Image recognition, speech recognition, language translation, game AI (AlphaGo), autonomous vehicles

Advantage: Can learn extremely complex patterns

Disadvantage: Requires massive data and computing power, "black box" (hard to explain why it made a decision)

Model Best For Pros Cons
Decision Trees Simple classification, interpretable decisions Easy to understand, fast, works with small data Overfits, unstable, limited accuracy on complex problems
Neural Networks Complex patterns (images, speech, text) Highly accurate, handles complex data Needs large data, slow to train, black box

📊 Common Machine Learning Algorithms

1. Linear Regression

Predicts numeric values assuming linear relationship between input and output.

Python - Linear Regression Example
from sklearn.linear_model import LinearRegression
import numpy as np

# Training data: house size (sqft) → price ($)
sizes = np.array([[1000], [1500], [2000], [2500], [3000]])
prices = np.array([200000, 300000, 400000, 500000, 600000])

# Create and train model
model = LinearRegression()
model.fit(sizes, prices)

# Predict price for 1800 sqft house
prediction = model.predict([[1800]])
print(f"Predicted price: ${prediction[0]:,.0f}")  # Output: ~$360,000
📖 Linear Regression Use Cases
  • Real Estate: Predict house prices from size, location, bedrooms
  • Sales Forecasting: Predict revenue from advertising spend
  • Risk Assessment: Predict insurance premiums from age, health
  • Supply Chain: Predict delivery time from distance, traffic

Limitation: Only works when relationship is linear (straight line). Real-world data often nonlinear.

2. Logistic Regression

Binary classification (yes/no, true/false, 0/1 predictions).

Python - Logistic Regression Example
from sklearn.linear_model import LogisticRegression
import numpy as np

# Training data: study hours → pass/fail
hours = np.array([[1], [2], [3], [4], [5], [6], [7], [8]])
passed = np.array([0, 0, 0, 1, 1, 1, 1, 1])  # 0=fail, 1=pass

# Create and train model
model = LogisticRegression()
model.fit(hours, passed)

# Predict: Will student pass if they study 3.5 hours?
prediction = model.predict([[3.5]])
probability = model.predict_proba([[3.5]])[0][1]

print(f"Prediction: {'Pass' if prediction[0] == 1 else 'Fail'}")
print(f"Probability of passing: {probability:.2%}")  # e.g., 67%
📖 Logistic Regression Use Cases
  • Medical Diagnosis: Disease present or not (based on symptoms, test results)
  • Credit Approval: Approve or deny loan application
  • Email Filtering: Spam or not spam
  • Customer Churn: Will customer cancel subscription?

3. K-Nearest Neighbors (KNN)

Classifies based on proximity to training data. "You are the average of your K closest neighbors."

📖 KNN Example: Movie Recommendations

Scenario: Recommend movies based on what similar users liked

Process (K=3):

  1. User A likes: Action, Sci-Fi, Thriller
  2. Find 3 most similar users (B, C, D) based on preferences
  3. User B liked "Inception" → User A might like it too
  4. Users C and D both liked "The Matrix" → Recommend "The Matrix"

How K affects results:

  • K=1: Very sensitive to outliers, may overfit
  • K=100: Too general, ignores local patterns
  • K=5-10: Often a good balance
Algorithm Problem Type Output Example
Linear Regression Regression (numeric prediction) Continuous number Predict house price: $350,000
Logistic Regression Binary classification 0 or 1 (yes/no) Email is spam: Yes (1)
K-Nearest Neighbors Classification or regression Category or number Movie genre: Action

🐍 Programming ML Models Using OOP

Object-oriented design makes ML code reusable, maintainable, and testable.

Quick Reminder: The 4 Pillars of OOP

1. Encapsulation

  • Bundle data (attributes) and methods together in a class
  • Hide internal details, expose only necessary interface
  • Example: Model's internal weights hidden, only train() and predict() exposed

2. Inheritance

  • Create new classes based on existing classes
  • Child class inherits attributes and methods from parent
  • Example: HousePricePredictor inherits from base MLModel class

3. Polymorphism

  • Same method name, different implementations
  • Objects of different classes respond to same method call
  • Example: Both LinearRegression and RandomForest have predict() method

4. Abstraction

  • Focus on essential features, hide complexity
  • Define interface without implementation details
  • Example: User calls predict() without knowing internal math calculations

These principles were covered in detail in Lesson 3. Here we apply them to machine learning!

Python - ML Model Class with OOP
class HousePricePredictor:
    """Predicts house prices using linear regression."""

    def __init__(self):
        from sklearn.linear_model import LinearRegression
        self.model = LinearRegression()
        self.is_trained = False

    def train(self, sizes, prices):
        """Train model on house sizes and prices."""
        self.model.fit(sizes, prices)
        self.is_trained = True
        print(f"Model trained on {len(sizes)} examples")

    def predict(self, size):
        """Predict price for given house size."""
        if not self.is_trained:
            raise ValueError("Model not trained yet!")

        prediction = self.model.predict([[size]])[0]
        return round(prediction, 2)

    def evaluate(self, test_sizes, test_prices):
        """Calculate model accuracy on test data."""
        from sklearn.metrics import r2_score
        predictions = [self.predict(size[0]) for size in test_sizes]
        score = r2_score(test_prices, predictions)
        return score

# Usage
predictor = HousePricePredictor()

# Training data
train_sizes = [[1000], [1500], [2000], [2500]]
train_prices = [200000, 300000, 400000, 500000]

predictor.train(train_sizes, train_prices)

# Make predictions
price = predictor.predict(1800)
print(f"Predicted price for 1800 sqft: ${price:,.0f}")

# Evaluate on test data
test_sizes = [[1200], [2200]]
test_prices = [240000, 440000]
accuracy = predictor.evaluate(test_sizes, test_prices)
print(f"Model accuracy (R²): {accuracy:.2%}")
Benefits of OOP in ML:
  • Encapsulation: Hide model complexity, expose simple interface
  • Reusability: Create once, use in multiple projects
  • Inheritance: Extend base model for specialized use cases
  • Polymorphism: Swap different models (LinearRegression → RandomForest) without changing code
  • Testability: Unit test train(), predict(), evaluate() methods separately

🌍 Impact of Automation on Society

Positive Impacts

1. Worker Safety Improvements

2. Support for People with Disabilities

3. Production Efficiency

Negative Impacts

1. Employment Disruption

Example: Truck Driving

Self-driving trucks threaten 3.5 million truck driver jobs in the US. While safer and more efficient, massive retraining needed for displaced workers.

Question: Who pays for retraining? What happens to small towns dependent on trucking?

2. Wealth Distribution

3. Environmental Effects

Impact Area Positive Negative
Employment New tech jobs, safer working conditions Job displacement, skill mismatch
Economy Increased productivity, lower costs Income inequality, wealth concentration
Accessibility Tools for disabled, elderly, remote areas Digital divide (access gap)
Environment Optimized resource use, reduced waste Energy consumption, e-waste

⚖️ Dataset Bias and Ethical Considerations

Understanding Bias in AI/ML

ML models learn from data. If training data is biased, the model will be biased.

Bias in Training Data Leads to Biased AI

Fundamental Rule: Machine learning models reflect the data they're trained on. Biased data → biased decisions.

Types of Bias

1. Historical Bias

Data reflects historical discrimination and inequalities.

📖 Example: Hiring Algorithm Bias

Scenario: Company trains ML model to screen job applicants

Training Data: Resumes of past successful hires (mostly men in tech roles)

Result: Model learns to favor male applicants, penalizes female applicants

Why: Historical data reflects past discrimination, model amplifies it

Real Case: Amazon scrapped hiring AI in 2018 for gender bias

2. Representation Bias

Training data doesn't represent population diversity.

📖 Example: Facial Recognition Bias

Problem: Facial recognition models trained mostly on white faces

Result: Higher error rates for people of color (false positives in security systems)

Study: MIT found some systems had 0.8% error for white males, 34% error for dark-skinned females

Solution: Diverse, representative training datasets

3. Measurement Bias

Features used for training are poor proxies for what we want to measure.

📖 Example: Recidivism Prediction

System: COMPAS (predicts if criminal will reoffend)

Problem: Uses arrest history as proxy for criminality

Bias: Black defendants flagged as high-risk twice as often as white defendants (similar crimes)

Why: Arrest rates reflect policing bias, not actual crime rates

Impact: Longer sentences, denied parole for biased predictions

Ethical Principles for AI/ML

Responsible AI Development:
  • Fairness: Ensure equal treatment across demographics (age, gender, race)
  • Transparency: Explain how model makes decisions (no "black boxes")
  • Accountability: Identify who is responsible when AI causes harm
  • Privacy: Protect user data, obtain informed consent
  • Safety: Test rigorously before deployment, especially in critical systems (healthcare, criminal justice)
  • Human Oversight: Humans make final decisions in high-stakes scenarios

Cultural and Psychological Considerations

Cultural Protocols and Belief Systems

Psychological and Stress Response Patterns

Key Takeaway:

ML is a powerful tool, but not neutral. Developers must actively work to identify and mitigate bias. Data scientists have ethical responsibility to build fair, transparent, accountable systems.

📝 Lesson Summary

Key Topics Covered:
  • Automation: DevOps (CI/CD, anomaly detection), RPA (task automation), BPA (workflow automation)
  • AI vs ML: AI = intelligent machines (broad), ML = learning from data (specific technique)
  • Training Models: Supervised (labeled), unsupervised (unlabeled), semi-supervised (mix), reinforcement (rewards)
  • Applications: Data forecasting, virtual assistants, image recognition, self-driving cars
  • Design Models: Decision trees (flowchart), neural networks (brain-inspired)
  • Algorithms: Linear regression (numeric), logistic regression (binary), K-nearest neighbors (similarity)
  • OOP in ML: Encapsulation, reusability, inheritance for ML models
  • Impact: Positive (safety, accessibility, efficiency), Negative (job displacement, inequality)
  • Ethics: Dataset bias, fairness, transparency, accountability, cultural sensitivity
HSC Exam Tips:
  • Distinguish AI (broad) from ML (learns from data)
  • Know training types: supervised needs labels, unsupervised finds patterns
  • Explain bias: biased training data → biased AI decisions
  • Describe impact: job displacement vs new opportunities
  • Give real examples: spam filter (supervised), customer segmentation (unsupervised)
Congratulations!

You've completed all 8 theory lessons. Focus now on coding practice and review. Good luck on the HSC exam!

← Back to Dashboard