From c8bc3acba1fdfc05fc874ac16eb220a53a40e2ce Mon Sep 17 00:00:00 2001 From: Parul Date: Sat, 29 Sep 2018 12:05:01 -0400 Subject: [PATCH 1/5] Added an example to the sklearn.feature_extraction.image.PatchExtractor class --- sklearn/feature_extraction/image.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index b6e68537c091c..88a1314ecf106 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -499,6 +499,32 @@ def transform(self, X): `n_patches` is either `n_samples * max_patches` or the total number of patches that can be extracted. + Examples + -------- + + >>> 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.]], + + [[ 0.], + [ 6.]], + + [[ 2.], + [ 5.]], + + [[ 0.], + [ 2.]]]) """ self.random_state = check_random_state(self.random_state) n_images, i_h, i_w = X.shape[:3] From 478d403d58f5f9b23e91b7d5ab4d6286e8f48f52 Mon Sep 17 00:00:00 2001 From: Parul Date: Sat, 29 Sep 2018 13:52:23 -0400 Subject: [PATCH 2/5] Used built-in image and intialized class with random_state --- sklearn/feature_extraction/image.py | 56 +++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 88a1314ecf106..9d1a70ff9427c 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -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)) + + >>> X = sp.misc.face() + >>> X.shape + (768, 1024, 3) + + >>> X[0] + array([[121, 112, 131], + [138, 129, 148], + [153, 144, 165], + ..., + [119, 126, 74], + [131, 136, 82], + [139, 144, 90]], dtype=uint8) + + >>> pe = PatchExtractor(patch_size=(1024, 2), random_state=1234) >>> pe.fit(X) - >>> pe.transform(X) - array([[[ 5.], - [ 9.]], - - [[ 0.], - [ 6.]], - - [[ 2.], - [ 5.]], - - [[ 0.], - [ 2.]]]) + >>> X_transform = pe.transform(X) + >>> X_transform[0] + 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] From edb8e0035cd93b087b1884c50a69d29945eff3e3 Mon Sep 17 00:00:00 2001 From: Parul Date: Sat, 29 Sep 2018 13:55:50 -0400 Subject: [PATCH 3/5] Removed trailing white space --- sklearn/feature_extraction/image.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 9d1a70ff9427c..adfa391821336 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -503,7 +503,7 @@ def transform(self, X): -------- >>> import scipy as sp >>> from sklearn.feature_extraction.image import PatchExtractor - + >>> X = sp.misc.face() >>> X.shape (768, 1024, 3) @@ -512,7 +512,7 @@ def transform(self, X): array([[121, 112, 131], [138, 129, 148], [153, 144, 165], - ..., + ..., [119, 126, 74], [131, 136, 82], [139, 144, 90]], dtype=uint8) @@ -524,7 +524,7 @@ def transform(self, X): array([[ 121., 112.], [ 138., 129.], [ 153., 144.], - ..., + ..., [ 119., 126.], [ 131., 136.], [ 139., 144.]]) @@ -533,7 +533,7 @@ def transform(self, X): array([[ 112., 131.], [ 129., 148.], [ 144., 165.], - ..., + ..., [ 126., 74.], [ 136., 82.], [ 144., 90.]]) From 4f1145988836b6652df91a099836988c1607a7a1 Mon Sep 17 00:00:00 2001 From: Parul Date: Sat, 29 Sep 2018 19:18:23 -0400 Subject: [PATCH 4/5] Modified patch_size --- sklearn/feature_extraction/image.py | 37 ++++++++++++----------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index adfa391821336..1359ab287202d 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -503,11 +503,8 @@ def transform(self, X): -------- >>> import scipy as sp >>> from sklearn.feature_extraction.image import PatchExtractor - + >>> X = sp.misc.face() - >>> X.shape - (768, 1024, 3) - >>> X[0] array([[121, 112, 131], [138, 129, 148], @@ -517,26 +514,22 @@ def transform(self, X): [131, 136, 82], [139, 144, 90]], dtype=uint8) - >>> pe = PatchExtractor(patch_size=(1024, 2), random_state=1234) + >>> pe = PatchExtractor(patch_size=(2, 3), random_state=1234) >>> pe.fit(X) - >>> X_transform = pe.transform(X) - >>> X_transform[0] - array([[ 121., 112.], - [ 138., 129.], - [ 153., 144.], - ..., - [ 119., 126.], - [ 131., 136.], - [ 139., 144.]]) - - >>> X_transform[1] - array([[ 112., 131.], - [ 129., 148.], - [ 144., 165.], + >>> pe.transform(X) + array([[[121., 112., 131.], + [138., 129., 148.]], + + [[138., 129., 148.], + [153., 144., 165.]], + ..., - [ 126., 74.], - [ 136., 82.], - [ 144., 90.]]) + + [[120., 156., 95.], + [119., 155., 93.]], + + [[119., 155., 93.], + [118., 154., 92.]]]) """ self.random_state = check_random_state(self.random_state) n_images, i_h, i_w = X.shape[:3] From 136fad46717ce5bb951a5f5e64d13162f63062a2 Mon Sep 17 00:00:00 2001 From: Parul Date: Wed, 3 Oct 2018 21:28:34 -0400 Subject: [PATCH 5/5] Assigned .fit output to self and fixed removed extra spacing --- sklearn/feature_extraction/image.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 1359ab287202d..af7c30c846aa7 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -503,7 +503,7 @@ def transform(self, X): -------- >>> import scipy as sp >>> from sklearn.feature_extraction.image import PatchExtractor - + >>> X = sp.misc.face() >>> X[0] array([[121, 112, 131], @@ -514,8 +514,7 @@ def transform(self, X): [131, 136, 82], [139, 144, 90]], dtype=uint8) - >>> pe = PatchExtractor(patch_size=(2, 3), random_state=1234) - >>> pe.fit(X) + >>> pe = PatchExtractor(patch_size=(2, 3), random_state=1234).fit(X) >>> pe.transform(X) array([[[121., 112., 131.], [138., 129., 148.]],