resampling an unbalanced dataset

3 次查看(过去 30 天)
Hi, I have a dataset which has 2 classes(churn='False.' and churn='True.'). It is unbalanced because 700 of the 5000 sample is churn='False.' Is there a way to balance that distribution? Thank you in advance.

采纳的回答

Image Analyst
Image Analyst 2015-1-3
Throw out all but 700 items where churn = true??? Then you'd have 700 false ones and 700 true ones. If not, then tell us in more detail what "balance" means to you.
  3 个评论
Ege
Ege 2015-1-3
I have 700 churn=False which means remaining 4300 belongs to the other class (churn=True). so do you mean I should do it manually like delete the 3600 of the 4300 and create 700 & 700 balanced data?
Image Analyst
Image Analyst 2015-1-3
Uh, sure, if that's what you want. If it's in a table, you can automate it somewhat, like
% Find out which rows are true.
trueRows = find(t.churn);
% Take only the first 700:
trueRows = trueRows(1:max([length(trueRows), 700]));
% Find out which rows are false - we want to keep all those.
falseRows = find(t.churn == false);
% Combine the false and true rows into one list of indexes.
rowsToExtract = sort([falseRows, trueRows]);
% Now extract only the first 700 true, but all the false.
t = t(rowsToExtract );
or something like that. You might have to debug it some.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by