Skip to content

Instantly share code, notes, and snippets.

044865cb6f588c41fbcaad474ae636f2a57e8dcb4e514eb9ac93cc8f063016c167814032c2461b2050878e5d9b867722fe93ceeb85c873cec8d0f01fd40bde81b8;rogererill
@afranzi
afranzi / IamAuthenticator.scala
Created June 19, 2018 15:00
Presto - IamAuthenticator
/*
* Copyright (c) 2018 Schibsted Media Group. All rights reserved
*/
package com.saas.presto.access.authentication
import java.security.Principal
import java.util.concurrent.TimeUnit.MILLISECONDS
import com.facebook.presto.spi.security.{AccessDeniedException, BasicPrincipal, PasswordAuthenticator}
import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache}
@afranzi
afranzi / gen_config.py
Created June 20, 2018 08:03
Jinja2 - Config Template
import argparse
import errno
import os
import sys
from jinja2 import Environment, FileSystemLoader, StrictUndefined
UTF8 = 'utf8'
TEMPLATE = 'template'
@afranzi
afranzi / SetupMLflow.md
Last active October 23, 2018 21:24
Setting up MLflow
pyenv install 3.7.0
pyenv global 3.7.0 # Use Python 3.7
mkvirtualenv mlflow # Create a Virtual Env with Python 3.7
workon mlflow

Install required libraries.

pip install mlflow==0.7.0 \
# Running a Tracking Server
mlflow server \
--file-store /tmp/mlflow/fileStore \
--default-artifact-root s3://<bucket>/mlflow/artifacts/ \
--host localhost
--port 5000
@afranzi
afranzi / runWineModel.sh
Created October 23, 2018 21:30
Launch wine quality prediction model with MLflow.
MLFLOW_TRACKING_URI=http://localhost:5000 python wine_quality.py \
--alpha 0.9
--l1_ration 0.5
--wine_file ./data/winequality-red.csv
@afranzi
afranzi / wineModelLogging.py
Created October 23, 2018 21:34
Log model by using the MLflow Tracking Server
with mlflow.start_run():
... model ...
mlflow.log_param("source", wine_path)
mlflow.log_param("alpha", alpha)
mlflow.log_param("l1_ratio", l1_ratio)
mlflow.log_metric("rmse", rmse)
mlflow.log_metric("r2", r2)
@afranzi
afranzi / sklearnServe.sh
Last active October 23, 2018 22:06
# Serve a sklearn model through 127.0.0.0:5005
# Serve a sklearn model through 127.0.0.0:5005
MLFLOW_TRACKING_URI=http://0.0.0.0:5000 mlflow sklearn serve \
--port 5005 \
--run_id 0f8691808e914d1087cf097a08730f17 \
--model-path model
@afranzi
afranzi / wineQualityPredictionCurl.sh
Created October 23, 2018 21:46
# Query Tracking Server Endpoint
# Query Tracking Server Endpoint
curl -X POST \
http://127.0.0.1:5005/invocations \
-H 'Content-Type: application/json' \
-d '[
{
"fixed acidity": 3.42,
"volatile acidity": 1.66,
"citric acid": 0.48,
"residual sugar": 4.2,
@afranzi
afranzi / PySparkJupyter.md
Last active May 16, 2019 08:47
Setup PySpark with Jupyter notebooks

Start by downloading the latest stable Apache Spark (current 2.4.3).

cd ~/Downloads/
tar -xzf spark-2.4.3-bin-hadoop2.7.tgz
mv ~/Downloads/spark-2.4.3-bin-hadoop2.7 ~/
ln -s ~/spark-2.4.3-bin-hadoop2.7 ~/spark̀

Install PySpark and Jupyter in our virtualEnv