tableau / TabPy

Execute Python code on the fly and display results in Tableau visualizations:
https://tableau.github.io/TabPy/
MIT License
1.56k stars 598 forks source link

ResponseError: (500) Error querying GLS #485

Closed msacs09 closed 3 years ago

msacs09 commented 3 years ago

deploys without any issues


import numpy as np
import pandas as pd
from sklearn.cluster import KMeans
from sklearn.preprocessing import MinMaxScaler
import tabpy_client

client=tabpy_client.Client('http://localhost:9004/')

def KMeansPlusPlus(_arg1,_arg2,_arg3):
    X=np.column_stack([_arg1,_arg2,_arg3])
    X_df=pd.DataFrame(X)
    norm=MinMaxScaler().fit(X_df)
    X_train_norm=norm.transform(X_df)

    km=KMeans(n_cluster=3, random_state=300, init='k-means++')
    kmeans_y=km.fit_predict(X_train_nrom)

    return kmeans_y.tolist()

client.deploy('KMeansPlusPlus', KMeansPlusPlus, 'Returns Cluster number based on  KMeans++ algorithm for 3 clusters', override = True)

Calling the endpoint results issue

_arg1 = [6,7,8,9]
_arg2 = [1,8,8,9]
_arg3 = [4,3,2,1]

client.query('KMeansPlusPlus', _arg1,_arg2,_arg3)

ResponseError: (500) Error querying GLS {'uri': 'KMeansPlusPlus', 'error': "AttributeError : 'TypeError' object has no attribute 'message'", 'type': 'QueryFailed'}
SCRIPT_REAL("return tabpy.query('KMeansPlusPlus',_arg1,_arg2,_arg3)['response']",
SUM([Profit]),SUM([Sales]),SUM([Quantity]))

Unable to complete action
An error occurred while communicating with the External Service.
Error Code: 6116DD27
Error processing script
The endpoint you're trying to query did not respond. Please make sure the endpoint exists and the correct set of arguments are provided.
msacs09 commented 3 years ago

@0golovatyi when you get a chance can you please look into this ?

nmannheimer commented 3 years ago

@msacs09 can you verify the function works before it's deployed?

Is there a typo at this line: X=np.colu,n_stack([_arg1,_arg2,_arg3])

msacs09 commented 3 years ago

@nmannheimer Thank you. continue to get error after fixing the typos... corrected my code above.. any idea on what exactly these error message is telling

   ~\Anaconda3\lib\site-packages\tabpy_client\rest_client.py in query(self, name, *args, **kwargs)
        149             raise ValueError('Mixing of keyword arguments and positional arguments '
        150                                 'when querying an endpoint is not supported.')

    ResponseError: (500) Error querying GLS {'uri': 'KMeansPlusPlus', 'error': "AttributeError : 'TypeError' object has no attribute 'message'", 'type': 'QueryFailed'}
nmannheimer commented 3 years ago

@msacs09 I think there's an issue with how you're invoking KMeans(). According to the sklearn docs, the argument should be n_clusters not n_cluster. (https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html)

You also have a typo here: kmeans_y=km.fit_predict(X_train_nrom) The table should be X_train_norm

When I fixed these issues, I was able to run your code without any issues. As a first step when deploying a function to TabPy, I'd suggest testing the function inside your IDE before deploying it. That way you can debug any issues before having to deal with the network errors, ie the 500 you're seeing.

nmannheimer commented 3 years ago

image

msacs09 commented 3 years ago

@nmannheimer Thank you for your time. Excellent support