Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/jonatan-leal/ia-proyecto-sustituto/llms.txt

Use this file to discover all available pages before exploring further.

Introduction

The Diabetes Prediction API is a FastAPI-based REST API that provides endpoints for training machine learning models and making diabetes predictions based on patient data.

Base URL

http://localhost
The API runs on port 80 by default.

Interactive Documentation

FastAPI provides automatic interactive API documentation:

Available Endpoints

MethodEndpointDescription
POST/trainTrain the diabetes prediction model
POST/predictMake a diabetes prediction for a patient

Request Format

All API requests should include the appropriate Content-Type header:
Content-Type: application/json

Response Format

All API responses are returned in JSON format:
{
  "message": "Response message"
}

Authentication

The current version of the API does not require authentication. All endpoints are publicly accessible.
In a production environment, you should implement proper authentication and authorization mechanisms to secure your API endpoints.

Error Handling

The API uses standard HTTP status codes and returns error messages in JSON format:

Success Response (200 OK)

{
  "message": "Model successfully trained"
}

Error Response

{
  "message": "Something went wrong"
}

Validation Error (422 Unprocessable Entity)

When the request body contains invalid data, FastAPI returns a detailed validation error:
{
  "detail": [
    {
      "loc": ["body", "age"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}

Machine Learning Model

The API uses a Random Forest Classifier with the following preprocessing steps:
  1. Encoding: Categorical variables (gender, smoking_history) are encoded to numerical values
  2. Scaling: Features are standardized using StandardScaler
  3. Resampling: SMOTEENN is applied during training to handle class imbalance

Model Artifacts

  • Model File: model.pkl (saved using pickle)
  • Training Data: train.csv (required for training)

Quick Start Example

# 1. Train the model
curl -X POST http://localhost/train

# 2. Make a prediction
curl -X POST http://localhost/predict \
  -H "Content-Type: application/json" \
  -d '{
    "gender": "Female",
    "age": 45,
    "hypertension": 0,
    "heart_disease": 0,
    "smoking_history": "never",
    "bmi": 27.5,
    "HbA1c_level": 5.7,
    "blood_glucose_level": 140
  }'

Rate Limiting

The current version does not implement rate limiting. Consider implementing rate limiting in production environments to prevent abuse.

Next Steps

Train Endpoint

Learn how to train the diabetes prediction model

Predict Endpoint

Make predictions for patient data

Patient Model

Understand the Patient data schema

Build docs developers (and LLMs) love