Download ((better)): Fetch_olivetti_faces
from sklearn.datasets import fetch_olivetti_faces # Download and cache the Olivetti faces dataset # shuffle=True randomizes the order of the dataset # data_home specifies a custom download directory (optional) olivetti_data = fetch_olivetti_faces(shuffle=False, random_state=42) Use code with caution.
# Print structural attributes print(f"Flattened data shape: {olivetti_data.data.shape}") print(f"Spatial image shape: {olivetti_data.images.shape}") print(f"Target labels shape: {olivetti_data.target.shape}") Use code with caution. 🖼️ Visualizing the Dataset
from sklearn.model_selection import train_test_split # Define feature matrix and target vector X = olivetti_data.data y = olivetti_data.target # Perform a stratified 80/20 train/test split X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.20, stratify=y, random_state=42 ) print(f"Training features: {X_train.shape}") print(f"Testing features: {X_test.shape}") Use code with caution. 💡 Common Use Cases download fetch_olivetti_faces
To confirm successful download, use Matplotlib to visualize a grid of faces showing different subjects or variations of a single individual.
Lighting conditions, facial expressions (open/closed eyes, smiling/not smiling), and facial details (glasses/no glasses). 🚀 Downloading the Dataset via Scikit-Learn from sklearn
: A 1D numpy array of shape (400,) . It contains integers from 0 to 39 corresponding to the identity label of the subject.
Because each subject has exactly 10 images, it is vital to use stratified splitting. This ensures that every individual is represented equally in both sets. 💡 Common Use Cases To confirm successful download,
: A 2D numpy array of shape (400, 4096) . Each row represents a flattened pixel image.