1. Home
  2. Explore
  3. Computer Science
  4. Machine Learning vs Deep Learning

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Machine Learning vs Deep Learning

Machine Learning and Deep Learning: The Complete Beginner's Guide

📜 What Is Artificial Intelligence?

Artificial intelligence (AI) emerged in the 1950s and 1960s with the goal of simulating human decisions and judgment. Early systems, like the chatbot ELIZA, attempted to mimic a therapist by carrying on a text-based conversation. Despite the hype, AI is fundamentally “just code and data”—there is no magic. A modern AI model (e.g., from BigScience) can explain itself: “AI is just a computer program that processes data and makes decisions.”

To understand how machines learn, start with how humans make simple rules and then progress through expert systems, machine learning, and deep learning.


📊 Simple Baseline: Predicting Tomorrow’s Temperature

A naive rule for predicting tomorrow’s maximum temperature (TmaxT_{\text{max}}Tmax​) is to assume it will be the same as today’s:

y^t+1=yt\hat{y}_{t+1} = y_ty^​t+1​=yt​

Using a Python library (pandas) to load weather observations, this rule is implemented by setting the prediction column equal to the current day’s T-Max value.

Measuring Error

To evaluate predictions, compute the absolute error for each day:

error=∣yactual−y^∣\text{error} = |y_{\text{actual}} - \hat{y}|error=∣yactual​−y^​∣

Then take the mean absolute error (MAE) across all days:

MAE=1n∑i=1n∣yi−y^i∣\text{MAE} = \frac{1}{n}\sum_{i=1}^{n} |y_i - \hat{y}_i|MAE=n1​∑i=1n​∣yi​−y^​i​∣

For the sample data (Nov 20–26, 2022), this simple rule gives an MAE of 3.28°F.


🧩 Expert Systems (1980s AI Wave)

Instead of a single rule, expert systems use human‑written rules to improve predictions. For example:

  • Tomorrow’s temperature = average of the past 5 days

  • If today is more than 5°F warmer than yesterday, add 2°F to tomorrow’s prediction

A computer evaluates these rules automatically. Applying such rules to the same weather data reduces the MAE to 3.05°F. Expert systems require humans to manually create all the rules—a tedious process when hundreds or thousands of rules are needed.


🧠 Machine Learning (1990s–2000s)

Machine learning automates rule generation. The algorithm learns the rules from data instead of requiring a human to write them. This is called supervised machine learning: give the algorithm some data and something to predict, and it learns the mapping.

Decision Trees

A decision tree is a simple machine learning model. For example, deciding whether to let someone into an R‑rated movie checks age and money conditions:

  • If under 17 → check if with an adult → yes: allow, no: deny

  • If 17 or older → check if they have 20 → yes: allow, no: deny

The algorithm automatically learns the entire tree structure and its thresholds from labeled data.

Linear Regression

Linear regression learns a linear relationship between predictors (XXX) and a target (yyy). The equation is:

y=m⋅x+by = m \cdot x + by=m⋅x+b

where mmm is the slope (or weight) and bbb is the y-intercept (or bias). The model finds mmm and bbb automatically (e.g., using an equation or gradient descent).

Visualizing a Linear Relationship

Plotting today’s TmaxT_{\text{max}}Tmax​ against tomorrow’s TmaxT_{\text{max}}Tmax​ shows a roughly linear shape—a line can be drawn through the center of the points.

Training on Weather Data (1970–2022)

Using scikit-learn:

from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(X_train, y_train)   # X = today's Tmax, y = tomorrow's Tmax

The learned parameters:

  • lr.coef_ (slope mmm): 0.81

  • lr.intercept_ (bias bbb): 12.0

So the prediction is: y^=0.81⋅x+12.0\hat{y} = 0.81 \cdot x + 12.0y^​=0.81⋅x+12.0.

Evaluating on Unseen Data

To avoid “open‑book test” cheating, evaluate the model on data it has never seen (the test set). This ensures the rules are general. The MAE on test data (after Nov 20, 2022) drops to 2.92°F—better than the expert system’s 3.05°F.

Using Multiple Predictors

Linear regression can use more than one predictor:

y=m1x1+m2x2+…+by = m_1 x_1 + m_2 x_2 + \ldots + by=m1​x1​+m2​x2​+…+b

Add the Rain column as a second predictor. The new coefficients:

  • coef_ for TmaxT_{\text{max}}Tmax​: 0.81

  • coef_ for rain: −1.53 (a negative value means rain today suggests cooler tomorrow)

  • intercept_: 12.0

With both predictors, MAE improves to 2.89°F.

Feature Engineering

The best ways to reduce error are more data or better features. Feature engineering creates new predictive columns from existing data without gathering new observations. Examples:

  • Rolling average of TmaxT_{\text{max}}Tmax​ over the past 7 days

  • Ratio of today’s TmaxT_{\text{max}}Tmax​ to that rolling average

After adding these two columns, training the model on TmaxT_{\text{max}}Tmax​, rain, average temp, and temp ratio yields an MAE of 2.69°F—a clear improvement.


🤖 Deep Learning (Neural Networks)

Deep learning (also called neural networks) goes one step further: it automatically creates both features and rules. You do not need to perform feature engineering; the hidden layers of the network generate new features internally.

How a Neural Network Works

A neural network consists of multiple hidden layers. Data flows through these layers, and each layer applies a linear transformation followed by a non‑linear activation function.

Basic building block (a single neuron):

z=W⋅x+bz = W \cdot x + bz=W⋅x+b
a=ReLU(z)a = \text{ReLU}(z)a=ReLU(z)

where:

  • WWW = weights (like slopes mmm)

  • bbb = bias (like intercept)

  • ReLU\text{ReLU}ReLU = a non‑linear activation function (ReLU outputs zzz if z>0z>0z>0, else 0)

A two‑layer network repeats the process:

  1. First hidden layer: a1=ReLU(W1x+b1)a_1 = \text{ReLU}(W_1 x + b_1)a1​=ReLU(W1​x+b1​)

  2. Second hidden layer: a2=ReLU(W2a1+b2)a_2 = \text{ReLU}(W_2 a_1 + b_2)a2​=ReLU(W2​a1​+b2​)

  3. Output layer (no activation): y^=W3a2+b3\hat{y} = W_3 a_2 + b_3y^​=W3​a2​+b3​

The network learns all weights and biases through gradient descent.

Practical Implementation (PyTorch Example)

Using the same weather data, a small network is configured:

  • Input layer: number of predictors (columns)

  • Hidden layer 1: 20 features

  • Hidden layer 2: 10 features

  • Output layer: 1 prediction

The network processes the data multiple times (epochs). For each piece of data:

  • It makes a prediction (forward pass)

  • It calculates the error

  • It adjusts the weights and biases proportionally to how incorrect the prediction was (backpropagation)

After training, the MAE on the test set is 2.88°F—slightly worse than the best feature‑engineered linear regression (2.69°F). This is expected because deep learning needs more data and careful tuning to outperform a well‑engineered linear model on small structured datasets.


⚖️ Machine Learning vs. Deep Learning: When to Use Which

Aspect

Machine Learning

Deep Learning

Feature engineering

Often required to achieve low error

Automatically generates features

Data type

Excels on tabular/structured data (Excel‑like tables)

Excels on unstructured data (text, images, audio)

Data size

Can work well with smaller datasets

Usually needs large amounts of data

Training time & tuning

Relatively fast, less hyperparameter tuning

Needs more data, time, and parameter optimization (learning rate, layer sizes)

Interpretability

High (e.g., linear regression coefficients directly show feature influence)

Low (“black box”); hard to explain why a specific prediction was made

Performance ceiling

Plateaus with feature engineering; better models may require more data or deep learning

Can achieve state‑of‑the‑art results on complex tasks (e.g., GPT, stable diffusion)

Practical Advice

  • Start with machine learning for tabular data (regression, classification) because it is simpler, faster, and interpretable.

  • Use deep learning when the data is unstructured (images, free text, audio) or when you have massive datasets and the problem requires learning complex structures.

  • Try both when in doubt. As long as you use a reliable error metric (like MAE), you can objectively compare the two approaches on your specific data.

  • Interpretability is an active research area. For high‑stakes decisions (e.g., medical diagnosis), machine learning’s transparency may be preferred.


Key Takeaway: Machine learning automates rule creation; deep learning automates both rule creation and feature creation. The best method depends on your data type, size, and need for interpretability.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent