Skip to the page
Tecyfy

Machine Learning vs. Deep Learning: What’s the Difference?

Deep learning is machine learning with many-layered neural networks. How the two differ, when each fits, and a short program of each that you can run.

Tecyfy · Published · Updated · 7 min read

Introduction

Machine learningMachine LearningA subset of artificial intelligence that enables computers to learn and make decisions from data without being explicitly programmed. is software that learns a task from examples instead of following rules a person wrote. Deep learning is one kind of machine learning: the kind that uses neural networksNeural NetworkA computing system inspired by biological neural networks that learn patterns from data with many layers. So the question is not which one is better, but when the extra layers are worth what they cost. This article explains the difference, with a short program of each kind that you can run.

What machine learning is

A machine learning model finds the pattern that links inputs to an answer, from examples where the answer is known. Classic methods such as linear regression, decision trees, random forests and gradient-boosted trees work on tables: one row per example, one column per feature.

They depend on the features you give them. A model predicting house prices learns nothing about location unless someone adds a column for it. Choosing and preparing those columns, feature engineeringData PreprocessingThe process of cleaning, transforming, and organizing raw data before analysis., is a large part of the work, and our article on feature engineering covers it.

Example: predicting disease progression

This uses a dataset that ships with scikit-learn: 442 diabetes patients, 10 measurements each, and how far the disease had progressed a year later. It trains two classic models and measures how far off each one is on patients it has not seen.

from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import HistGradientBoostingRegressor
from sklearn.metrics import mean_absolute_error

# 442 patients: age, sex, BMI, blood pressure and 6 blood measurements.
# The target is how far the disease progressed one year later.
X, y = load_diabetes(return_X_y=True, as_frame=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

for model in [LinearRegression(), HistGradientBoostingRegressor(random_state=42)]:
    model.fit(X_train, y_train)
    error = mean_absolute_error(y_test, model.predict(X_test))
    print(f"{type(model).__name__}: off by {error:.1f} on average")

When we ran it, the plain linear model was off by about 43 points on average and the gradient-boosted trees by about 45. With 442 rows, the simplest model did as well as the boosted trees, trains in milliseconds and is easy to explain: each feature gets one weight.

What deep learning is

A deep learning model is a neural networkNeural NetworkA computing system inspired by biological neural networks that learn patterns from data with many layers. Each layer turns its input into a slightly more useful form, and training adjusts millions of weightsWeightA trainable parameter in a neural network that scales input values and is updated during training. together with backpropagationBackpropagationAn algorithm for computing gradients in deep networks via the chain rule. and gradient descentGradient DescentThe way a neural network learns. Measure how wrong it is, work out which way each weight should move to be less wrong, take a small step that way, repeat.. The difference that matters: the network learns its own features from raw input. Shown pixels, its first layers learn edges and corners, and later layers combine them into shapes and objects. Nobody writes a "has a collar" column.

That is why deep learning took over images, sound and text, where the raw input is too large and too unstructured to describe in hand-made columns.

Example: recognising clothes in photos

This trains a small convolutional network with Keras on Fashion-MNIST, 70,000 photos of clothing in 10 classes, downloaded by Keras the first time it runs.

import keras
from keras import layers

# 70,000 small photos of clothing in 10 classes: shirts, trainers, bags and so on
(x_train, y_train), (x_test, y_test) = keras.datasets.fashion_mnist.load_data()
x_train = x_train[..., None]  # add a channel: 28 x 28 x 1
x_test = x_test[..., None]

model = keras.Sequential([
    keras.Input(shape=(28, 28, 1)),
    layers.Rescaling(1 / 255),                    # pixels from 0-255 to 0-1
    layers.Conv2D(32, 3, activation="relu"),      # learns small patterns: edges, corners
    layers.MaxPooling2D(),
    layers.Conv2D(64, 3, activation="relu"),      # combines them into larger shapes
    layers.MaxPooling2D(),
    layers.Flatten(),
    layers.Dense(128, activation="relu"),
    layers.Dense(10, activation="softmax"),       # one probability per class
])

model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
model.fit(x_train, y_train, epochs=5, batch_size=64, validation_split=0.1)

loss, accuracy = model.evaluate(x_test, y_test)
print(f"Test accuracy: {accuracy:.1%}")

After 5 passes over the data, which take a minute or two on a laptop, it labels about 90% of the test photos correctly. The network was never told what a sleeve or a sole looks like.

The differences side by side

Classic machine learningDeep learning
FeaturesChosen and prepared by peopleLearned from raw input
Best atTables: rows and columnsImages, sound, text
Data neededHundreds to millions of rowsUsually many thousands of examples or more
HardwareA laptop CPUGPUs for anything large
Explaining a resultOften direct (weights, tree splits)Hard; needs special tools

Two cautions on that table. Deep learning does not remove feature work completely: someone still decides what goes in and cleans it. And it does not need huge data every time: fine-tuningFine-TuningTraining an existing model a little further on your own examples so it picks up a task, a format or a style. Often a good prompt does the job first. a network someone else trained can work with far less data of your own.

Which to use

Start with classic machine learning when your data is a table, which covers most business data: sales, transactions, sensor readings, customer records. A 2022 study across 45 tabular datasets found that tree-based models such as gradient boosting still beat deep learning on medium-sized tables (around 10,000 rows), while being faster to train.

Use deep learning when the input is images, audio, video or free text, or when you can build on a pretrained model. For text today that usually means calling a language model rather than training your own; our concepts library explains how those work.

Tecyfy Takeaway

Deep learning is machine learning with deep neural networks, and its edge is learning features from raw data. On tables, start with a classic model: it is quicker, cheaper and easier to explain, and it often wins. Reach for deep learning when the data is images, sound or text, and prefer a pretrained model to training one from scratch.

Questions

What is the difference between machine learning and deep learning?
Deep learning is one kind of machine learning: the kind that uses neural networks with many layers. Classic machine learning depends on features people choose; deep learning learns its own features from raw input such as pixels, sound or text.
Is deep learning better than machine learning?
Usually not on medium-sized tables (around 10,000 rows). A 2022 study across 45 tabular datasets found tree-based models such as gradient boosting still beat deep learning on medium-sized tables and train faster. Deep learning wins on images, audio, video and free text.
When should I use deep learning?
When the input is images, audio, video or free text, or when you can build on a pretrained model. For business data in rows and columns, start with a classic model: it is quicker, cheaper and easier to explain.
Does deep learning need a lot of data?
Training from scratch usually needs many thousands of examples or more, but fine-tuning a network someone else trained can work with far less data of your own.