Skip to content

Instantly share code, notes, and snippets.

@navarasu
Last active October 13, 2019 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navarasu/bcf3c6481e87f698f18a2be3a278bbe5 to your computer and use it in GitHub Desktop.
Save navarasu/bcf3c6481e87f698f18a2be3a278bbe5 to your computer and use it in GitHub Desktop.
Utils for training and prediction
import numpy as np
import boto3
import os
import joblib
def getModel():
bucket=os.getenv("BUCKET_NAME")
S3 = boto3.client('s3')
model_file=os.getenv("MODEL_FILE_NAME")
response = S3.download_file(bucket,model_file,model_file)
return joblib.load(model_file)
def upload_model_to_s3(value):
s3 = boto3.client('s3')
bucket=os.getenv("BUCKET_NAME")
file_name=os.getenv("MODEL_FILE_NAME")
joblib.dump(value,file_name)
s3.upload_file(file_name, bucket,file_name)
print("Uploaed sucessfully modal "+file_name+" to "+bucket)
def encode_events(COLUMNS_NAMES,data):
value=np.zeros(len(COLUMNS_NAMES),dtype=int)
for service_id, vendor_id in data:
key=str(service_id)+"_"+str(vendor_id)
if key in COLUMNS_NAMES:
value[COLUMNS_NAMES[key]]=1
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment