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

ValueError from Deployed Function #418

Closed ascherer587 closed 4 years ago

ascherer587 commented 4 years ago

Hello. I have successfully deployed a few models from Jupyter in the past, but for some reason I am running into an issue for this one. I am trying to make a classification model that will provide assign a probability value for the risk of a loan. The error I am getting is "Length of values does not match length of index." I have tested the function in Jupyter, and it runs fine. It also returns the same length of values as the number of loans in the data set in that exists Tableau. I have been stuck on this for over a day now, and I appreciate any insight.

image

0golovatyi commented 4 years ago

@ascherer587 It seems like the error message is for the pandas dataframe - https://stackoverflow.com/questions/42382263/valueerror-length-of-values-does-not-match-length-of-index-pandas-dataframe-u.

ascherer587 commented 4 years ago

Thanks for the response. It works fine when I run I have tested it out. It doesn't work when called for the same data (even same number of data points) in Tableau.

image

0golovatyi commented 4 years ago

Tableau passes a collection of values for each argument, this is what may cause a difference:

ascherer587 commented 4 years ago

I actually had already come across those articles, but what you said made it something click. I am pretty sure it has to do with the values I am trying to pass through for the discrete variables arguments. So I updated my function definition to just have continuous arguments, updated the calculated field in Tableau to match, and it worked as it was supposed to in Tableau. However, I then added one discrete variable back in to the function and Tableau (aggregating with min), and I got the same error. Do you have any advice on how to bring in discrete variables from Tableau so I can assign a value from my function to each account? Again thanks so much for helping me understand this.

image

nmannheimer commented 4 years ago

Hey @ascherer587 given what you're describing I think there could be two possible issues here. One could be that the data in tableau are being passed as floats instead of ints which is messing up your scaler functions. The other could be that there are values in the discrete variables that show up in the data in Tableau but that are not in the training data for the scalers.

Are either of those scenarios possible?

ascherer587 commented 4 years ago

Hi @nmannheimer. And maybe but scenario number #2 of the discrete variable's values possibly being different is not. The SQL query used for training the model and what resides in Tableau are exactly the same. I just updated & retrained the model today, and I have a live connection in Tableau.

Scenario #1 could have been an issue, but I just updated all data types of the variables used in my Measures from decimal to whole. It still is throwing the same value error, even though it is running perfectly on my IDE. Was there a better way to address the data types in Tableau? Or do you have any other suggestions? Also would null values in Tableau have an impact?

0golovatyi commented 4 years ago

@ascherer587 For each parameter Tableau sends a collection and the size of the collections for all the parameters is the same. Null values are passed as None.

You can add parameter output for debugging purposes, but there may be something useful in TabPy log file for when the failure happens.

0golovatyi commented 4 years ago

@ascherer587 Were you able to solve your issue? Closing this one due to no update in a month.