This repository was built for a #30DaysOfDataScience talk that demonstrates how to build a regression model using sci-kit learn and then deploy it as an HTTP API to Azure Functions.
Technologies used: Jupyter notebook, pandas, scikit-learn, numpy, matplotlib, joblib, Azure functions, Azure Developer CLI, FastAPI
The slides are viewable online here: tinyurl.com/regression-slides
The slides are generated using a Github action that runs nbconvert
on notebook/index.ipynb
.
Locally, you can use RISE to view the notebook as slides.
The function
folder contains the code necessary to turn the pickled regression model into an Azure function:
__init__.py
: The main Python code that uses FastAPI to setup themodel_predict
API endpointcategories.py
: The values of the enums formodel_predict
(generated from thecategorical features
in the notebook)model.pkl
: The pickled regression modelfunction.json
: Configuration JSON needed for Azure functions
The function can be deployed using the Azure Developer CLI. The azd
CLI uses these files:
infra
:main.bicep
: Creates an Azure resource group and passes parameters toresources.bicep
resources.bicep
: Creates a Function App, Storage account, App Service Plan, Log Analytics workspace, and Application Insights.main.parameters.json
: Describes parameters needed formain.bicep
azure.yaml
: Describes which code to upload to the Function App
To deploy the code, download the azd
CLI and run:
azd up
It will prompt you to login and to provide a name (like "salary-model") and location (like "centralus"). Then it will provision the resources in your account (if they don't yet exist) and deploy the latest code.
When you've made any changes to the function, you can just run:
azd deploy
If you have any issues going through this repository, you can use the discussions tab on this repo or tweet at @pamelafox.