Prerequisites



Custom Data Function for TIBCO Spotfire? to Execute Python CodeVersion 1.2PrerequisitesThe following requirements must be met to enable running Python code from the data function extension:Spotfire 7.13 (or 7.14) client and serverLatest copy of SpotfirePS.DataFunctions.Python*.spkSpotfirePS.DataFunctions.PythonForms.*.spkA runtime python distribution (Preferred versions are 2.7.xx and 3.7.xx) installed in your local environment and the python executable file path listed in your PATH environment variable. By doing this, the Spotfire can automatically detect your python version and make use of the provided boilerplate python code.The packages used in the python code must be manually installed in your Python environment before calling it in the user code. The following packages Pandas, Numpy must be installed for the Python data function to work. Preferred Pandas version is Pandas 0.24.0 and aboveOther preferred Data Science packages are Scipy, Matplotlib, Scikit-learn, NLTK.InstallationIn order to add the Custom Data Function to the client software, the above packages must be deployed to a Spotfire server and the client software is needed to log into the deployment area containing the .spk’s in order to be updated. HYPERLINK "" \h See here for details.Running the Data FunctionSteps:Open up a Spotfire DXP with a data table in a Spotfire 7.13 client. The Spotfire client should be connected to a Spotfire server with the required packages installed in them.Go to Tools menu and click Register Data Functions to open a new data function window orGo to Edit menu, click Data Function Properties and again click Register New button to open a new data function windowName the script as desired.Copy and paste the script in the Script tab and make sure that the Python Engine drop down is set to the right python version.Paste “from Python_Data_Function import *“ as first line of your script. This piece of code will invoke the boilerplate code, which is a requirement to run the Python data function.Go to the Input Parameters tab, click the Add button, and add an input parameter with desired definitions.Go to the Output Parameters tab, click the Add button, and add an output parameter with desired definitions.Map the inputs parameters to the script and map the results from the script to the output parameters.Now that the script and its parameters are in place, click the Run button.? You may see a pop up asking if you would like to save to the library.? If you click No, nothing bad will happen.? It means that the data function will be saved in the DXP file as opposed to be saved in the file and the Spotfire library (if you have one).Example: Anomaly Detection using Isolation Forest for TIBCO Spotfire Python Data functionDescription:In this example, the python data function accepts an input table, and uses Isolation Forest algorithm to detect the outliers. The data function produces?a new column, "Prediction", that returns the anomaly score of each sample.See the included documentation, and examine this example?dxp file,?for more details.Script:from Python_Data_Function import *from sklearn import preprocessingfrom sklearn.ensemble import IsolationForestimport pandas as pdimport numpy as np#Analysis using IsolationForestcols = ['ProdPerMinute', 'Pressure', 'BaroPressure', 'WasteGas', 'LossOfEfficiency', 'SR', 'PowerIn', '1dp', '2dp', '3dp', '4dp', '5dp', '6dp']train = it[cols]scale = preprocessing.MinMaxScaler(feature_range=[0,1])X_train = pd.DataFrame(scale.fit_transform(train),columns = train.columns)Clf = IsolationForest(n_estimators=nEstimators, max_samples=MaxSamples,contamination=Contamination, bootstrap=True)clf.fit(X_train)it['Prediction'] = pd.DataFrame(clf.decision_function(X_train))ot = itInput Parameters:Python data function supports Column, Value and Table data types for input parameters.A value type is processed as a single value assigned to a variable that has the same input parameter name.A column type is converted into a dataframe with same name as input parameter name with a single column.A table is converted into a dataframe with same name as input parameter name.These inputs with assigned values can be readily used in the scripts using their input parameters name.Output Parameters:Python data function supports Column, Value and Table data types for output parameters. All the outputs must be mapped to its respective output parameters name in the user code and they are automatically converted to Spotfire types.KNOWN ISSUES:Timespan variable types in Spotfire are not supportedDatetime type columns with timestamps outside of supported pandas date ranges will fail due to a limitation in pandas. Timestamps should be in range 1678 and 2261 years. Boolean and Datetime type columns with missing values will be returned as string type due to a limitation in pandasInteger and long type columns with missing values will be returned as float type due to a limitation in pandas ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download