posted 7 years ago
I am in the process of implementing a decision tree for a machine learning course. I am given a 2D ArrayList where each row describes an instance (set of attributes with a given classification) for training my decision tree. Each column is a particular attribute, all attributes are real-valued doubles, and the last column is a binary classification (either a 0 or a 1). What I need help with is sorting my 2D ArrayList by 1 attribute at a time. I want the entire row to be moved along with the attribute it's being sorted by.
For example:
[ 9, 8, ... , 0]
[ 3, 2, ... , 1]
[ 4, 1, ... , 1]
[ 5, 6, ... , 0]
first time it's sorted (i.e sort by the first attribute):
[ 3, 2, ... , 1]
[ 4, 1, ... , 1]
[ 5, 6, ... , 0]
[ 9, 8, ... , 0]
after sorting on the first attribute (column) I will perform a set of operations with this data. Then I need to sort it by the second attribute, third attribute, ... nth attribute. I do not want to sort by the final column because this stores classifications, not attributes.
If anyone could lead me in the correct direction for the sorting behavior it would be greatly appreciated! Please let me know if you need any further clarifications.