Skip to Content
Learn Python by Building Data Science Applications
book

Learn Python by Building Data Science Applications

by Philipp Kats, David Katz
August 2019
Beginner
482 pages
12h 56m
English
Packt Publishing
Content preview from Learn Python by Building Data Science Applications

Setting up a simple model

Similar to how we built a REST API in Chapter 18, Serving Models with a RESTful API, let's start by serving median values from a JSON file. This will help us to set the model for working with Chalice:

  1. First of all, we need to load the JSON object:
import jsonwith open('./model.json', 'r') as f:    model = json.load(f)
  1. Now we will rename the route and define the last resource to map to the complaint type (in the same way we would for FastAPI, again!). We will also have to import a Response object:
from chalice import Response@app.route('/predict/{complaint_type}', methods=['GET'])def predict(complaint_type:str) -> Response:
  1. Finally, finalize the function by adding simple lookup logic; here, we decided to be ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for Data Science

Python for Data Science

Yuli Vasiliev
Introduction to Machine Learning with Python

Introduction to Machine Learning with Python

Andreas C. Müller, Sarah Guido

Publisher Resources

ISBN: 9781789535365Supplemental Content