Specify the Python code on the Pre-Input and On Input tabs.
Use the Pre-Input tab to import libraries, load the resource file, and initialize variables.
For example, you might enter the following code on the Pre-Input tab:
from sklearn import svm
from sklearn.externals import joblib
import numpy as np
clf = joblib.load(resourceFileArrays[0])
classes = ['common', 'woolly']
On the On Input tab, define how the Python transformation uses the pre-trained model to evaluate each row of data.
For example, you might enter the following code on the On Input tab:
input = [sepal_length, sepal_width, petal_length, petal_width]
input = np.array(input).reshape(1,-1)
pred = clf.predict(input)
predicted_class = classes[pred[0]]
sepal_length_out = sepal_length
sepal_width_out = sepal_width
petal_length_out = petal_length
petal_width_out = petal_width
true_class_out = true_class
The Python transformation processes the data in the input ports according to the Python code and writes the data to the output ports.