Skip to main content
POST
/
credit_score_prediction
POST /credit_score_prediction
curl --request POST \
  --url https://api.example.com/credit_score_prediction \
  --header 'Content-Type: application/json' \
  --data '
{
  "Age": 123,
  "Sex": "<string>",
  "Job": "<string>",
  "Housing": "<string>",
  "Saving accounts": "<string>",
  "Checking account": "<string>",
  "Credit amount": 123,
  "Duration": 123,
  "Purpose": "<string>"
}
'
{
  "200": {},
  "422": {},
  "500": {},
  "prediction": "<string>",
  "probability": 123
}

Overview

This endpoint predicts whether a customer’s credit risk is “good” or “bad” based on their demographic and financial information. The prediction is made using a PyTorch deep learning model that has been trained on historical credit data.

Endpoint

POST /credit_score_prediction

Request Schema

The request body must be a JSON object with the following fields:

Required Fields

Age
integer
required
Age of the applicant in years. Must be greater than 0.Example: 35
Sex
string
required
Gender of the applicant.Allowed values:
  • "male"
  • "female"
Example: "male"
Job
string
required
Skill level of the applicant’s job.Allowed values:
  • "unskilled and non-resident"
  • "unskilled and resident"
  • "skilled"
  • "highly skilled"
Example: "skilled"
Housing
string
required
Type of housing for the applicant.Allowed values:
  • "own" - Owns housing
  • "rent" - Rents housing
  • "free" - Free housing
Example: "own"
Saving accounts
string
required
Status of the savings account. Note the space in the field name.Allowed values:
  • "NA" - No savings account
  • "little" - Little savings
  • "moderate" - Moderate savings
  • "quite rich" - Quite rich savings
  • "rich" - Rich savings
Example: "NA"
Checking account
string
required
Status of the checking account. Note the space in the field name.Allowed values:
  • "NA" - No checking account
  • "little" - Little balance
  • "moderate" - Moderate balance
  • "rich" - Rich balance
Example: "little"
Credit amount
number
required
Amount of credit requested. Must be greater than 0.Example: 9055.0
Duration
integer
required
Duration of the credit in months. Must be greater than 0.Example: 36
Purpose
string
required
Purpose of the credit.Allowed values:
  • "car"
  • "furniture/equipment"
  • "radio/TV"
  • "domestic appliances"
  • "repairs"
  • "education"
  • "business"
  • "vacation/others"
Example: "education"

Response Schema

The response is a JSON object with the following fields:
prediction
string
required
The predicted credit risk category.Possible values:
  • "good" - Good credit risk
  • "bad" - Bad credit risk
probability
number
required
The probability that the credit risk is “good”. Value between 0 and 1.Range: 0.0 to 1.0Note: Higher values indicate higher confidence in a “good” prediction.

Example Request

{
  "Age": 35,
  "Sex": "male",
  "Job": "unskilled and resident",
  "Housing": "free",
  "Saving accounts": "NA",
  "Checking account": "NA",
  "Credit amount": 9055,
  "Duration": 36,
  "Purpose": "education"
}

Example Response

{
  "prediction": "good",
  "probability": 0.8542
}

Response Status Codes

200
OK
Prediction completed successfully
422
Unprocessable Entity
Invalid input data - validation failed
500
Internal Server Error
Error during model inference

Inference Pipeline

The prediction process follows these steps:
1

Input Validation

The request data is validated against the CreditRiskInput Pydantic schema to ensure all fields are present and have correct types and values.
2

Data Preprocessing

The input is transformed into a pandas DataFrame and processed using a scikit-learn preprocessor that handles:
  • Categorical encoding
  • Feature scaling
  • Feature engineering
3

Model Inference

The preprocessed data is converted to a PyTorch tensor and passed through the deep learning model:
  • The model outputs probabilities for both “bad” and “good” classes
  • The prediction is determined by the class with the highest probability
4

Response Generation

The prediction result and probability are packaged into a CreditRiskOutput response object and returned as JSON.

Implementation Details

Important Notes

Field Names with Spaces: The fields "Saving accounts" and "Checking account" contain spaces. Ensure you include the space when making requests, or the validation will fail.
Singleton Pattern: The model is loaded once at startup using a singleton pattern. All prediction requests share the same model instance for optimal performance.
CPU Inference: The model runs on CPU by default. For high-throughput production deployments, consider configuring GPU support.

API Overview

Learn about the API architecture

Interactive Docs

Try the API in Swagger UI

Build docs developers (and LLMs) love