Generating two classes of points
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to create a 100x2 feature vector set, with roughly half in class '1' and the rest in class '-1'. (As in, when I make a scatter plot of the x-y coordinates, the points should be almost linearly separable). I suppose rand or randn wouldn't help much here.
Thanks for your inputs.
0 个评论
采纳的回答
John D'Errico
2018-2-20
Why would rand or randn NOT be of use here?
For example, what do you know about a bivariate random sample? How far out can you expect points to deviate from the mean, if you know the variances? In the case of using randn, the default covariance matrix would be an identity matrix. So you would expect almost the entire distribution to lie within 3*sigma.
So if you adjust the mean of the two set of samples to be separate by a sufficient amount, they will be distinct. You even know how much to offset the two distributions, based on those variances. Adding a constant value to normally distributed samples just adjusts the mean. So WTP?
Likewise, had you used rand, it produces uniformly distributed samples. In 2-dimensions, they will thus live in a unit square. Again, WTP? add a constant to one set.
更多回答(1 个)
Image Analyst
2018-2-20
No, but randperm() can help. Try this:
m = zeros(100, 2); % Initialize to all zero.
indexes = randperm(numel(m), numel(m)/2) % Get half of the indexes to change to 1.
m(indexes) = 1 % Change them to 1.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!