Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I have a data set that is imbalanced and would like to weight the samples to compensate, however I can't find code to implement this in R though I believe there is a feature in the randomForest package to do this.

Here's a sample dataset :

id      buy=1/noBuy=0    timeOnSite(sec.)     clicksOnSite      estAge
1             0              150                   12             44
2             0              342                   56             23
3             0               33                   11             18
4             1              167                   34             27
5             0               95                    3             52
6             0              254                   98             26
7             0              982                    4             36
8             0               72                    6             22
9             1              259                   62             48
10            0              438                  104             24
...

I'm trying to predict the buy/noBuy column but the real data is even more imbalanced than this. Anyone know of an example written in R to deal with a similar situation?

share|improve this question

1 Answer

up vote 1 down vote accepted

Ok, so I found part of my answer but not the good part. It turns out the randomForest package can do stratified sampling but only for classification. Here is a link to the package author's explanation.

I'm still looking for ideas on how to do stratified sampling for regression rf's.

share|improve this answer
This question confuses me - are you looking for a general way to do stratified sampling for regression forests (hard, because there's no obvious classes to weight), or is it for this problem in particular? This problem looks very much like a straight-up binary classification problem, in which case all you need to do is convert your buy/noBuy column to a factor. – Martin O'Leary Mar 20 '12 at 23:27
@MartinO'Leary: I'm not sure how well the question is posed but I was looking ideally for a way to do stratified sampling for both regression and classification. I just used a simple classification problem to write the question. I do some work with securities prices where a large portion of the securities move in a small range and a small percentage have large ranges and was curious whether strat.samp. might help. – screechOwl Mar 21 '12 at 1:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.