Endpoint
Trains a new fraud detection model using training data from the specified folder path. This endpoint triggers the complete training workflow including data validation, preprocessing, and model training.
Request Body
The request must be sent as JSON with the following parameter:
The file system path to the folder containing training data files. This folder should contain properly formatted CSV files with transaction data for model training.
{
"folderPath" : "/path/to/training/data"
}
Training Workflow
When the /train endpoint is called, the following process is executed:
Validation - The train_validation object validates the training data structure and format
Data Processing - Training data is validated and inserted into the database
Model Training - The trainModel object trains the fraud detection model using the validated data
train_valObj = train_validation(path)
train_valObj.train_validation()
trainModelObj = trainModel()
trainModelObj.trainingModel()
Response
Returns a success message when training completes successfully.
Success Response
Error Responses
Returns an error message if training fails.
Possible error responses:
Error Occurred! <class 'ValueError'>
Error Occurred! <class 'KeyError'>
Error Occurred! {exception_message}
Example Request
cURL
curl -X POST http://127.0.0.1:5001/train \
-H "Content-Type: application/json" \
-d '{
"folderPath": "/home/user/fraud_detection/training_data"
}'
Python (requests)
import requests
url = "http://127.0.0.1:5001/train"
payload = {
"folderPath" : "/home/user/fraud_detection/training_data"
}
response = requests.post(url, json = payload)
print (response.text)
JavaScript (fetch)
fetch ( 'http://127.0.0.1:5001/train' , {
method: 'POST' ,
headers: {
'Content-Type' : 'application/json' ,
},
body: JSON . stringify ({
folderPath: '/home/user/fraud_detection/training_data'
})
})
. then ( response => response . text ())
. then ( data => console . log ( data ));
Error Handling
The endpoint handles the following error cases:
Raised when the provided folder path or data format is invalid. Error Occurred! <class 'ValueError'>
Raised when the required folderPath parameter is missing from the request body. Error Occurred! <class 'KeyError'>
Catches any other exceptions during the training process and returns the specific error message. Error Occurred! {specific_error_message}
Implementation Details
The endpoint implementation from main.py:64-92:
@app.route ( "/train" , methods = [ 'POST' ])
@cross_origin ()
def trainRouteClient ():
try :
if request.json[ 'folderPath' ] is not None :
path = request.json[ 'folderPath' ]
train_valObj = train_validation(path)
train_valObj.train_validation()
trainModelObj = trainModel()
trainModelObj.trainingModel()
except ValueError :
return Response( "Error Occurred! %s " % ValueError )
except KeyError :
return Response( "Error Occurred! %s " % KeyError )
except Exception as e:
return Response( "Error Occurred! %s " % e)
return Response( "Training successfull!!" )