Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

IvanNardini

🏠
Working from home
View GitHub Profile
@IvanNardini
IvanNardini / ModelRegistration.py
Created Jun 7, 2020
MLOps series #2 : Deploy a Recommendation System as Hosted Interactive Web Service on AWS
View ModelRegistration.py
model_name = 'Champion'
artifact_path = "model"
model_uri = "runs:/{run_id}/{artifact_path}".format(run_id=run_id, artifact_path=artifact_path)
model_details = mlflow.register_model(model_uri=model_uri, name=model_name)
client = MlflowClient()
client.update_registered_model(
name=model_details.name,
description="This model provides recommendation for specific users and items based on purchase data. The data consists of user transactions"
@IvanNardini
IvanNardini / Model_tracker.py
Last active Jun 7, 2020
MLOps series #2 : Deploy a Recommendation System as Hosted Interactive Web Service on AWS
View Model_tracker.py
def reader(df):
"""
return a data parsed with Reader class
args:
df: pandas dataframe
returns:
data parsed
"""
mindata = df.rating.min()
maxdata = df.rating.max()
@IvanNardini
IvanNardini / Model_service_tree
Last active Jun 7, 2020
MLOps series #2 : Deploy a Recommendation System as Hosted Interactive Web Service on AWS
View Model_service_tree
└── src
└── score_interactive_endpoint
├── Dockerfile
├── app.py
├── callbacks.py
├── layouts.py
├── model
│   └── model_aa0lcc9j.pkl
├── requirements.txt
└── run.py
@IvanNardini
IvanNardini / callbacks.py
Last active Jun 7, 2020
MLOps series #2 : Deploy a Recommendation System as Hosted Interactive Web Service on AWS
View callbacks.py
'''
This module contains the predict callback
'''
from dash.dependencies import Input, Output
from app import *
@app.callback([Output('table', component_property='columns'), Output('table', component_property='data')],[Input(component_id='uid', component_property='value')])
def predict(uid):
columns = []
@IvanNardini
IvanNardini / layouts.py
Created Jun 7, 2020
MLOps series #2 : Deploy a Recommendation System as Hosted Interactive Web Service on AWS
View layouts.py
'''
This module contains the layout of the application
'''
import dash_table
import dash_core_components as component
import dash_html_components as html
#Customerid Input
c_id_component = component.Input(id="uid",
@IvanNardini
IvanNardini / run.py
Created Jun 7, 2020
MLOps series #2 : Deploy a Recommendation System as Hosted Interactive Web Service on AWS
View run.py
'''
This module runs the entire Dash Application
'''
import dash_table
import dash_core_components as component
import dash_html_components as html
from dash.dependencies import Input, Output
from app import *
@IvanNardini
IvanNardini / model_tracking.py
Created Jun 7, 2020
MLOps series #1 : Batch scoring with Mlflow Model (Mleap flavor) on Google Cloud Platform
View model_tracking.py
# Define tracking function
def log_lineareg(experimentID, run_name, params, abt_train, abt_test, debug=False):
"""
Function to start a run within a existing experiment
:param experimentID: unique ID associated to original experiment
:param run_name: label for the name of the run
:param params: ters used for the run, such as arguments
:param abt_train: analytical base table for training
:param abt_test: analytical base table for testing
@IvanNardini
IvanNardini / databricks_bash.txt
Created Jun 7, 2020
MLOps series #1 : Batch scoring with Mlflow Model (Mleap flavor) on Google Cloud Platform
View databricks_bash.txt
%sh
rm -rf /tmp/mleap_python_model_export
mkdir /tmp/mleap_python_model_export
ls -la /tmp/mleap_python_model_export
#Serialize Model to Bundle
lrModel.serializeToBundle("jar:file:/tmp/mleap_python_model_export/lrModel.zip", predictions)
%sh
ls -la /tmp/mleap_python_model_export/
dbutils.fs.cp("file:/tmp/mleap_python_model_export/lrModel.zip", "dbfs:/example/lrModel.zip")
display(dbutils.fs.ls("dbfs:/example"))
@IvanNardini
IvanNardini / setup.sh
Created Jun 7, 2020
MLOps series #1 : Batch scoring with Mlflow Model (Mleap flavor) on Google Cloud Platform
View setup.sh
#!/bin/bash
# setup.sh
# Create a bucket if doesn't exist.
# And load deployment scripts(.sh, .py)
# REGION - Region name (default eu)
# BUCKET - Bucker name (default cloud-demo-databrick-gcp)
#Pass REGION and BUCKET names (or use default parameters)
@IvanNardini
IvanNardini / setup_cluster.sh
Last active Jun 7, 2020
MLOps series #1 : Batch scoring with Mlflow Model (Mleap flavor) on Google Cloud Platform
View setup_cluster.sh
#!/bin/bash
# setup_cluster.sh
# Create a plain vanilla cluster if doesn't exist with config.
# REGION - Region name (default eu)
# BUCKET - Bucker name (default cloud-demo-databrick-gcp)
#Pass all parameters (or use default parameters)
CLUSTER_NAME=${1:-cluster-00000}
You can’t perform that action at this time.