Lesson 50

Computer Vision and Spatial Economic Measurement

Big question

How does a model transform pixels into useful local patterns without being told the exact edge or texture to search for?

Lesson progress

Complete checkpoints as you learn

0% complete0 checkpoint streak
Progress tracking available after sign-in. Sign in to save your work.
Big question
Concept
Activity
Quiz

Learning objectives

  • Represent images as arrays.
  • Explain convolution, stride, padding, and channels.
  • Describe CNNs, augmentation, and transfer learning.
  • Evaluate errors, bias, and privacy.
  • Prerequisites: Chapters 8 and 30.
  • Key terms: pixel, channel, convolution, kernel, padding, transfer learning.

Simple explanation

A grayscale image is a two-dimensional array; a colour image commonly adds a channel axis. Pixel scale, channel order, and spatial dimensions must be documented. Resizing changes information, and normalization affects optimization. Plotting a few images and labels is a basic data audit that can reveal corrupted files, wrong orientation, or class leakage.

Key terms

Represent images as arrays
A core idea in Chapter 50 that students apply carefully in economic analysis.
convolution, stride, padding, and channels
A core idea in Chapter 50 that students apply carefully in economic analysis.
CNNs, augmentation, and transfer learning
A core idea in Chapter 50 that students apply carefully in economic analysis.
Evaluate errors, bias, and privacy
A core idea in Chapter 50 that students apply carefully in economic analysis.
Prerequisites: Chapters 8 and 30
A core idea in Chapter 50 that students apply carefully in economic analysis.
Key terms: pixel, channel, convolution, kernel, padding, transfer learning
A core idea in Chapter 50 that students apply carefully in economic analysis.

Analytical workflow

Question+data+assumptions+transparentPython>evidenceQuestion + data + assumptions + transparent Python -> evidence

Interpret the expression in words and units before using it in a claim.

Example

Interpretation. The vertical edge creates a strong response where intensity changes across columns.

Prerequisites

  • Complete the preceding course chapters or review their summaries as needed.

Full theory and examples

50.2

Images are structured tensors

A grayscale image is a two-dimensional array; a colour image commonly adds a channel axis. Pixel scale, channel order, and spatial dimensions must be documented. Resizing changes information, and normalization affects optimization. Plotting a few images and labels is a basic data audit that can reveal corrupted files, wrong orientation, or class leakage.

50.3

Convolution searches locally with shared weights

A convolution slides a small kernel across the image and computes local weighted sums. Weight sharing lets one pattern detector operate in many positions, reducing parameters relative to a fully connected layer. Stride controls movement; padding controls border treatment; multiple filters produce feature maps. Deeper layers combine edges and textures into task-specific representations.

50.4

Transfer learning is borrowed representation, not borrowed truth

A pretrained network can supply useful visual features when the new dataset is small. Fine-tuning adapts some or all weights. Performance depends on similarity between source and target images, class balance, image quality, and deployment conditions. Augmentation should represent plausible variation rather than alter the label. Vision systems can encode demographic bias and expose sensitive images, so privacy and subgroup evaluation are essential.

50.5

Core equations

Discrete convolution

A kernel K aggregates a local neighbourhood of image X into an output feature Y.

50.6

Python demonstrations

50.6.1

Demonstration 31.1: Apply a simple edge kernel

Verified output

Interpretation. The vertical edge creates a strong response where intensity changes across columns.

50.6.2

Demonstration 31.2: Inspect a tensor shape

Verified output

Interpretation. Padding preserves height and width, while eight learned filters replace the three input channels.

50.7

Visual evidence

50.8

Reference table

Why This Matters

Computer vision combines spatial structure with learned representations, but deployment validity depends on the image-generating context.

Common Mistake

Applying augmentation that changes the label, such as flipping a directional medical image without checking domain meaning.

Ceteris LAB Tip

Inspect misclassified images by subgroup and acquisition source, not only the aggregate accuracy.

R-to-Python / Source Bridge

The chapter adapts IntroAI session 8 on convolution, padding, channels, augmentation, CNNs, and transfer learning, using new original diagrams instead of source screenshots (Sharifi-Zarchi and contributors 2026).

Table 31. Chapter reference.
ChoiceEffectQuestion
kernel sizelocal receptive fieldWhat pattern scale matters?
stridedownsamplingWill detail be lost?
paddingoutput size/border handlingHow should edges be treated?
augmentationsynthetic variationDoes it preserve the label?
pretraininginitial representationIs the source domain relevant?

Visual evidence

Figure 58. A small convolution kernel highlights vertical edges in an image.
Figure 58. A small convolution kernel highlights vertical edges in an image.
Figure 59. Different convolution filters extract different local image structures.
Figure 59. Different convolution filters extract different local image structures.

Additional Python demonstrations

Live Python

Source demonstration 2

Source demonstration 2

Stdout

Run Python to see results here.

Status / stderr

Ready to run Python in your browser.

Line-by-line guide

  1. Line 1Load a Python library needed for data work or regression.
  2. Line 3Create or update a Python object used in the analysis.
  3. Line 4Create or update a Python object used in the analysis.
  4. Line 5Create or update a Python object used in the analysis.
  5. Line 6Create or update a Python object used in the analysis.
  6. Line 7Create or update a Python object used in the analysis.
  7. Line 8Create or update a Python object used in the analysis.
  8. Line 9Display a result so students can inspect the output.
  9. Line 10Display a result so students can inspect the output.

Verified source output

3.0 (8, 8)
(16, 8, 64, 64)

Interpretation. The vertical edge creates a strong response where intensity changes across columns.

Interpretation. Padding preserves height and width, while eight learned filters replace the three input channels.

Guided practice

  1. 1Re-run Demonstration 31.1 and change one input while keeping the analytical question fixed.
  2. 2Explain in two sentences how the output supports, or fails to support, the chapter opening question.
  3. 3Add one validation check that would prevent a plausible error.

Exercises

  1. 1Convolve an image with blur and edge kernels.
  2. 2Compare output shapes under two padding choices.
  3. 3Design three label-preserving augmentations.
  4. 4Write a transfer-learning evaluation plan.

Source and downloads

Chapter 50 of Fundamentals of Python for Financial Econometrics by Mohammad Safavi, Ph.D.. The lesson is an original Ceteris Lab web adaptation of the supplied publication package.

Live Python

Computer Vision and Spatial Economic Measurement: live Python

Computer Vision and Spatial Economic Measurement: live Python

Stdout

Run Python to see results here.

Status / stderr

Ready to run Python in your browser.

Line-by-line guide

  1. Line 1Load a Python library needed for data work or regression.
  2. Line 3Create or update a Python object used in the analysis.
  3. Line 4Create or update a Python object used in the analysis.
  4. Line 5Create or update a Python object used in the analysis.
  5. Line 6Create or update a Python object used in the analysis.
  6. Line 7Create or update a Python object used in the analysis.
  7. Line 8Create or update a Python object used in the analysis.
  8. Line 9Display a result so students can inspect the output.

Python walkthrough

  1. 1`import numpy as np`: Loads a package or function used by the analysis.
  2. 2`image = np.zeros((8, 8))`: Creates or updates a named object used by later steps.
  3. 3`image[:, 4:] = 1`: Creates or updates a named object used by later steps.
  4. 4`kernel = np.array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]])`: Creates or updates a named object used by later steps.
  5. 5`padded = np.pad(image, 1, mode="symmetric")`: Creates or updates a named object used by later steps.
  6. 6`windows = np.lib.stride_tricks.sliding_window_view(padded, (3, 3))`: Creates or updates a named object used by later steps.
  7. 7`feature = np.einsum("ijkl,kl->ij", windows, kernel)`: Creates or updates a named object used by later steps.
  8. 8`print(float(np.abs(feature).max()), feature.shape)`: Displays a result so it can be checked and interpreted.

Live notebook

Run this lesson as a notebook

Open an editable notebook cell-by-cell, run Python in the browser, and download the `.ipynb` file for later.

Related dataset

Ceteris Lab teaching sample

Estimated time

25 to 40 min

Packages

pandas, numpy

Expected output

Printed Python results that can be compared with the lesson explanation.

Learning goals

  • Load and inspect Ceteris Lab teaching sample.
  • Run the Python cells connected to Computer Vision and Spatial Economic Measurement.
  • Interpret the output using Represent images as arrays and convolution, stride, padding, and channels.

Common errors

  • File not found: check that wage_sample.csv is installed or use the course data folder.
  • Package import error: use the browser notebook first, then download for local Jupyter if your local packages differ.
  • Column name error: compare your variable names with the dataset variables listed for this notebook.

Dataset path helper

import pandas as pd

df = pd.read_csv("/data/wage_sample.csv")
df.head()

Interactive activity

Chapter 50 interactive

Model governance check

Evidence strength: 55%
Training fluencyVerified generalization

What is the safest basis for evaluating an ML or AI result?

Immediate feedback

Choose a decision, then test how the claim changes as evidence becomes stronger or weaker.

Try it yourself

Write one plain-English sentence explaining the main idea from this lesson.

Common mistakes

Check these before you move on.

Return to the lesson assumptions, units, diagnostics, and source evidence to replace this shortcut with a defensible interpretation.

Quick quiz

Which statement best answers the Chapter 50 opening question: How does a model transform pixels into useful local patterns without being told the exact edge or texture to search for?

Quick quiz

Which practice should be avoided when applying Computer Vision and Spatial Economic Measurement?

Quick quiz

What is the most defensible way to interpret the Python demonstration?

Quick quiz

Why does Chapter 50 matter in an applied econometrics workflow?

Key takeaway

Images are tensors with spatial and channel structure. Convolution uses local shared filters. Transfer learning and augmentation require domain-valid assumptions.