0 Replies Latest reply on Oct 26, 2018 10:17 AM by Kalidas Shetty

    Tabpy POC

    Kalidas Shetty

      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.