Iris prediction using a Deep Neural Network
Launch Iris predictor See source code
The goal of this project was to have some fun building a deep neural network and to build and deploy a Flask app frontend for the model prediction inputs.
Goals
- Build a deep neural network using tensorflow
- Build a half decent Flask app
- Host app
Learnings
- Web dev is really hard and something I could (and should) improve on.
- Persistence is not optional. Try, try, try again.
- PythonAnywhere has really outdated libraries out of the box - and a really limited capacity on the free tier, making it very difficult to install more recent versions of these libraries.
Build a deep neural network using tensorflow
For this project I decided to use the classic Iris dataset as I had never attempted a project with this data before. No data cleaning to be done with this dataset, but I did plot it in a 3 dimensional space, reducing the 4 features to 3 first using principle component analysis (see below).
This neural network has a train accuracy of 99% and a test accuracy of 98%.
Build a half decent Flask app
This was quite fun, although my app looked terrible to start with as it had just the 4 input form fields and a submit button, with the picture of the species of iris at the top. I enlisted the help of ChatGPT to prettify the page and generate CSS for me to make the page responsive and create form validations etc.
Host app
This was harder than expected to say the least. I had initially planned to use PythonAnywhere to host, however the free tier on PythonAnywhere only comes with tensorflow 2.9.0 pre-installed which doesn’t support pickling and unpickling model files. Setting up a venv and installing a newer version of tensorflow also did not work, as the free tier doesn’t come with enough storage to install tensorflow 2.18.0 (which is a whopping 600mb+).
I decided to change my approach at this point because I’m not prepared to spend real dollars to make this happen. After a day of fiddling around with nginx and gunicorn config, I managed to deploy my app on an AWS EC2 instance following this article, and set it up to link to my custom subdomain using this other article, with some debugging (read: a lot of debugging) here and there where it all fell apart and the issues weren’t covered by these articles or Stackoverflow.