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:
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.
Hi Myrto,
[n clusters] is a Parameter (just a single value),
so the _arg5[1] could be written in the calc:
...
db=KMeans(n_clusters=_arg5[1]).fit(X)
...
Yours,
Yuri
Become a Viz Whiz on the Forums!
Support the Community and master Tableau.