0

I have mapped an area using object-based image analysis. This has resulted in 2000 image objects (polygons) that I want to classify based on their properties (spectral, RGB data, shape, size etc.).

I have saved the data as a .csv for use in 'Randomforest' package.

I have assigned "Habitat Level" as one of six factors for each object in the data (1, 2, 3, 4, 5,6). Example of the csv attached.

data used for randomforest, csv

What I want to do is run randomforest to predict a "Habitat_Level" to each of the image objects (Column: OBJECT_ID).

So the result I need will fill the "PREDICTED" column with "Habitat_Level" (generated from random forest) that uses the OBJECT_ID to discriminate between objects.

I have run the randomforest but I don't know how to assign the classification to existing OBJECT_ID

Any advice would be greatly appreciated

Thanks

Benja1987
  • 3
  • 2
  • It looks like you're new to SO; welcome to the community! If you want great answers quickly, make your question reproducible. This includes sample code you've attempted, non-base R packages that you are using or that you plan on using, any errors/warnings received, and sample data, like the output from `dput(head(dataObject)))` (not an attachment). Check out these resources for great questions: [making R questions reproducible](https://stackoverflow.com/q/5963269). There are hundreds of packages with a random forest model–you said you've already tried to run one. Which package did you use? – Kat Mar 08 '22 at 05:12

1 Answers1

0

You need to use the predict function to generate predictions for each row in your dataset.

It's hard to give some code without seeing the code you've used so far, and a cut of your data, but something like this should work:

data$PREDICTED <- predict(yourmodel, data)
rw2
  • 1,549
  • 1
  • 11
  • 20
  • Thanks for the response, this is great. I worked out how to commit the OBJECT_ID to being the unique identifier and now with your help I can populate the PREDICTED field with RF data from R Much appreciated. – Benja1987 Mar 09 '22 at 02:22