This project demonstrates a complete workflow for developing, testing, and deploying an AI model. The primary objective is to build and test a machine learning model, expose it via a REST API, and automate the entire process using CI/CD pipelines. Below is a detailed summary of the work done.
- Project Description
- Setup Instructions
- Key Features
- Step-by-Step Workflow
- CI/CD Pipeline
- API Usage
- Technologies Used
- License
This project involves:
- Building a machine learning model to predict survival on the Titanic dataset.
- Automating testing for the model’s functionality and accuracy using PyTest.
- Exposing the trained model as a REST API using Flask.
- Containerizing the application using Docker.
- Automating CI/CD workflows using GitHub Actions.
- Python 3.9 or above
- Docker installed on your machine
- A GitHub account
- Optional: Docker Hub account
-
Clone the repository:
git clone <repository-url> cd ai-model-testing
-
Install dependencies:
pip install -r requirements.txt
-
Run the Flask application locally:
python app.py
-
Test the application locally:
pytest
-
Build and run the Docker container:
docker build -t ai-model-api . docker run -p 5000:5000 ai-model-api
- Machine Learning Model: Logistic regression on Titanic dataset.
- Testing: Automated testing with PyTest.
- API: Flask-based REST API for model predictions.
- Containerization: Dockerized application.
- CI/CD: GitHub Actions for automation.
- Loaded the Titanic dataset.
- Cleaned data by handling missing values and encoding categorical variables.
- Prepared the data for training.
- Trained a logistic regression model.
- Evaluated accuracy to ensure the model meets performance criteria.
- Wrote PyTest scripts to:
- Validate data preprocessing.
- Ensure model accuracy meets thresholds.
- Integrated tests into the CI/CD pipeline.
- Created a Flask REST API with an endpoint to make predictions.
- Tested the API locally with tools like Postman and cURL.
- Wrote a Dockerfile to containerize the application.
- Built and ran the Docker container locally.
- Pushed the container image to Docker Hub.
- Configured GitHub Actions to:
- Run automated tests.
- Generate and upload test/coverage reports.
- Build and push the Docker image to Docker Hub.
- Verified the pipeline’s success on every commit.
The GitHub Actions pipeline automates the following steps:
- Checkout Code:
- Clones the repository.
- Set Up Python:
- Installs dependencies from
requirements.txt
.
- Installs dependencies from
- Run Tests:
- Executes PyTest scripts.
- Generates test and coverage reports.
- Build and Push Docker Image:
- Logs into Docker Hub using GitHub secrets.
- Builds and pushes the Docker image.
- URL:
http://<host>:5000/predict
- Method: POST
{
"Pclass": 3,
"Sex": 1,
"Age": 25,
"SibSp": 0,
"Parch": 0,
"Fare": 7.25,
"Embarked": 2
}
{
"prediction": 0
}
- Programming Language: Python 3.9
- Libraries: Flask, Scikit-learn, PyTest
- Containerization: Docker
- CI/CD: GitHub Actions
This project is licensed under the MIT License. See the LICENSE file for details.
- Explore AI model testing techniques:
- Functional testing.
- Performance testing.
- Bias and fairness testing.
- Deploy the container on a cloud platform.
- Integrate notifications into the CI/CD pipeline.