Icon

03_​Include_​Custom_​Python_​Class_​in_​Workflow

Include Python Custom Class defined by user inside KNIME Workflow

This workflow showcases the usage of custom class inside KNIME. The user has to define the custom python class in a (.py) file and place it inside the workflow directory. The Python Script node can access this custom class and use it for execution.

In this example, we define a python custom class for normalising data and encoding taregt column, this class file (.py) is placed inside the workflow directory. Inside the Python Script node we use this python class for normalising input data and encodinmg target column supplied at second input port

Read Tables Data Preparation Normalise Data and Encode Target Column Configure the Python Script node for using Custom Class defined by theuserThe user can define the custom class in a .py file and place it in the workflow directory. ThePython Script node can read this class from the worklfow directory and use it for execution.Step 1: Drag the Python Script node to KNIME Analytics PlatformStep 2: Place the Custom class definition file .py in the workflow directoryThe path to the workflow directory in your system is: Windows OS : C:/users/KNIME Workspace name/Workflow name (by default)MacOS : /Users/<username>/KNIME Workspace name/Workflow name (by default)Step 3: Write your script in the "Script" tab that imports the custom class and press "executescript" to understand if the execution was successful. Adopting Python Bundled Packages : Download and open this workflow to auto-install requirements and execute the Python scripts. This workflow uses a node from KNIME Python Integration, which installs Pythonand a number of pre-defined packages on your system. Supported on KNIME Analytics Platform 4.7 or higher. FeaturesPass NumericColumnsInput Port 0: Features Port 1: Target ColumnOutput Port 0: Normalised data Port 1: Encoded Target columnTarget ColumnTable Reader Missing Value Column Filter Python Script Table Reader Read Tables Data Preparation Normalise Data and Encode Target Column Configure the Python Script node for using Custom Class defined by theuserThe user can define the custom class in a .py file and place it in the workflow directory. ThePython Script node can read this class from the worklfow directory and use it for execution.Step 1: Drag the Python Script node to KNIME Analytics PlatformStep 2: Place the Custom class definition file .py in the workflow directoryThe path to the workflow directory in your system is: Windows OS : C:/users/KNIME Workspace name/Workflow name (by default)MacOS : /Users/<username>/KNIME Workspace name/Workflow name (by default)Step 3: Write your script in the "Script" tab that imports the custom class and press "executescript" to understand if the execution was successful. Adopting Python Bundled Packages : Download and open this workflow to auto-install requirements and execute the Python scripts. This workflow uses a node from KNIME Python Integration, which installs Pythonand a number of pre-defined packages on your system. Supported on KNIME Analytics Platform 4.7 or higher. FeaturesPass NumericColumnsInput Port 0: Features Port 1: Target ColumnOutput Port 0: Normalised data Port 1: Encoded Target columnTarget ColumnTable Reader Missing Value Column Filter Python Script Table Reader

Nodes

Extensions

Links