Skip to content

Commit

Permalink
Add a few images as it is done in other notebooks
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Tauzin <guillaumetauzin.ut@gmail.com>
  • Loading branch information
gtauzin committed Aug 30, 2020
1 parent da78912 commit 6bc29de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions examples/MNIST_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@
},
"outputs": [],
"source": [
"from gtda.images import Binarizer, Inverter, ImageToPointCloud, HeightFiltration, DilationFiltration, RadialFiltration, ErosionFiltration, SignedDistanceFiltration\n",
"from gtda.images import Binarizer, Inverter, HeightFiltration, DilationFiltration, RadialFiltration, ErosionFiltration, SignedDistanceFiltration\n",
"from gtda.homology import CubicalPersistence\n",
"from gtda.diagrams import ForgetDimension, Amplitude, Scaler, PersistenceEntropy, BettiCurve, PersistenceLandscape, HeatKernel\n",
"from gtda.plotting import plot_heatmap, plot_betti_curves, plot_diagram\n",
"from sklearn.pipeline import Pipeline, make_pipeline, FeatureUnion, make_union\n",
"from sklearn.ensemble import RandomForestClassifier\n",
"from sklearn.model_selection import GridSearchCV\n",
"from sklearn.metrics import classification_report\n",
"import numpy as np\n",
"\n",
"# This would be quite nice but is available with sklearn >= 0.23\n",
"# from sklearn import set_config\n",
"#set_config(display='diagram') "
"from sklearn import set_config\n",
"set_config(display='diagram') "
]
},
{
Expand Down Expand Up @@ -152,7 +149,7 @@
"metadata": {},
"outputs": [],
"source": [
"inverter = Inverter(n_jobs=4)\n",
"inverter = Inverter(n_jobs=-1)\n",
"X_train_inverted = inverter.fit_transform(X_train_binarized)"
]
},
Expand Down Expand Up @@ -322,7 +319,11 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Building a pipeline to extract features"
"## Building a pipeline to extract features\n",
"\n",
"We can summarize all the previous step into a single giotto Pipeline pictured below:\n",
"\n",
"![example_pipeline_images](images/example_pipeline_images.png \"TDA pipeline for MNIST images.\")"
]
},
{
Expand All @@ -333,8 +334,9 @@
"source": [
"steps = [\n",
" ('binarizer', Binarizer(threshold=0.4)),\n",
" ('filtration', SignedDistanceFiltration(n_iterations=28), n_jobs=-1),\n",
" ('filtration', RadialFiltration(center=np.array([20, 6])), n_jobs=-1),\n",
" ('diagram', CubicalPersistence(n_jobs=-1)),\n",
" ('rescaling'), Scaler(),\n",
" ('amplitude', Amplitude(metric='wasserstein', metric_params={'p': 2}, n_jobs=-1))\n",
"]\n",
"\n",
Expand Down Expand Up @@ -400,7 +402,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can go full-scale and extract a large number of features. Careful, some of them will be highly correlated, so it would be good to use a feature selection algorithm to reduce their number before passing them to a classifier.\n",
"We can go full-scale and extract a large number of features by creating a full-blown pipeline such as the one below.\n",
"\n",
"![diagram_pipeline_images](images/diagram_pipeline_images.png \"Full-blown TDA pipeline for MNIST images.\")\n",
"\n",
"\n",
"Careful, some of them will be highly correlated, so it would be good to use a feature selection algorithm to reduce their number before passing them to a classifier.\n",
"\n",
"Note that if you have selected a large number of training/testing samples, this part will take a lot of resources to run. Consider using a cluster."
]
Expand Down
Binary file added examples/images/diagram_pipeline_images.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 examples/images/example_pipeline_images.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 6bc29de

Please sign in to comment.