Skip to content

Instantly share code, notes, and snippets.

View mnguyenngo's full-sized avatar

Nguyen Ngo mnguyenngo

View GitHub Profile
@mnguyenngo
mnguyenngo / min_sample_size.py
Last active January 27, 2024 14:40
Determine Minimum Sample Size for A/B test
import scipy.stats as scs
def min_sample_size(bcr, mde, power=0.8, sig_level=0.05):
"""Returns the minimum sample size to set up a split test
Arguments:
bcr (float): probability of success for control, sometimes
referred to as baseline conversion rate
mde (float): minimum change in measurement between control
@mnguyenngo
mnguyenngo / zscore.py
Last active August 1, 2024 19:58
Code to calculate and plot the z-score
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as scs
def z_val(sig_level=0.05, two_tailed=True):
"""Returns the z value for a given significance level"""
z_dist = scs.norm()
if two_tailed:
sig_level = sig_level/2
area = 1 - sig_level
@mnguyenngo
mnguyenngo / read_yaml.py
Last active August 31, 2018 00:50
Reading a yaml file
import yaml
with open("apikey.yaml", 'r') as f:
try:
credentials_dict = yaml.load(f)
except yaml.YAMLError as exc:
print(exc)
@mnguyenngo
mnguyenngo / nginx-quickstart.sh
Last active August 24, 2018 19:45
Typical workflow for nginx on a new VM
# update the virtual machine
sudo apt-get update
# install nginx
sudo apt-get install nginx
# check version
sudo nginx -v
# start the nginx service
@mnguyenngo
mnguyenngo / docker-quickstart.sh
Last active August 24, 2018 20:21
Typical workflow for starting docker on a new VM
# install docker
sudo apt-get install docker
# the above command did not work (8/24/18); try the command below
sudo curl -sSL https://get.docker.com/ | sh
# pull nginx image
sudo docker pull nginx:1.10.0
sudo docker images
# verify the versions match
@mnguyenngo
mnguyenngo / docker-image.sh
Last active August 24, 2018 21:11
Typical workflow for creating a Docker image and pushing the image to docker hub
"""simple Dockerfile
FROM alpine:3.1 # starter image (typical)
MAINTAINER <name> <email>
ADD hello /usr/bin/hello # ADD <bin> <path-on-image>
ENTRYPOINT ["hello"] # run hello app on startup
"""
# install GO
wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz
rm -rf /usr/local/bin/go
@mnguyenngo
mnguyenngo / docker-push.sh
Created August 24, 2018 22:25
Typical workflow for pushing docker images to a remote repository
# see all images
sudo docker images
# docker tag command help
docker tag --help
# add your tag to the image
sudo docker tag monolith:1.0.0 <your username>/monolith:1.0.0
# you can also rename the image
sudo docker tag monolith:1.0.0 udacity/example-monolith:1.0.0
@mnguyenngo
mnguyenngo / plac_quickstart.rst
Last active September 20, 2018 22:47
Implementing plac

plac Quickstart

plac makes parsing arguments from the command line easy.

plac Documentation: https://micheles.github.io/plac/


This short guide will only cover the decorator function plac.annotations().

@mnguyenngo
mnguyenngo / plot.py
Created August 31, 2018 18:06
Center histogram bars on corresponding x-label when plotting from Pandas dataframes
# set bins to the (number of bins + 1) - 0.5 to center the bar on the right x-label
df['col_name'].hist(xrot=90, figsize=(12,6), rwidth=0.5, bins=np.arange(9)-0.5)
@mnguyenngo
mnguyenngo / api.py
Created August 31, 2018 18:51
Sentiment Classifier as REST API
from flask import Flask
from flask_restful import reqparse, abort, Api, Resource
import pickle
import numpy as np
from model import NLPModel
app = Flask(__name__)
api = Api(app)
model = NLPModel()