Here I will go through a very simple example of how you can use flask to act as an endpoint for a ML application.
For this project we require a Python version >=3.6
python -m venv venv
source venv/bin/activate
pip install -r requirements
To run the application it is pretty simple.
python app.py
There are two forms of request that can be processed by the application.
To train a model you will need to provide:
model_type
This is the type of model you want to train. ['LogisticRegression', 'RandomForest', 'SVC', 'DecisionTree']X
The data to train on. (Frompd.DataFrame.to_dict
)y
The associated label. (Frompd.DataFrame.to_dict
)
This will need to be sent to the application as a json.
The app will return the associated model_id
for the newly created model.
To generate the prediction from a previously trained model you will need:
model_id
The id of the model to generate the prediction.data
The data to predict. (Frompd.DataFrame.to_dict
)
This will need to be sent to the application as a json.
The application will then return the predictions and the probabilities for each of the data points sent.