import tabpy_client
client = tabpy_client.Client('http://localhost:9004/')
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=1, min_samples=3).fit(X)
return db.labels_.tolist()
client.deploy('clustering',
clustering,
'Returns cluster Ids for each data point specified by the pairs in x and y')
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]
client.query('clustering', x, y)
ValueErrorTraceback (most recent call last)
in ()
2 y = [1.95, 1.95, 2.05, 3.05, 3.05, 3.10, 3.15]
3
----> 4 client.query('clustering', x, y)
/Tableau-Python-Server/lib/python2.7/site-packages/tabpy_client/client.pyc in query(self, name, *args, **kwargs)
187 uuid : a unique id for the request.
188 """
--> 189 return self._service.query(name, *args, **kwargs)
190
191 #
/Tableau-Python-Server/lib/python2.7/site-packages/tabpy_client/rest_client.pyc in query(self, name, *args, **kwargs)
151 return self.service_client.POST('query/'+name,
152 data={'data':args or kwargs},
--> 153 timeout=self.query_timeout)
154
155
/Tableau-Python-Server/lib/python2.7/site-packages/tabpy_client/rest.pyc in POST(self, url, data, timeout)
170 def POST(self, url, data=None, timeout=None):
171 """Prepends self.endpoint to the url and issues a POST request."""
--> 172 return self.network_wrapper.POST(self.endpoint + url, data, timeout)
173
174 def PUT(self, url, data=None, timeout=None):
/Tableau-Python-Server/lib/python2.7/site-packages/tabpy_client/rest.pyc in POST(self, url, data, timeout)
104 'content-type': 'application/json',
105 },
--> 106 timeout=timeout)
107 if response.status_code not in (200, 201):
108 self.raise_error(response)
/Tableau-Python-Server/lib/python2.7/site-packages/requests/sessions.pyc in post(self, url, data, json, **kwargs)
533 """
534
--> 535 return self.request('POST', url, data=data, json=json, **kwargs)
536
537 def put(self, url, data=None, **kwargs):
/Tableau-Python-Server/lib/python2.7/site-packages/requests/sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
486 }
487 send_kwargs.update(settings)
--> 488 resp = self.send(prep, **send_kwargs)
489
490 return resp
/Tableau-Python-Server/lib/python2.7/site-packages/requests/sessions.pyc in send(self, request, **kwargs)
607
608 # Send the request
--> 609 r = adapter.send(request, **kwargs)
610
611 # Total elapsed time of the request (approximately)
/Tableau-Python-Server/lib/python2.7/site-packages/requests/adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
407 raise ValueError(err)
408 else:
--> 409 timeout = TimeoutSauce(connect=timeout, read=timeout)
410
411 try:
/Tableau-Python-Server/lib/python2.7/site-packages/requests/packages/urllib3/util/timeout.pyc in init(self, total, connect, read)
92
93 def init(self, total=None, connect=_Default, read=_Default):
---> 94 self._connect = self._validate_timeout(connect, 'connect')
95 self._read = self._validate_timeout(read, 'read')
96 self.total = self._validate_timeout(total, 'total')
/Tableau-Python-Server/lib/python2.7/site-packages/requests/packages/urllib3/util/timeout.pyc in _validate_timeout(cls, value, name)
131 raise ValueError("Attempted to set %s timeout to %s, but the "
132 "timeout cannot be set to a value less "
--> 133 "than or equal to 0." % (name, value))
134 except TypeError: # Python 3
135 raise ValueError("Timeout value %s was %s, but it must be an "
ValueError: Attempted to set connect timeout to 0.0, but the timeout cannot be set to a value less than or equal to 0.