1 Reply Latest reply on Apr 29, 2018 4:52 AM by Yuriy Fal

    Tableau and Python Integration

    Myrto Dima

      Hi!

      I am trying to conduct a clustering analysis using  Python- Tableau integration and I am having an issue when using a parameter in a Python script inside Tableau Desktop.

      This is the calculated field for K means:

       

      SCRIPT_INT("
      import numpy as np
      from sklearn.cluster import KMeans
      from sklearn.preprocessing import StandardScaler
      x=np.column_stack([_arg1, _arg2,_arg3,_arg4])
      X=StandardScaler().fit_transform(x)

      db=KMeans(n_clusters=_arg5).fit(X)
      return db.labels_.tolist()

      ", SUM(["Petal.Length"]), SUM(["Petal.Width"]),
      SUM(["Sepal.Length"]),SUM(["Sepal.Width"]), [n clusters]
      )

       

      [n clusters] is an integer parameter which I want to be interactive.

       

      This code gives me the following error:

       

      • An error occurred while communicating with the Predictive Service.
      • Error processing script
      • TypeError : %d format: a number is required, not list

       

      Is there a solution to this problem? I have also tried the same thing with R and doesn't work.

       

      Please find attached a demo .twbx file.