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
Deployment steps:
-
Sign up for a free Azure account and create an Azure Subscription.
-
Install the Azure Developer CLI. (If you open this repository in Codespaces or with the VS Code Dev Containers extension, that part will be done for you.)
-
Login to Azure:
azd auth login
-
Provision and deploy all the resources:
azd up
It will prompt you to provide an
azd
environment name (like "modelfunc"), select a subscription from your Azure account, and select a location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. -
When
azd
has finished deploying, you'll see an endpoint URI in the command output. -
When you've made any changes to the app code, you can just run:
azd deploy
If you have any issues going through this repository, you can use the Discussions tab on this repo.