-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModel Deployment.py
More file actions
42 lines (35 loc) · 1.39 KB
/
Model Deployment.py
File metadata and controls
42 lines (35 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Import tabpy client for deployment
from tabpy.tabpy_tools.client import Client
# Server URL (This would be the host and port on which you are running the TabPy server)
client = Client('http://localhost:9004/')
# Define the function tested above
def clustering(x, y):
import numpy as np
from sklearn.cluster import DBSCAN
from sklearn.preprocessing import StandardScaler
X = np.column_stack([x, y])
X = StandardScaler().fit_transform(X)
db = DBSCAN(eps=0.3, min_samples=3).fit(X)
return db.labels_.tolist()
# Deploy the model to TabPy server
# Add Override = True if you are deploying the model again
client.deploy('clustering', clustering,
'Returns cluster Ids for each data point specified by the pairs in x and y')
"""
Check if the model is model is deployed on the TabPy server at the URL below:
Server URL (This would be the host and port on which you are running the TabPy server):
http://localhost:9004/endpoints
"""
# Sample Data
x = [6.35, 6.40, 6.65, 8.60, 8.90, 9.00, 9.10]
y = [1.95, 1.95, 2.05, 3.05, 3.05, 3.10, 3.15]
# Test the deployed model
print(client.query('clustering', x, y))
# Tableau code for calculated field:
# SCRIPT_INT("
# return tabpy.query('clustering', _arg1, _arg2)['response']
# ",
# SUM([Profit]), SUM([Sales])
# )
# To delete the deployed model from TabPy server
# client.remove('clustering')