フィルターのクリア

how to imply array of zeros and ones to my dataset, help me plz

1 回表示 (過去 30 日間)
Ayman Alotaibi
Ayman Alotaibi 2018 年 3 月 13 日
編集済み: Ayman Alotaibi 2018 年 3 月 13 日
hi guy , I've those tasks, and I did my best to get them all done, this is what I've done so far. plz help me with task3 to get it done,
data=readData('adult.csv',',');
hdr=fieldnames(data)
N=length(data.income)
Task 1
Split the dataset into two subsets, say, "train" and "test", with the train set containing 80% of the data and the test set containing the remaining 20%.
Splitting means to generate a logical index of length equal to the number of observations in the dataset, with 1 for a training sample and 0 for at test sample.
Output: logical arrays called idxTrain and idxTest.
p=0.8; %train which is %80
numOfOne= N*p;
idxTrain=[ones(1, numOfOne)]; // array of ones %80
idxTest=[ zeros(1, N - numOfOne)]; // array of zeros %20
Task 2 using unique() convert the "race" categories into numerical indices. Then compute the popluation counts of the "race" categories.
Output: array E with the population counts of the race variable.
x=data.race(:);
[ux,~,idx]=unique(x);
idx=idx(:);
numbers = accumarray (idx , ones(size(idx)) );
Task 3 using accumarray compute the observed counts for the train and for the test subsets. Call tese TrainO and TestO, respectively.
Output: arrays TrainO and TestO with the race counts in each of the 2 subsets.
TrainO=
TestO=

回答 (0 件)

カテゴリ

Help Center および File ExchangeOctave についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by