Skip to content

Instantly share code, notes, and snippets.

View achad4's full-sized avatar

Avi Chad-Friedman achad4

View GitHub Profile
import ...
import fire
class CustomerModel(BaseModel):
def __init__(self):
super().__init__()
def train_model(lookback_days=30: int):
@achad4
achad4 / batch_customer_ml_inference_with_dynamodb.py
Created February 5, 2023 16:44
Example code for batch ML inference from DynamoDB using GSI
import boto3
from datetime import datetime
import numpy as np
from fastapi import FastAPI
app = FastAPI()
dynamodb = boto3.resource("dynamodb")
s3 = boto3.client('s3')
import boto3
dynamodb = boto3.resource("dynamodb")
params = {
'TableName': "customer_purchase_ts",
"KeySchema": [
{"AttributeName": "customer_id", "KeyType": "HASH"},
{"AttributeName": "transaction_date_epoch", "KeyType": "RANGE"}
],
import boto3
dynamodb = boto3.resource("dynamodb")
params = {
"TableName": "customer_purchase_ts",
"KeySchema": [
{"AttributeName": "customer_id", "KeyType": "HASH"}
],
"LocalSecondaryIndexes": [
/*
purchase table example
transaction_date | customer_id | purchase_price | category
2022-01-01 customer_A $10 jewelry
2022-01-02 customer_A $1 t-shirts
...