Here's a process that finds the upper, middle and lower quartiles of a real valued special attribute within an example set and discretizes all the real values into the corresponding bins. It assumes there is one special attribute only. Additional special attributes would need to be de-selected as an extra step before being processed.
The process works as follows. After sorting the example set, it uses various macro extraction and manipulation operators to work out how many examples there are, determine the index corresponding to the quartile locations and from there the values of the attributes at these locations. These values are set as macros that are used in the "Discretize by User Specification" operator as boundaries between the quartile ranges in order to place each example into the correct bin.
The main work happens in a subprocess which makes the process easier to read and allows the operators to be moved to other processes more easily. The very useful operator "Rename by Generic Names" is used. This allows the macro manipulation operators to work without having to be concerned about the name of the special attribute which again allows the operators to be more portable when used in other processes.
Search this blog
Showing posts with label Discretize. Show all posts
Showing posts with label Discretize. Show all posts
Thursday, 9 July 2015
Wednesday, 13 February 2013
Sorting discretized examples in the order nature intended
Using the "Discretize" operators puts examples into different nominal bins depending on the value of an attribute. When using the long form of the name type, the possible nominal value names are of this general format "rangeN [x-y]"
N starts at 1 and ends at whatever the largest bin number is. The N is not preceded by any leading zeros so this means that when sorted, range10 comes before range2. When using the histogram plotter this is OK because the nominal values have an implicit order that gets used. When using the advanced plotter however, a histogram comes out wrong.
Here's a histogram, produced using the advanced plotter, showing the original ordering. The data is 10,000 examples generated by multiplying 5 random numbers together and normalizing to the range 0 to 1.
As can be seen, the ordering of the bins is not in the same numerical order of the underlying numerical values.
This can be fixed by using regular expressions and the "Replace" operator.
I'm not enough of a regular expression ninja to do this in one operator so I had to use two.
So, in the first "Replace" operator, set the "replace what" field to
In the second "Replace" operator, set the replace field to
Be aware that you might have to tweak these numbers if the number of names is different in your case.
The end result is then a histogram like this
Now the ordering is the same as the implied numerical ordering.
N starts at 1 and ends at whatever the largest bin number is. The N is not preceded by any leading zeros so this means that when sorted, range10 comes before range2. When using the histogram plotter this is OK because the nominal values have an implicit order that gets used. When using the advanced plotter however, a histogram comes out wrong.
Here's a histogram, produced using the advanced plotter, showing the original ordering. The data is 10,000 examples generated by multiplying 5 random numbers together and normalizing to the range 0 to 1.
As can be seen, the ordering of the bins is not in the same numerical order of the underlying numerical values.
This can be fixed by using regular expressions and the "Replace" operator.
I'm not enough of a regular expression ninja to do this in one operator so I had to use two.
So, in the first "Replace" operator, set the "replace what" field to
range(\d+.*)and set the replace by field to
range0000$1This will change all the values to have leading zeros inserted before the number within the value.
In the second "Replace" operator, set the replace field to
range0+(\d{4})(.*)and set the replace by field to
range$1$2This ensures that all the numeric parts of the range name are of the same length and are preceded by at least one leading 0.
Be aware that you might have to tweak these numbers if the number of names is different in your case.
The end result is then a histogram like this
Now the ordering is the same as the implied numerical ordering.
Labels:
AdvancedPlotter,
Discretize,
RegularExpression,
Replace
Wednesday, 16 March 2011
Discretize by user specification: an example
The Discretize By User Specification operator allows numerical attributes to be placed in bins where the boundaries of the bins are defined by the user. This converts numerical attributes into nominal ones as required by some algorithms.
The following shows some example settings for the operator
The class names show the equality tests. The order of the list is important. The first entry must be the biggest, the last the smallest. Anything lower than the smallest entry is automatically less than "-Infinity". The upper case I on Infinity is important.
These example settings on a small example set are shown below.
The attribute "Copy of att1" is simply a copy of att1 before the discretization.
The following shows some example settings for the operator
The class names show the equality tests. The order of the list is important. The first entry must be the biggest, the last the smallest. Anything lower than the smallest entry is automatically less than "-Infinity". The upper case I on Infinity is important.
These example settings on a small example set are shown below.
The attribute "Copy of att1" is simply a copy of att1 before the discretization.
Subscribe to:
Posts (Atom)



