
Deploying Scikit-Learn Models using CI/CD on Google Cloud
In my most recent project, I undertook an in-depth exploration of the offerings available on Google Cloud Platform (GCP). The central goal was to deploy a machine learning model, trained using various algorithms from the Scikit-learn library in Python3, and to integrate this with a Streamlit front end. The end product would be an application hosted on GCP, which dynamically updates based on changes made to a corresponding GitHub repository.
The project seemed straightforward initially, but as someone new to this particular space, I found it to be quite a challenge. In fact, my overarching aim was to build a comprehensive Machine Learning Operations (MLOps) pipeline. To clarify, MLOps is a hybrid discipline that combines Machine Learning Engineering and Developer Operations (DevOps), effectively forming the foundation for the role of an AI Engineer in the modern digital landscape.
An AI Engineer, in this context, doesn’t necessarily hold a PhD or command a deep understanding of the mathematics and statistics underlying each and every algorithm. Instead, their expertise lies in providing solutions to problems within the scope of Machine Learning (ML) and Large Language Models (LLM).
The project unfolded as follows:
- I initiated the project by calling upon a Google Cloud Storage bucket. Overcoming the associated library difficulties, I stored the retrieved data in a pandas dataframe for subsequent analysis.
- Rather than undertaking any extensive data processing, I simply split the dataframe into the independent features (X) and the target variable, labelled “death”, based on a Heart Disease Dataset.
- I then fitted two classifiers to the data: a Logistic Regression model and a Random Forest Classifier.
- The performance of these classifiers was evaluated based on their accuracy and AUC-ROC (Area Under the Receiver Operating Characteristics curve) scores.
- Next, I designed a Streamlit front end for the application, which would allow external users to interact with the deployed model.
- Each experiment with an individual classifier is tracked on wandb.ai using their logging tools. This is a new step for me but I’m slowly getting my head around tools like this including MLFLow and others. Being able to physically visualize how the hyperparameters and models perform is a massive benefit when planning deployment. Given that I didn’t do any feature engineering with the aim of deploying to the Cloud continuously, it is not so effective as informative.
- The code was subsequently pushed to GitHub. You can access the repository here: GitHub – nullzero-live/multi-model-classification: run sklearn classification algorithms over your cleaned dataset (hosted on GCloud with Build)
- The Github code is pulled to the Google Cloud Run environment and built from a Docker image.
- The front end required numerous iterations (approximately 120) to ensure the correct outputs were being displayed.
- I also incorporated an LLM to provide a summary of the accuracy and AUC-ROC results.
- To streamline future development, I set up a Google Cloud Build job. This was designed to trigger a new integration (Continuous Integration, CI) every time a new change was pushed to the GitHub repository.
- Along the way, there were some frustrating moments that had me metaphorically pulling my hair out.
- After taking a brief respite for sleep, I returned to the project and persevered through the challenges.
The project has proven to be incredibly informative thus far. Notably, I’ve gained insights into IAM permissioning on GCP, familiarized myself with a range of GCP services, and honed my skills in integrating front end code with back end code.
However, this project is far from complete. Although it’s currently operational, I aim to continue refining and expanding its capabilities.
Thank you for taking the time to read about my journey. I look forward to sharing further updates as the project progresses.
