This repository contains the code for a Flask-based API that predicts the likelihood of recidivism based on provided input data. The API provides endpoints to submit data for prediction and to retrieve prediction results.
- Installation
- Configuration
- Usage
- Endpoints
- Database Schema
- Logging
- License
To set up the project locally, follow these steps:
- Clone the repository:
git clone https://github.com/your-repo/recidivism-prediction-api.git
cd recidivism-prediction-api
- Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
- Install the required packages (DEV):
pip install -r requirements_dev.txt
- Ensure you have the necessary data files in the data directory:
columns.json
dtypes.pickle
pipeline.pickle
The application relies on environment variables for configuration. The primary environment variable is DATABASE_URL
, which specifies the database connection string. If not set, the application defaults to using a local SQLite database (sqlite:///predicts.db
).
To start the Flask application, run the following command:
python app.py
The API will be available at http://0.0.0.0:5000
Predicts the likelihood of recidivism for the given input data.
- Request Body: JSON
{
"id": 1234,
"name": "rui antonio",
"sex": "Male",
"dob": "1987-06-21",
"race": "Caucasian",
"juv_fel_count": 0,
"juv_misd_count": 3,
"juv_other_count": 0,
"priors_count": 5,
"c_case_number": "13022428MM10A",
"c_charge_degree": "F",
"c_charge_desc": "Driving Under The Influence",
"c_offense_date": "2013-08-19",
"c_arrest_date": "2013-09-07",
"c_jail_in": "2013-09-20 06:32:00",
}
- Response: JSON
{
"id": 1234,
"outcome": true
}
Updates the true outcome for a prediction and retrieves the stored prediction.
{
"id": 1234,
"outcome": true
}
- Response: JSON
{
"id": 1234,
"outcome": true,
"predicted_outcome": false
}
The application uses a SQLite database (or other databases via the DATABASE_URL environment variable) with the following schema:
observation_id
(Integer, unique)observation
(Text)pred
(Boolean)pred_proba
(Float)true_class
(Integer, nullable)
The application uses Python's built-in logging module to log information. Logs are configured to display messages at the INFO level and higher.
This project is licensed under the MIT License. See the LICENSE
file for more details.