ia-cloud-1
Cloud IA model.
House Price Prediction Project
This project provides a simple machine learning pipeline to predict house prices based on size, number of rooms, and the presence of a garden.
Features
- Model Training: Linear regression model trained on house data.
- FastAPI: REST API for real-time predictions.
- Streamlit: Web interface for interactive predictions.
- Containerization: Docker and Docker Compose support.
Getting Started
Prerequisites
- Install UV
1. Installation
Install dependencies using UV:
2. Train the Model
Run the training script:
3. Run the API (FastAPI)
The API will be available at http://localhost:8000. You can test the /predict endpoint.
4. Run the Web App (Streamlit)
Kafka Workflows
Setup: Create Partitions
Initialize Kafka partitions for both input and output topics:
This creates 2 partitions per topic to enable parallel processing and prevent duplicate message handling.
Workflow 1: Single Message Production & Consumption
Purpose: Test basic producer-consumer interaction with partition routing.
- Start consumer (partition 0):
- Send message:
- Verify message received on assigned partition.
Workflow 2: ML Model Predictions (Full Pipeline)
Purpose: Production ML inference pipeline - predictions should be processed only once across multiple consumers.
Step 1: Start Prediction Consumers
Each consumer handles one partition independently:
Terminal 1 (partition 0):
Terminal 2 (partition 1):
What they do:
- Load ML model at startup
- Listen on their assigned partition
- Receive raw input data
- Run predictions using the trained model
- Send results to
OUTPUT_TOPIC
Step 2 (Optional): Monitor Predictions
View prediction results:
Terminal 3 (partition 0):
Terminal 4 (partition 1):
Step 3: Send Data for Prediction
Send multiple messages (they route to random partitions):
Result:
- Each message goes to partition 0 or 1 randomly
- Only the corresponding consumer receives and processes it
- Predictions are made and sent to
OUTPUT_TOPIC - No duplicate processing even with multiple consumers
- Enables horizontal scaling of prediction workers
Architecture Overview
Producer (random partition)
↓
Input Topic [Partition 0, Partition 1]
↓
Consumer Predict 0 ─→ Load Model ─→ Predict ─→ Output Topic [Partition 0]
Consumer Predict 1 ─→ Load Model ─→ Predict ─→ Output Topic [Partition 1]
↓
Consumer View (optional monitoring)
Docker
Build and run the entire stack using Docker Compose:
Pierre Roy