How christianarroyoauz/predict-rental-prices-ecuador works
1. Repository purpose
- This is a small ML inference service, not a full CRUD application.
- The production surface is a FastAPI REST API that predicts monthly rental prices for properties in Ecuador from a handful of structured inputs.
2. Main runtime boundary
- The live serving layer is in the api/ package.
- The rest of the repository is supporting offline work: model training, data exploration, artifact generation, and deployment configuration.
- For an architecture diagram, treat api/ as the online path and notebooks/, src/, data/, models/ as the offline ML pipeline/assets.
3. API layer
- api/main.py is the entrypoint for the HTTP service.
- api/schemas.py defines the request/response contracts used by FastAPI/Pydantic.
- The API exposes at least:
- GET /health for liveness/model status
- POST /predict for inference
- The /health endpoint also reports library versions, which indicates the service is used to confirm the runtime environment as well as readiness.
4. Inference flow
- A client sends JSON with provincia, lugar, num_dormitorios, num_banos, area, and num_garages.
- FastAPI validates the payload via Pydantic schemas.
- The request is passed to the model loading/prediction code in src/model.py and helper utilities in src/utils.py.
- The response returns a single numeric prediction, likely in USD.
5. Model and artifact layer
- The deployed model is stored as a serialized artifact in models/rental_price_model.pkl.
- Additional artifacts exist in models/mejor_modelo.pkl and models/model_artifacts.pkl, suggesting the training pipeline produced multiple saved outputs or a best-model snapshot.
- The application reads the model path from configuration; the README explicitly mentions MODEL_PATH=./models/rental_price_model.pkl.
6. Preprocessing / feature engineering
- src/data_processing.py likely contains the transformation logic for cleaning, encoding, and shaping inputs before prediction.
- Because the model is a Random Forest pipeline per the README, preprocessing is probably bundled into the serialized pipeline or mirrored in the src/ helpers.
- This is an important boundary: raw API inputs are not fed directly to the estimator; they are normalized into the exact feature structure expected by the saved model.
7. Training and analysis workflow
- notebooks/01_eda.ipynb and notebooks/02_modeling.ipynb document the offline ML lifecycle: exploration, feature analysis, training, and artifact creation.
- The root notebooks Prueba_Funcionamiento_Local.ipynb and Pruebas_Funcionamiento_API.ipynb appear to be validation/demo notebooks for local and API testing.
- data/real_state_ecuador_dataset.csv is the training dataset source used offline, not part of the inference request path.
8. Shared library code
- src/ is the reusable ML support layer imported by the API and likely by notebooks during experimentation.
- src/model.py is the most important internal abstraction for loading the persisted model and producing predictions.
- src/utils.py likely holds common helpers such as path resolution, serialization, or feature preparation.
- This separation suggests a clean divide between application entrypoint (api/) and ML utility code (src/).
9. Deployment architecture
- The service is designed to run in containers: there is a Dockerfile.frontend, a second dockerfile, and docker-compose.yaml.
- render.yaml and the README’s Railway references show cloud deployment is managed through platform config rather than custom infrastructure code.
- runtime.txt and requirements.txt pin the Python environment and dependencies for reproducible deployment.
10. External/runtime characteristics
- The stack is Python 3.11 with FastAPI/Uvicorn/Pydantic on the serving side, and scikit-learn/pandas/numpy/joblib on the ML side.
- The application is stateless at request time: the model is loaded from disk and predictions are computed in-process.
- There is no database, message queue, or object storage in the current architecture.
11. Operational behavior
- Startup behavior likely includes loading the serialized model and exposing the API once the model is available.
- If the model is missing or fails to load, /health reports that state through model_loaded.
- This makes model availability the key operational dependency for the service.
12. What to draw in an architecture diagram
- Show four main blocks:
- Client/UI/CLI sending JSON requests
- FastAPI service (api/) handling validation and routing
- **ML inference layer (src/ + models/*.pkl)** performing preprocessing and prediction
- Offline training assets (notebooks/, data/) producing the serialized model
- Connect deployment config (Dockerfile, docker-compose.yaml, render.yaml, Railway) around the API service as the execution environment.
Main entry points: main.py API entrypoint · model.py Model loader · 02_modeling.ipynb Modeling notebook · requirements.txt Dependencies
Components 21
Online serving
Live FastAPI inference path
- Client · Sends structured JSON for health checks and rent predictions
- API entrypoint · Starts the HTTP service and registers routes
api/main.py - Schemas · Validates prediction input and shapes responses
api/schemas.py - Health check · Reports liveness, model status, and runtime versions
- Predict route · Accepts property features and returns a rent estimate
- Model loader · Loads the serialized model and runs predictions
src/model.py - Preprocessing · Normalizes and transforms raw inputs into model-ready features
src/data_processing.py - Helpers · Common support code for pathing, serialization, and feature helpers
src/utils.py - Rental model · Primary persisted model used by the API
models/rental_price_model.pkl
Offline ML lifecycle
Training, exploration, and artifact generation
- Best model · Alternative or best-snapshot model artifact
models/mejor_modelo.pkl - Artifact bundle · Saved training outputs and supporting metadata
models/model_artifacts.pkl - Dataset · Offline source dataset for exploration and model fitting
data/real_state_ecuador_dataset.csv - EDA notebook · Explores the rental data and feature distributions
notebooks/01_eda.ipynb - Modeling notebook · Trains and evaluates the model, producing artifacts
notebooks/02_modeling.ipynb - Local demo · Checks the service and model behavior locally
Prueba_Funcionamiento_Local.ipynb - API demo · Exercises the HTTP prediction flow end to end
Pruebas_Funcionamiento_API.ipynb
Deployment
Container and platform configuration
- Containers · Container build definitions for running the service
- Compose · Local multi-container orchestration for development
docker-compose.yaml - Platform config · Deployment settings for hosted runtime platforms
render.yaml - Python env · Pins Python version and dependencies for reproducible deploys
runtime.txt - Dependencies · Python libraries used by the API and ML stack
requirements.txt
Connections 25
- Client → API entrypoint: HTTP requests · External caller sends health and prediction requests
- API entrypoint → Schemas: validates with · FastAPI uses schemas for request and response contracts
- API entrypoint → Health check: serves · Exposes liveness and model status endpoint
- API entrypoint → Predict route: serves · Exposes prediction endpoint
- Predict route → Schemas: parses input · Structured request payload is validated before inference
- Predict route → Preprocessing: preprocesses · Raw feature values are shaped into model-ready inputs
- Predict route → Model loader: predicts via · Prediction route delegates to model loading and inference code
- Health check → Model loader: checks model · Health response includes model_loaded state
- Health check → Helpers: reports versions · Runtime/library metadata is assembled for readiness checks
- Model loader → Rental model: loads · Primary serialized model artifact is read from disk
- Model loader → Artifact bundle: may use · Loader can rely on saved metadata or auxiliary artifacts
- Preprocessing → Helpers: uses · Shares helper functions and path/feature utilities
- Modeling notebook → Dataset: trains on · Offline training uses the CSV dataset
- EDA notebook → Dataset: explores · EDA notebook analyzes the same training data
- Modeling notebook → Rental model: produces · Training pipeline exports the deployed model artifact
- Modeling notebook → Best model: produces · May also export best-snapshot model artifacts
- Modeling notebook → Artifact bundle: produces · Stores training outputs and supporting artifacts
- Local demo → API entrypoint: tests · Notebook exercises the local service runtime
- API demo → API entrypoint: tests · Notebook exercises the HTTP prediction flow
- Containers → API entrypoint: runs · Container images package the FastAPI application
- Compose → Containers: orchestrates · Compose coordinates local container execution
- Platform config → Containers: deploys · Platform config references containerized runtime
- Python env → Dependencies: pins · Environment version works with declared dependencies
- Dependencies → API entrypoint: supports · API depends on FastAPI, Uvicorn, and Pydantic stack
- Dependencies → Model loader: supports · Inference layer depends on scikit-learn and joblib stack