Splitting polygon dataset

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Splitting polygon dataset

Enoch Gyamfi Ampadu
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: [hidden email] <[hidden email]>*


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

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

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Splitting polygon dataset

Bede-Fazekas Ákos
Dear Enoch,

There is a typo in your code that causes the error: function c() is not
equivalent of C().
Solution:
id <- sample(2, nrow(dfTrainshape), prob = c(0.7, 0.3), replace = TRUE)

HTH,
Ákos Bede-Fazekas
Hungarian Academy of Sciences

2019.08.23. 12:17 keltezéssel, Enoch Gyamfi Ampadu írta:

> 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
>
>

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo