Data Preprocessing Using Orange

Dhwanipanjwani
4 min readSep 26, 2021

A guide to data preprocessing using Orange and how to use Python in Orange.

This blog will help you understand how to perform Data pre-processing using Orange, use the Orange library in Python, and integrate Python Scripts in Orange.

Guide To Use Orange in Python

Using Orange in Python is straightforward. To perform this task, I have used Google Colab. Firstly, we have to install Orange3 in our machines using:

Discretization

Data discretization is a method of converting a huge number of data values into smaller ones so that the evaluation and management of data become easy. In other words, data discretization is a method of converting attributes values of continuous data into a finite set of intervals with minimum data loss.

Here, I have taken the built-in dataset provided by Orange, namely housing.tab, which predicts house prices based on certain parameters. To perform discretization, we will be using Discretize function.

Continuization

Given a data table, return a new table where the discretize attributes are replaced with continuous or removed.

  • Binary variables are transformed into 0.0/1.0 or -1.0/1.0 indicator variables, depending upon the argument zero_based.
  • Multinomial variables are treated according to the argument multinomial_treatment.
  • Discrete attributes with only one possible value are removed.

Continuize_Indicators

The variable is replaced by indicator variables, each corresponding to one value of the original variable. For each value of the actual attribute, only the corresponding new attribute will have a value of one while that of others will be zero. This is the default behavior.

For example, as shown in the below code snippet, dataset “titanic” has featured “status” with values “crew”, “first”, “second” and “third”, in that order. Its value for the 10th row is “first”. Continuization replaces the variable with variables “status=crew”, “status=first”, “status=second” and “status=third”.

Normalization

Normalization is used to scale an attribute’s data so that it falls in a smaller range, such as -1.0 to 1.0 or 0.0 to 1.0. Normalization is generally required when dealing with attributes on a different scale; otherwise, it may dilute the effectiveness of a critical equally important attribute(on a lower scale) because of other attributes having values on a larger scale. We use the Normalize function to perform normalization.

Randomization

Using randomization on the given data table, the preprocessor returns a new table in which the data is shuffled. Randomize function is used from the Orange library to perform randomization.

Guide To Use Python Scripts In Orange

Python Script is this mysterious widget most people do not know how to use, even those versed in Python. Python Script is the widget that supplements Orange functionalities with (almost) everything that Python can offer.

We will try to replicate the work for Discretization using Python Script. As shown below, we will create two paths in the workflow; one will use the Discretize Widget and then give output; meanwhile, the other path will go to Python Script, where we will write the logic related to discretization.

Discretization using Python Script

Now, two different tables will be generated — one for each path. ‘Data Table’ has output after passing through the Discretize widget, and ‘Data Table (2)’ has the output after passing through the Python Script Widget.

As you can see above, both the Data Tables are similar. This helps in proving that by using Orange, we can also carry out Script Programming along with Visual Programming.

--

--