[R-sig-Geo] Splitting polygon dataset

Enoch Gyamfi Ampadu eg@mp@du @end|ng |rom gm@||@com
Fri Aug 23 12:17:26 CEST 2019


Dear List,

Please I have been implementing Random Forest in R for the to classify
forest cover. I am doing it for 4 main classes. I Have extracted the pixel
values of the bands with that of the training polygons. In all I had 226
observations and the 8 bands as the response variables.

I tried to split it into 70% for training set and 30% for as testing set
sing the codes below;

#setting training and testing samples
set.seed(999)

id <- sample(2, nrow(dfTrainshape), prob = C(0.7, 0.3), replace = TRUE)
dfTrainshape_train <- dfTrainshape[id==1,]
dfTrainshape_test <- dfTrainshape[id==2,]

I had the error below;

set.seed(999)
> id <- sample(2, nrow(dfTrainshape), prob = C(0.7, 0.3), replace = TRUE)
Error in C(0.7, 0.3) : object not interpretable as a factor
> dfTrainshape_train <- dfTrainshape[id==1,]
Error in `[.data.frame`(dfTrainshape, id == 1, ) : object 'id' not found

I will be glad to have some advice and probable some code to assist me.

Secondly,

Please I also want to create a separate testing polygons for the validation
in ArcMap. I want to know how I will be able to use the 226 observations of
the earlier set of polygons for the training and the new polygons for
validation. I will be glad to have some codes which I can change to suite
what I want to do.

Hope to hear from you.

Best regards,

Enoch


-- 
*Enoch Gyamfi - Ampadu*

*Geography & Environmental Sciences*

*College of Agriculture, Engineering & Science*

*University of KwaZulu-Natal, Westville Campus*

*Private Bag X54001*
*Durban, South Africa **– 4000**.*
*Phone: +27 835 828255*

*email: egampadu using gmail.com <egampadu using gmail.com>*


*skype: enoch.ampadu*
*The highest evidence of nobility is self-control*.

*A simple act of kindness creates an endless ripple*.

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list