Skip to content

randomForest: How to append ID column along with predictions

4 messages · Liaw, Andy, Dennis Duro

#
Hi all,

When running a prediction using RF on another data, I get two columns
returned: row number(?) and predicted class. Is there a way of
appending the unique row value from an ID column in the dataframe to
the predictions instead of the row number? I'm assuming that the
returned results follow the data frame in that the first result
returned equals the first entry in the dataframe.

i.e., instead of a prediction output like this:

1, ants
2, ants
3, bees
4, ants

I'd like the first column to pull IDs from the dataframe associated
with each row (row number in parenthesis for illustration):

(1) 1130, ants
(2) 1130, ants
(3) 2139, bees
(4) 1130, ants

This is likely a simple procedure, but I haven't been able to get
anything to work. Any help would be appreciated!

Cheers,

Dennis
#
Hi all,

When running a prediction using RF on another data, I get two columns
returned: row number(?) and predicted class. Is there a way of
appending the unique row value from an ID column in the dataframe to
the predictions instead of the row number? I'm assuming that the
returned results follow the data frame in that the first result
returned equals the first entry in the dataframe.

i.e., instead of a prediction output like this:

1, ants
2, ants
3, bees
4, ants

I'd like the first column to pull IDs from the dataframe associated
with each row (row number in parenthesis for illustration):

(1) 1130, ants
(2) 1130, ants
(3) 2139, bees
(4) 1130, ants

This is likely a simple procedure, but I haven't been able to get
anything to work. Any help would be appreciated!

Cheers,

Dennis
#
The order in the output correspond to the order of the input.  I will
patch the code so that it grabs the row names of the input (if exist).
If you specify type="prob", it already labels the rows by the input row
names.
Notice:  This e-mail message, together with any attachme...{{dropped:11}}
#
Thanks for the confirmation Andy. It would be great if one could
specify a specific column as the unique ID to be returned and/or
display the input row, along with the predictions. Thanks for the
quick reply and looking forward to the patch!

Cheers,

Dennis
On Tue, Dec 7, 2010 at 12:00 PM, Liaw, Andy <andy_liaw at merck.com> wrote: