Implementation:Scikit learn Scikit learn FetchOlivettiFaces
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Computer Vision |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for fetching and loading the Olivetti faces dataset for face recognition tasks, provided by scikit-learn.
Description
The fetch_olivetti_faces function downloads and caches the modified Olivetti faces dataset. The dataset contains 400 grayscale face images of 40 subjects (10 images per subject), each of size 64x64 pixels. The images were taken at AT&T Laboratories Cambridge and are provided in MATLAB format from Sam Roweis's personal web page.
Usage
Use this function when you need a face recognition dataset for evaluating classification, clustering, or dimensionality reduction algorithms. It is commonly used in tutorials for PCA, NMF, and face recognition examples.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/datasets/_olivetti_faces.py
Signature
@validate_params(...)
def fetch_olivetti_faces(
*,
data_home=None,
shuffle=False,
random_state=0,
download_if_missing=True,
return_X_y=False,
n_retries=3,
delay=1.0,
):
Import
from sklearn.datasets import fetch_olivetti_faces
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| data_home | str, PathLike or None | No | Custom directory for caching (default None) |
| shuffle | bool | No | Whether to shuffle the dataset (default False) |
| random_state | int, RandomState or None | No | Random seed for shuffling (default 0) |
| download_if_missing | bool | No | If True, download data if not cached (default True) |
| return_X_y | bool | No | If True, return (data, target) instead of Bunch (default False) |
| n_retries | int | No | Number of download retries (default 3) |
| delay | float | No | Delay between retries in seconds (default 1.0) |
Outputs
| Name | Type | Description |
|---|---|---|
| dataset | Bunch | Dictionary-like object with data (400x4096), target, images (400x64x64), and DESCR |
| (X, y) | tuple of ndarray | Feature matrix and target array when return_X_y=True |
Usage Examples
Basic Usage
from sklearn.datasets import fetch_olivetti_faces
faces = fetch_olivetti_faces()
print(faces.data.shape) # (400, 4096)
print(faces.images.shape) # (400, 64, 64)
print(faces.target.shape) # (400,)
X, y = fetch_olivetti_faces(return_X_y=True, shuffle=True, random_state=42)