Skip to content

Introduction to Machine Learning

This tutorial introduces machine learning (ML) fundamentals and helps you understand what ML is, when to use it, and the core concepts that power every ML system. You'll learn how ML differs from traditional programming and develop intuition for when ML makes sense.

Estimated time: 20 minutes

Why This Matters

Problem statement:

Traditional programming requires explicit instructions for every scenario. Machine learning learns patterns from examples instead.

ML vs Traditional Programming

Programming falls short when rules are too complex to code explicitly (recognizing faces in photos), when rules change frequently (detecting new fraud patterns), or when you need personalization at scale (recommending products to millions of users with different preferences).

Practical benefits: Understanding ML fundamentals helps you identify which problems benefit from ML, avoid misapplying ML to simple rule-based problems, and communicate effectively with data scientists and engineers.

Professional context: ML drives modern applications from search engines to voice assistants to fraud detection. Companies hiring data professionals expect fluency in ML concepts even for non-modeling roles. Knowing when ML applies (and when simpler approaches work better) separates effective practitioners from those who chase buzzwords.

Core Concepts

What is Machine Learning?

Machine Learning is the science of programming computers to learn patterns from data without being explicitly programmed for specific tasks.

Traditional programming approach:

Rules + Data → Output
Example: Calculate shipping cost

  • Rule: "If weight > 5kg, charge $10 + $2 per kg over 5"
  • Data: Package weighs 7kg
  • Output: $14

Machine learning approach:

Data + Desired Output → Model (learned rules)
Example: Predict shipping cost

  • Data: 10,000 past shipments (weight, distance, cost)
  • Desired output: Actual costs paid
  • Model: Learns patterns to predict cost for new packages

ML discovers patterns you didn't know existed. You provide examples, not instructions.

ML vs AI vs Deep Learning

These terms are often confused. Here's the relationship:

Artificial Intelligence (AI): The broadest term. Any technique making computers behave intelligently: includes rule-based systems, ML, robotics, expert systems.

Machine Learning (ML): A subset of AI. Systems that learn from data without explicit programming. Includes decision trees, regression, clustering, neural networks.

Deep Learning (DL): A subset of ML. Uses neural networks with many layers (hence "deep"). Excels at image recognition, natural language processing, game playing.

AI ML DL

This part of our training focuses on ML: You'll master foundational algorithms before exploring deep learning.

Key ML Terminology

Features (Input Variables): The attributes used to make predictions. In house price prediction: square footage, bedrooms, location, age.

Labels (Target Variable): What you're trying to predict. In house price prediction: the sale price.

Model: The mathematical representation that maps features to labels. Think of it as the "learned rules."

Training: The process of feeding data to an algorithm so it learns patterns. The model adjusts internal parameters to minimize prediction errors.

Prediction (Inference): Using a trained model to make predictions on new, unseen data.

Example ML

Example:

  • Features: [2000 sq ft, 3 bedrooms, Tirana, 5 years old]
  • Label: $250,000 (training data only)
  • Training: Model learns relationship between features and prices
  • Prediction: Given new house [1500 sq ft, 2 bedrooms, Durrës, 10 years old], model predicts price

How Models Learn

Step 1: Initialize - Model starts with random parameters (wild guesses)

Step 2: Make predictions - Use current parameters to predict labels for training data

Step 3: Calculate error - Compare predictions to actual labels, measure how wrong they are

Step 4: Adjust parameters - Update parameters to reduce error (the "learning" part)

Step 5: Repeat - Loop through steps 2-4 thousands of times until error is minimized

ML Cycle

Real-world analogy: Learning to shoot basketball free throws

  • Initialize: First shot goes nowhere near basket (random)
  • Make prediction: Take a shot with current technique
  • Calculate error: Measure distance from basket
  • Adjust: Modify arm angle, force, release point
  • Repeat: Practice until shots consistently go in

The model "practices" on training data until it gets good at predictions.

When to Use Machine Learning

ML makes sense when:

Complexity defeats explicit rules: Face recognition requires identifying patterns across millions of pixel combinations—impossible to code manually.

Patterns exist but are unclear: Customer churn depends on dozens of factors interacting in non-obvious ways. ML finds patterns humans miss.

Problems require personalization: Recommending movies to 100 million users means learning individual preferences—rule-based systems can't scale.

Rules change over time: Spam patterns evolve daily. ML models retrain automatically as new examples arrive.

Data is abundant: ML needs examples to learn. More data generally means better performance.

When NOT to Use Machine Learning

Avoid ML when:

Simple rules work: Calculating tax based on income brackets doesn't need ML. Use if-else statements.

Data is scarce: Training a medical diagnosis model with 50 patient records will fail. ML needs volume.

Interpretability is critical: Banking regulators require explainable decisions. Complex models create "black boxes" that can't justify predictions.

Cost exceeds benefit: ML infrastructure (data collection, training, deployment, monitoring) has overhead. Sometimes Excel suffices.

Rules are fixed and known: Validating email format follows clear patterns (regex). No learning needed.

Real-time requirements are strict: If predictions must happen in microseconds and consistency is critical, rule-based systems often win.

Use the simplest approach that solves your problem. ML is powerful but not always necessary.

ML in Practice: Real-World Examples

Email Spam Detection

Traditional approach: Create rules (if email contains "free money" → spam) Problem: Spammers adapt; rules become outdated daily

ML approach: Train model on labeled emails (spam/not spam) Advantage: Model learns evolving patterns; retrains automatically

Product Recommendations

Traditional approach: "Customers who bought X also bought Y" (simple rules) Problem: Doesn't account for individual preferences, context, trends

ML approach: Learn from millions of user interactions Advantage: Personalized to each user; improves over time

Medical Diagnosis

Traditional approach: Expert systems with encoded medical knowledge Problem: Can't capture all edge cases; requires manual updates

ML approach: Learn from thousands of patient records and outcomes Advantage: Finds subtle patterns doctors might miss; improves with more data

Credit Scoring

Traditional approach: Fixed formula (income × 0.4 + assets × 0.3 - debt × 0.3) Problem: Misses non-linear relationships; treats everyone equally

ML approach: Learn complex patterns from historical loan performance Advantage: More accurate risk assessment; adapts to economic changes

Common Misconceptions

"More data always means better models"

Reality: Quality matters more than quantity.

Ten thousand labeled examples from representative samples outperform one million biased, mislabeled examples. More data helps only if it's relevant, accurate, and diverse.

"Complex models always beat simple ones"

Reality: Simple models often win in practice.

Linear regression frequently outperforms neural networks when you have limited data, interpretability requirements, or well-understood relationships. Start simple, add complexity only if needed.

"ML can find patterns in any data"

Reality: Models learn only what exists in training data.

If your training data excludes important scenarios (rural customers, extreme weather, economic recessions), models fail when those scenarios appear in production. No algorithm fixes bad data.

"ML replaces domain expertise"

Reality: Domain knowledge guides every step.

Experts choose relevant features, interpret results, identify data issues, and decide when predictions make sense. Algorithms are tools; humans provide context.

"ML is objective and bias-free"

Reality: Models inherit biases from training data.

If historical hiring data shows bias against certain groups, ML models trained on that data perpetuate the bias. Fairness requires careful data curation and model auditing.

Prerequisites for Learning ML

You don't need a PhD, but certain foundations make learning easier:

Math (refresher sufficient):

  • Linear algebra: Vectors, matrices, dot products
  • Calculus: Derivatives, gradients (conceptual understanding)
  • Probability: Distributions, conditional probability, Bayes' theorem
  • Statistics: Mean, variance, hypothesis testing, correlation

Programming (intermediate):

  • Python: Comfortable with functions, loops, data structures
  • NumPy: Array operations, indexing, broadcasting
  • Pandas: Load data, filter, transform, aggregate

Data skills:

  • Read CSV/JSON files
  • Handle missing values
  • Create visualizations
  • Understand databases (SQL basics)

Best Practices

Start with the end in mind: Define success metrics before building models. "Reduce fraud losses by 20%" beats "build accurate fraud detector."

Embrace simplicity: Simple models are easier to debug, interpret, deploy, and maintain. Complexity should be justified by performance gains.

Question everything: Does this data make sense? Why did the model make this prediction? What happens if this assumption is wrong? Skepticism prevents costly mistakes.

Document decisions: Record why you chose features, models, and hyperparameters. Future you (or teammates) will need to understand choices made months ago.

Think beyond accuracy: Consider latency, interpretability, fairness, maintenance cost, and business impact. The "most accurate" model isn't always the right choice.

Test on real-world conditions: Models that work in lab settings sometimes fail in production. Test with realistic data, edge cases, and adversarial inputs.

Quick Reference: ML Fundamentals

Concept Definition Example
Machine Learning Learning patterns from data without explicit programming Spam detection learns from labeled emails
Features Input variables used for predictions Square footage, bedrooms, location
Labels Target variable being predicted House price, spam/not spam
Model Mathematical representation mapping features to labels Equation, decision tree, neural network
Training Process of model learning patterns from data Adjusting parameters to minimize errors
Prediction Using trained model on new data Estimate price for unseen house
Traditional Programming Rules + Data → Output Calculate tax from income using formula
Machine Learning Data + Output → Rules (Model) Learn what makes email spam from examples

Summary & Next Steps

Key accomplishments: You now understand what machine learning is and how it differs from traditional programming, know when ML makes sense and when simpler approaches work better, understand core ML terminology (features, labels, models, training, prediction), and recognize common misconceptions about ML capabilities and limitations.

Critical insights:

  • ML learns patterns, not rules: You provide examples; algorithms discover relationships
  • Not every problem needs ML: Use the simplest approach that works
  • Data quality matters most: Better data beats better algorithms
  • Domain expertise is essential: ML is a tool that augments human knowledge

External resources:

Remember: Machine learning is a tool, not magic. Master the fundamentals, question assumptions, and prioritize data quality. With these foundations, you'll build models that work reliably in the real world.