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.

Endpoint

POST /predict
Makes a diabetes prediction for a patient based on their health information. The model must be trained first using the POST /train endpoint.

Request

Headers

Content-Type: application/json

Body

The request body must contain a valid Patient object with all required fields.
gender
string
required
Patient’s gender. Must be one of:
  • Female
  • Male
  • Other
age
integer
required
Patient’s age in years (e.g., 45)
hypertension
integer
required
Whether the patient has hypertension:
  • 0: No hypertension
  • 1: Has hypertension
heart_disease
integer
required
Whether the patient has heart disease:
  • 0: No heart disease
  • 1: Has heart disease
smoking_history
string
required
Patient’s smoking history. Must be one of:
  • never: Never smoked
  • former: Former smoker
  • current: Current smoker
  • not current: Not currently smoking
  • ever: Has smoked at some point
  • No Info: No information available
bmi
float
required
Body Mass Index (BMI) of the patient (e.g., 27.5)
HbA1c_level
float
required
Hemoglobin A1c level, a measure of average blood sugar over 2-3 months (e.g., 5.7)Normal range: 4.0 - 5.6%Prediabetes: 5.7 - 6.4%Diabetes: 6.5% or higher
blood_glucose_level
integer
required
Blood glucose level in mg/dL (e.g., 140)Normal (fasting): 70 - 100 mg/dLPrediabetes: 100 - 125 mg/dLDiabetes: 126 mg/dL or higher

Response

message
string
required
Prediction result. Possible values:
  • "Tiene diabetes": Patient is predicted to have diabetes
  • "No tiene diabetes": Patient is predicted not to have diabetes
  • "Something went wrong": An error occurred during prediction

Examples

curl -X POST http://localhost/predict \
  -H "Content-Type: application/json" \
  -d '{
    "gender": "Female",
    "age": 35,
    "hypertension": 0,
    "heart_disease": 0,
    "smoking_history": "never",
    "bmi": 22.5,
    "HbA1c_level": 5.2,
    "blood_glucose_level": 90
  }'

Response Examples

Success - No Diabetes

Status Code: 200 OK
{
  "message": "No tiene diabetes"
}

Success - Has Diabetes

Status Code: 200 OK
{
  "message": "Tiene diabetes"
}

Error Response

Status Code: 200 OK
{
  "message": "Something went wrong"
}

Validation Error

Status Code: 422 Unprocessable Entity When required fields are missing or have invalid values:
{
  "detail": [
    {
      "loc": ["body", "age"],
      "msg": "field required",
      "type": "value_error.missing"
    },
    {
      "loc": ["body", "bmi"],
      "msg": "value is not a valid float",
      "type": "type_error.float"
    }
  ]
}

Prediction Process

The prediction endpoint performs the following steps:
1

Validate Input

Validates that all required Patient fields are present and correctly typed using Pydantic validation.
2

Load Model

Checks if model.pkl exists and loads the trained model. Returns an error if the model hasn’t been trained yet.
3

Encode Data

Converts categorical variables to numeric codes:
  • Gender: Female (0), Male (1), Other (2)
  • Smoking History: No Info (0), current (1), ever (2), former (3), never (4), not current (5)
4

Scale Features

Applies StandardScaler to normalize all features to the same scale.
5

Make Prediction

Uses the trained Random Forest model to predict diabetes (0 or 1).
6

Return Result

Returns a human-readable message based on the prediction:
  • 1 → “Tiene diabetes”
  • 0 → “No tiene diabetes”

Common Issues

Error: Prediction fails because model.pkl doesn’t exist.Solution: Train the model first using POST /train before making predictions.
curl -X POST http://localhost/train
Error: 422 validation error for gender field.Solution: Ensure gender is exactly one of: Female, Male, or Other (case-sensitive).
Error: 422 validation error for smoking_history field.Solution: Use one of the valid values: never, former, current, not current, ever, or No Info.
Error: 422 validation error with “field required” message.Solution: Include all 8 required fields in the request body. See the Patient Model for details.
Error: 422 validation error with “value is not a valid” message.Solution: Ensure correct data types:
  • Strings: gender, smoking_history
  • Integers: age, hypertension, heart_disease, blood_glucose_level
  • Floats: bmi, HbA1c_level

Understanding Results

The prediction is based on machine learning and should be used as a screening tool only. Always consult healthcare professionals for medical diagnosis.

Risk Factors

The model considers multiple risk factors when making predictions:
  1. Age: Diabetes risk increases with age
  2. BMI: Higher BMI correlates with increased diabetes risk
  3. HbA1c Level: Direct indicator of blood sugar control
  4. Blood Glucose Level: Key diagnostic marker
  5. Hypertension: Often co-occurs with diabetes
  6. Heart Disease: Shares risk factors with diabetes
  7. Smoking History: Increases diabetes risk
  8. Gender: May influence risk patterns

Interpreting Predictions

No tiene diabetes

The model predicts the patient does not have diabetes based on their health metrics.Note: This is a screening prediction, not a medical diagnosis.

Tiene diabetes

The model predicts the patient may have diabetes based on their health metrics.Recommendation: Consult a healthcare provider for proper testing and diagnosis.

Best Practices

1

Validate data before sending

Ensure all patient data is accurate and in the correct format before making API calls.
2

Handle errors gracefully

Implement proper error handling in your application to manage validation errors and API failures.
3

Don't rely solely on predictions

Use predictions as a screening tool alongside clinical judgment and proper medical testing.
4

Keep the model updated

Retrain the model periodically with new data to maintain prediction accuracy.

Patient Model Schema

Complete reference for the Patient data model

Train Endpoint

Learn how to train the prediction model

Build docs developers (and LLMs) love