How to use calculate the several means of same class

조회 수: 1 (최근 30일)
Kong
Kong 2020년 4월 2일
편집: Kong 2020년 4월 6일
Hello.
I have a data (90 x 2857), column 2857 is a label(class).
I'm using table function.
I want to read rows of the same class from table, select N rows, calculate the average.
Could you giva an idea to make the code?
data = readtable("outfile.csv");
data.Properties.VariableNames{end} = 'label';
data{:,1:end-1} = normalize(data{:,1:end-1},1); % I belive this should be "1"
data = sortrows(data,'label'); % The data are sorted by the lables
  댓글 수: 1
Kong
Kong 2020년 4월 6일
I did't find how to select rows for same class randomly.
Can I get some ideas to make a code?

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 2일
편집: Ameer Hamza 2020년 4월 2일
Try this
data = csvread('outfile.csv');
values = data(:,1:end-1);
labels = data(:,end);
avg = splitapply(@(x) mean(x,1), values, labels+1);
The avg matrix is 10x2856, each row corresponds to mean value of one class.
  댓글 수: 7
Ameer Hamza
Ameer Hamza 2020년 4월 3일
@Kong, your question is not clear. Do you want to apply softmax function to all the distance values
data = csvread('outfile.csv');
values = data(:,1:end-1);
labels = data(:,end);
avg = splitapply(@(x) {mean(x,1)}, values, labels+1);
grps = splitapply(@(x) {x}, values, labels+1);
Distance = cellfun(@(x,y) {pdist2(x,y)}, grps, avg);
dlY = cellfun(@(x) {softmax(x)}, Distance);
Kong
Kong 2020년 4월 4일
Thank you so much.
I want to select 5 rows of the same classes randomly and compute the mean of each 5 rows.
(10 Combination 5)
So I want to get all possible combinations' average values of the same classes.
In this code, I computed all rows of the same class and got one average value.
Could you explain how to fix the code?
data = csvread('outfile.csv');
values = data(:,1:end-1);
labels = data(:,end);
avg = splitapply(@(x) {mean(x,1)}, values, labels+1);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Classification Trees에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by