Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Added an example to the sklearn.feature_extraction.image.PatchExtractor #12202

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 32 additions & 20 deletions sklearn/feature_extraction/image.py
Expand Up @@ -501,30 +501,42 @@ def transform(self, X):

Examples
--------

>>> import scipy as sp
>>> from sklearn.feature_extraction.image import PatchExtractor
>>> X = np.random.randint(10, size=(2, 2, 2))
>>> X
array([[[5, 0],
[9, 6]],

[[2, 0],
[5, 2]]])

>>> pe = PatchExtractor(patch_size=(2, 1))
>>> pe.fit(X)
>>> pe.transform(X)
array([[[ 5.],
[ 9.]],
>>> X = sp.misc.face()
>>> X.shape
(768, 1024, 3)

[[ 0.],
[ 6.]],
>>> X[0]
array([[121, 112, 131],
[138, 129, 148],
[153, 144, 165],
...,
[119, 126, 74],
[131, 136, 82],
[139, 144, 90]], dtype=uint8)

[[ 2.],
[ 5.]],

[[ 0.],
[ 2.]]])
>>> pe = PatchExtractor(patch_size=(1024, 2), random_state=1234)
>>> pe.fit(X)
>>> X_transform = pe.transform(X)
>>> X_transform[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just show the shape of X_transform? And maybe use a different patch size? this seems strange.

array([[ 121., 112.],
[ 138., 129.],
[ 153., 144.],
...,
[ 119., 126.],
[ 131., 136.],
[ 139., 144.]])

>>> X_transform[1]
array([[ 112., 131.],
[ 129., 148.],
[ 144., 165.],
...,
[ 126., 74.],
[ 136., 82.],
[ 144., 90.]])
"""
self.random_state = check_random_state(self.random_state)
n_images, i_h, i_w = X.shape[:3]
Expand Down