Skip to content

Commit 75858e0

Browse files
committed
Initial Commit
0 parents  commit 75858e0

File tree

8 files changed

+166
-0
lines changed

8 files changed

+166
-0
lines changed

.gitignore

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# Jupyter Notebook checkpoints
28+
.ipynb_checkpoints
29+
30+
# PyInstaller
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.nox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*.cover
48+
.hypothesis/
49+
.pytest_cache/
50+
51+
# mypy
52+
.mypy_cache/
53+
.dmypy.json
54+
55+
# VS Code
56+
.vscode/
57+
58+
# Docker
59+
*.log
60+
61+
# Model artifacts
62+
models/*.joblib
63+
64+
# OS files
65+
.DS_Store
66+
Thumbs.db
67+
68+
# Environment variables
69+
.env
70+
.env.*

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
FROM python:3.11-slim
3+
4+
WORKDIR /app
5+
COPY . .
6+
7+
RUN pip install --no-cache-dir -r requirements.txt
8+
9+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
# Logistic Regression ML Pipeline with FastAPI 🚀
3+
4+
A clean and modern ML microservice for logistic regression using FastAPI. Built with scalability, explainability, and deployability in mind.
5+
6+
## 🔧 Project Structure
7+
8+
```
9+
logistic-regression-fastapi/
10+
11+
├── app/
12+
│ ├── main.py # FastAPI app entrypoint
13+
│ ├── model.py # Model loading and prediction logic
14+
│ └── schemas.py # Pydantic request/response models
15+
16+
├── models/
17+
│ └── logistic_model.joblib # Pretrained logistic regression model
18+
19+
├── notebooks/
20+
│ └── train_model.ipynb # Jupyter notebook for training and evaluation
21+
22+
├── Dockerfile # Containerisation setup
23+
└── requirements.txt # Python dependencies
24+
```
25+
26+
## 🧪 Training
27+
28+
The `notebooks/train_model.ipynb` trains a simple logistic regression classifier and exports the model.
29+
30+
## ▶️ Run API
31+
32+
```bash
33+
uvicorn app.main:app --reload
34+
```
35+
36+
## 🐳 Docker
37+
38+
```bash
39+
docker build -t logistic-api .
40+
docker run -d -p 8000:8000 logistic-api
41+
```
42+
43+
## ✨ Author
44+
45+
[![Pierre-Henry Soria](https://avatars0.githubusercontent.com/u/1325411?s=200)](https://ph7.me)
46+
47+
Made with ❤️ by **[Pierre-Henry Soria](https://pierrehenry.be)** — an AI Data Scientist & Senior Software Engineer. Incredibly passionate about AI, machine learning, data science, and emerging technologies. I could happily talk all night about programming and IT with anyone who’s keen. Roquefort 🧀, ristretto ☕️, and dark chocolate lover! 😋
48+
49+
[![@phenrysay](https://img.shields.io/badge/x-000000?style=for-the-badge&logo=x)](https://x.com/phenrysay) [![GitHub](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/pH-7) [![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white)](https://youtu.be/cWBuZ4DXGK4) [![Bluesky](https://img.shields.io/badge/bluesky-1e90ff?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMDAwMDAwIiBoZWlnaHQ9IjI0cHgiIHZpZXdCb3g9IjAgMCAzMiAzMiIgd2lkdGg9IjI0cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTMwIDZsLTIuOTk5LTEuNjY2TDMyIDMuMzQgMjMuMTg5IDAgMTYuMDA2IDUuMzQgOC44MTMgMCAwIDMuMzQgNC45OTkgNC4zMzQgMCA2bDUuMDAxIDQuODAzTDQgMjAuODFWMjRsNS4wMDEtMS42NjZMMTYgMjhMMjIuOTk5IDIyLjM0IDMyIDI0di0zLjE4OUwyNy4wMDIgMTIgMzAgNiIgLz48L3N2Zz4=)](https://bsky.app/profile/ph7s.bsky.social "Bluesky Profile")

app/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
from fastapi import FastAPI
3+
from app.model import predict
4+
from app.schemas import PredictRequest, PredictResponse
5+
6+
app = FastAPI()
7+
8+
@app.post("/predict", response_model=PredictResponse)
9+
def predict_endpoint(req: PredictRequest):
10+
prediction = predict(req.features)
11+
return PredictResponse(prediction=prediction)

app/model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import joblib
3+
import numpy as np
4+
from pathlib import Path
5+
6+
model_path = Path(__file__).parent.parent / "models" / "logistic_model.joblib"
7+
model = joblib.load(model_path)
8+
9+
def predict(features: list) -> int:
10+
X = np.array(features).reshape(1, -1)
11+
return int(model.predict(X)[0])

app/schemas.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
from pydantic import BaseModel
3+
from typing import List
4+
5+
class PredictRequest(BaseModel):
6+
features: List[float]
7+
8+
class PredictResponse(BaseModel):
9+
prediction: int

notebooks/train_model.ipynb

Whitespace-only changes.

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
fastapi
3+
uvicorn
4+
joblib
5+
scikit-learn
6+
numpy
7+
pydantic

0 commit comments

Comments
 (0)