Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

datasets
sklearn
communitycreator

What is the datasets.load_sample_images() method in Sklearn?

AKASH BAJWA

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In Python, the Scikit-learn library (sklearn) is used for machine learning. This library contains different algorithms for classification, SVM, random forests, regression, k-neighbours, etc.

Classification is helpful to create a model which separates your data into multiple classes for prediction based on the dataset.

The Scikit-learn library contains a pair of sample images (china and flower) that are helpful to test different pipelines and algorithms on two-dimensional data.

  • The load_sample_images() method is used to load sample images for performing manipulations.
  • The load_sample_image(image_name) is used to load an array containing single image.

Syntax


sklearn.datasets.load_sample_images()

Parameters

It does not take anything as an argument.

Return value

The function returns a dictionary-like object with three attributes.

  1. images: two sample images, i.e. china and flower.
  2. filenames: a list of the names of the images.
  3. DESCR: a short description of the dataset.

Code

In the following code snippet, on line 3, we loaded two sample images from sklearn datasets. It then prints the shape (427, 640, 3) of sample images in the output.

# Demo code load_sample_images()
from sklearn.datasets import load_sample_images
mydataset = load_sample_images()
print("Dataset length:", len(mydataset.images))
first_img_data = mydataset.images[0]
print("1st image Shape:",first_img_data.shape)
second_img_data = mydataset.images[1]
print("2nd image Shape:", second_img_data.shape)

RELATED TAGS

datasets
sklearn
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring