Skip to content

Commit

Permalink
Added feature extraction class example
Browse files Browse the repository at this point in the history
  • Loading branch information
kaboroevich committed Mar 8, 2021
1 parent 015dacc commit d3bbd00
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 33 deletions.
49 changes: 30 additions & 19 deletions README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Initialize image transformer."
"Initialize image transformer. There are three built-in feature extraction options, 'tsne', 'pca', and 'kpca' to align with the original MatLab implementation."
]
},
{
Expand All @@ -120,6 +120,27 @@
" n_jobs=-1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, any class instance with method `.fit_transform()` that returns a 2-dimensional array of extracted features can also be provided to the ImageTransformer class. This allows for customization of the feature extraction procedure."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.manifold import TSNE\n",
"\n",
"tsne = TSNE(n_components=2, perplexity=30, metric='cosine',\n",
" random_state=1701, n_jobs=-1)\n",
"\n",
"it = ImageTransformer(feature_extractor=tsne, pixels=50)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -131,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -145,21 +166,11 @@
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<pyDeepInsight.image_transformer.ImageTransformer at 0x7f7549a01220>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plt.figure(figsize=(5, 5))\n",
"it.fit(X_train_norm, plot=True)"
"_ = it.fit(X_train_norm, plot=True)"
]
},
{
Expand All @@ -171,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -211,7 +222,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -258,7 +269,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -274,7 +285,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -291,7 +302,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -325,7 +336,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand Down
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ X_train_norm = ln.fit_transform(X_train)
X_test_norm = ln.transform(X_test)
```

Initialize image transformer.
Initialize image transformer. There are three built-in feature extraction options, 'tsne', 'pca', and 'kpca' to align with the original MatLab implementation.


```python
Expand All @@ -73,29 +73,35 @@ it = ImageTransformer(feature_extractor='tsne',
n_jobs=-1)
```

Alternatively, any class instance with method `.fit_transform()` that returns a 2-dimensional array of extracted features can also be provided to the ImageTransformer class. This allows for customization of the feature extraction procedure.


```python
from sklearn.manifold import TSNE

tsne = TSNE(n_components=2, perplexity=30, metric='cosine',
random_state=1701, n_jobs=-1)

it = ImageTransformer(feature_extractor=tsne, pixels=50)

```

Train image transformer on training data. Setting plot=True results in at
a plot showing the reduced features (blue points), convex full (red), and
minimum bounding rectagle (green) prior to rotation.


```python
plt.figure(figsize=(5, 5))
it.fit(X_train_norm, plot=True)
_ = it.fit(X_train_norm, plot=True)
```



![png](README_files/README_10_0.png)
![png](README_files/README_12_0.png)






<pyDeepInsight.image_transformer.ImageTransformer at 0x7f7549a01220>



The feature density matrix can be extracted from the trained transformer in order to view overall feature overlap.


Expand All @@ -116,7 +122,7 @@ _ = plt.title("Genes per pixel")



![png](README_files/README_12_0.png)
![png](README_files/README_14_0.png)



Expand Down Expand Up @@ -146,7 +152,7 @@ it.pixels = 50



![png](README_files/README_14_0.png)
![png](README_files/README_16_0.png)



Expand Down Expand Up @@ -179,7 +185,7 @@ plt.tight_layout()



![png](README_files/README_20_0.png)
![png](README_files/README_22_0.png)



Expand All @@ -199,7 +205,7 @@ plt.tight_layout()



![png](README_files/README_22_0.png)
![png](README_files/README_24_0.png)



Expand Down
Binary file removed README_files/README_10_0.png
Binary file not shown.
Binary file modified README_files/README_12_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/README_14_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README_files/README_16_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed README_files/README_20_0.png
Binary file not shown.
Binary file modified README_files/README_22_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added README_files/README_24_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d3bbd00

Please sign in to comment.