Sign inSign up

vfoster2docker/titanic-survival-api

By vfoster2docker

•Updated 11 days ago

FastAPI + scikit-learn API that predicts Titanic passenger survival. Run it with one docker command.

Image
0

82

vfoster2docker/titanic-survival-api repository overview

⁠Titanic Survival Prediction API

A machine learning API that predicts whether a Titanic passenger would have survived, using a Random Forest classifier. Pull it and run it with one command, no Python setup needed.

Try it live (no install): vfoster-repo.github.io/ml-model-api-project⁠

Source code: github.com/vfoster-repo/ml-model-api-project⁠

⁠Quick Start

docker pull vfoster2docker/titanic-survival-api:latest
docker run -p 8000:8000 vfoster2docker/titanic-survival-api:latest

Then open http://localhost:8000/docs⁠ in your browser to try it out.

If port 8000 is already in use on your computer, change the first number, for example -p 8080:8000, and go to http://localhost:8080/docs⁠ instead.

⁠Tags

TagWhat it is
latestThe newest version
v1.0First release (same image as latest right now)

⁠Example Prediction

curl -X POST "http://localhost:8000/predict" \
     -H "Content-Type: application/json" \
     -d '{
       "Pclass": 1,
       "Sex": "female",
       "Age": 30.0,
       "SibSp": 0,
       "Parch": 0,
       "Fare": 50.0,
       "Embarked": "S"
     }'

Response:

{
  "survived": 1,
  "survival_probability": 0.92,
  "prediction_confidence": "High",
  "passenger_profile": {
    "class": "Class 1",
    "gender": "female",
    "age_group": "Adult",
    "family_size": 1,
    "traveling_alone": true,
    "fare_level": "High",
    "embarkation_port": "Southampton"
  }
}

⁠API Endpoints

MethodEndpointWhat it does
GET/Health check
POST/predictPrediction for one passenger
POST/predict-batchPredictions for a list of passengers
GET/model-infoModel details and accuracy

⁠Input Parameters

ParameterTypeDescriptionExample
PclassintPassenger class (1, 2, 3)1
SexstrGender ('male', 'female')'female'
AgefloatAge in years (0 to 100)30.0
SibSpintSiblings/spouses aboard0
ParchintParents/children aboard0
FarefloatTicket fare50.0
EmbarkedstrPort ('S', 'C', 'Q')'S'

The API checks these values before predicting. For example, "Sex": "Male" (capital M) or "Pclass": 4 gets a clear error back instead of a wrong prediction.

⁠About the Model

  • Algorithm: Random Forest Classifier (100 trees, max depth 10)
  • Accuracy: about 82% (0.8156) on 179 passengers held out for testing
  • Training data: Kaggle's Titanic train.csv (891 passengers)
  • Features: Passenger class, sex, age, family size, fare, embarkation port, plus title, age group, and fare group made from those

You can see the full training run, with charts, in the training notebook on GitHub⁠.

⁠Image Details

  • Base image: python:3.13-slim
  • Port: 8000
  • Runs as: a regular user (appuser), not root
  • Health check: built in, so docker ps shows healthy once the API is up
  • Built with: FastAPI, Uvicorn, pandas 3.0, scikit-learn 1.9

⁠Author

Victor Foster

Completed as part of the TripleTen AI/ML Engineering program, Sprint 11 "Project: Docker and Containerization".

Tag summary

Content type

Image

Digest

sha256:28fc91064…

Size

146.8 MB

Last updated

11 days ago

docker pull vfoster2docker/titanic-survival-api