This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import numpy as np | |
import StanfordSentiment | |
import matplotlib | |
import matplotlib.pyplot as plt | |
import time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A/B Testing: Conversion Rate: Distance between chi-squared distributions | |
from scipy.stats import chi2 | |
T = np.array([165, 165, 9835, 9835]) | |
O = np.array([150, 180, 9850, 9800]) | |
D = np.sum(np.square(T-O)/T) | |
pvalue = chi2.sf(D, df=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A/B testing: Z-test for Booking time (Normal Distribution) | |
from scipy.stats import norm | |
mu_A, std_A, n_A = 300, 105, 10000 | |
mu_B, std_B, n_B = 296, 120, 10000 | |
Z = (mu_A - mu_B)/np.sqrt(std_B**2/n_B + std_A**2/n_A) | |
pvalue = norm.sf(Z) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# REST API Service to get Price Predictions for Airbnb listings | |
@app.route("/predict", methods=["POST"]) | |
def predict(): | |
# initialize the data dictionary that will be returned from the view | |
data = {"success": False} | |
# ensure an image was properly uploaded to our endpoint | |
if flask.request.method == "POST": | |
data["predictions"] = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FLASK Webapp for serving price Predictions for Airbnb listings | |
import os, sys | |
sys.path.append(".") | |
import webapp_predict_price | |
import pickle | |
from flask import Flask | |
import flask | |
import sklearn | |
import joblib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FLASK Webapp for Image Segmentation Model | |
import os, sys, io | |
sys.path.append(".") | |
import webapp | |
from flask import Flask | |
import flask | |
import numpy as np | |
import pandas as pd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Serve Model predictions using REST API | |
# Predict and return JSON data | |
@app.route("/predict", methods=["POST"]) | |
def predict(): | |
# initialize the data dictionary that will be returned from the view | |
data = {"success": False} | |
# ensure an image was properly uploaded to our endpoint | |
if flask.request.method == "POST": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Saving Tensorflow models for serving | |
# Option 1: SavedModel format | |
# Save model | |
model.save('saved_model/model') | |
# Load model | |
loaded_model = tf.keras.models.load_model('saved_model/model') | |
# Option 2: .h5 format | |
# Save model |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model quantisation using TFLite | |
save_model_path = "/tmp/" | |
# Save original model in tflite format | |
tflite_models_dir = pathlib.Path(save_model_path) | |
tflite_models_dir.mkdir(exist_ok=True, parents=True) | |
converter = tf.lite.TFLiteConverter.from_keras_model(model) | |
tflite_model = converter.convert() | |
tflite_model_file = tflite_models_dir/"model.tflite" | |
print(tflite_model_file.write_bytes(tflite_model)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Tensorboard callbacks | |
# Log IoU at end of epoch | |
def log_epoch_metrics(epoch, logs): | |
# Log directory | |
logdir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") | |
file_writer = tf.summary.create_file_writer(logdir + "/fit") | |
file_writer.set_as_default() | |
# Intersection Over Union metric | |
m = tf.keras.metrics.MeanIoU(num_classes=len(LABEL_NAMES)) |
NewerOlder