What is datasets.load_sample_image() in scikit-learn?
In a Python programming language, scikit-learn is a library for machine learning. This library contains different algorithms that include supervised learning and unsupervised learning techniques. For learning purposes, Sklean.dataset contains multiple build-in datasets like Toy datasets, Real-world datasets, etc.
The scikit-learn library contains a pair of sample images that are helpful to test different pipelines and algorithms on two-dimensional data.
load_sample_image(image_name)is used to load an array containing a single image.- The
load_sample_images()method is used to load sample images to perform manipulations.
Syntax
sklearn.datasets.load_sample_image(image_name)
Parameters
image_name: It takes a string of an image name with format type jpg.
This string can either be
china.jpgorflower.jpgbecauseload_sample_images()has only a pair of images.
Return value
A Numpy 3D array with dimensions (height, width, and color) is returned.
Example
This code snippet demonstrates the use of the _load_sample_image()_ method which helps extract sample images from the sklearn.datasets module.
In lines 4 and 5, we extract china.jpg and flower.jpg images respectively and print their dimensions and datatype.
# Demo codefrom sklearn.datasets import load_sample_image# loading 1st image named china.jpgimg1 = load_sample_image('china.jpg')# loading 2nd image named flower.jpgimg2 = load_sample_image('flower.jpg')# for china.jpg imageprint("1st image datatype: ", img1.dtype)print("1st image dimensions: ", img1.shape)# for flower.jpg imageprint("2nd image datatype: ", img2.dtype)print("2nd image dimensions: ", img2.shape)