Generate three datasets with given details
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I need to perform such action:
- Generate three datasets (data, dataB and dataC), every one containing two features and two classes (0 and 1) with 100 points for each class. Draw the data from random distributions with the following parameters:
- a. DataA: class 0: mean = 0, standard deviation = 1, class 1: mean = 3 standard deviation = 0.5
- b. DataB: class 0: mean = 0, standard deviation = 1, class 1: mean = 2 standard deviation = 1
- c. DataC: class 0: mean = 0, standard deviation = 1, class 1: mean = 1 standard deviation = 2
Is this code is relevant to the task?
% Data A
Class0=randn(100,2);
label_0=zeros(100,1);
Class1=0.5*randn(100,2)+3
label_1=ones(100,1)
data_a=[[Class0, label_0];[Class1, label_1]]
% Data B
Class0=randn(100,2);
label_0=zeros(100,1);
Class1=1*randn(100,2)+2
label_1=ones(100,1)
data_b=[[Class0, label_0];[Class1, label_1]]
% Data C
Class0=randn(100,2);
label_0=zeros(100,1);
Class1=2*randn(100,2)+1
label_1=ones(100,1)
data_c=[[Class0, label_0];[Class1, label_1]]
0 个评论
回答(1 个)
Rajeev
2023-1-20
编辑:Rajeev
2023-1-20
This code is correct if you want to generate data with the required metrics.
You can verify the results by using the "mean" and "std" functions to find the average and the standard deviation of the data.
One thing to note: For less number of observations, the mean and standard deviation will be farther to the expected values. As you increase the sample size, for example from 100 to 1000, the mean and standard deviation of the data will approach the true values.
You can find more about it here: https://en.wikipedia.org/wiki/Central_limit_theorem
Documentation links:
mean function: https://www.mathworks.com/help/fixedpoint/ref/mean.html
std function: https://www.mathworks.com/help/matlab/ref/std.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!