Hello
Just started using Tabpy and tried to do a POC but somehow not getting desired results. Not sure if I am doing the right steps. I have attached the workbook.
So this is what I was trying
1. Read data from Wine data set.
2. Apply Linear regression model
Wine Analysis(Copy)
SCRIPT_REAL(
"
import numpy as np
from sklearn.externals import joblib
import pickle
import sklearn
from sklearn.linear_model import LinearRegression
X = np.array(_arg1)
Y = np.array(_arg2)
X = X.reshape(-1,1)
lreg = LinearRegression()
lreg.fit(X,Y)
pred = lreg.predict(X)
return pred.tolist()
" ,ATTR([Density]), ATTR([Alcohol])
)
3. Store the model by creating a calculated field (Wine Analysis)
SCRIPT_REAL(
"
import numpy as np
import pickle
import sklearn
from sklearn.linear_model import LinearRegression
X = np.array(_arg1)
Y = np.array(_arg2)
X = X.reshape(-1,1)
lreg = LinearRegression()
lreg.fit(X,Y)
filename = 'lnWineModel.sav'
file=open(filename,'wb')
pickle.dump(lreg,file )
file.close()
pred = lreg.predict(X)
return pred.tolist()
" ,ATTR([Density]), ATTR([Alcohol])
)
4. Read the model and use it using calculated field (WineTest). Passed Density and expected return for Alcohol data.
SCRIPT_REAL("
import numpy as np
import pickle
X = np.array(_arg1)
X = X.reshape(-1,1)
clf = pickle.load(open('lnWineModel.sav','rb'))
return clf.predict(X).tolist()
",ATTR([Density])
)
However only one value is getting returned.
Hi Kalidas,
It doesn't look like the workbook attached to the post here, but this may be an issue with how the table calculation is computed: you will want to address every point in the visualization.
This blog post contains helpful information on how to use Tableau's external services with Python:
Working with External Services in Tableau: Python, R, and MATLAB | Tableau Software
Sincerely,
Nathan
Become a Viz Whiz on the Forums!
Support the Community and master Tableau.