make categorical array out of 4D array

2 次查看(过去 30 天)
hi,
When I want to use the cross-entropy solver in matlab, I have to use the classificationlayer at the end of my layers and therefore the responses have to be a categorical array. My response array has the size of [1 1 500 7000] where the last two indexes are the the scale of the sample(500) as well as the number of observations (7000).
For using this as a categorical response, I know that is has to be in the form of nx1, as noted in the documantation. However, I don´t how to extract my response array to a categorical one. Any Ideas?
Thanks in advance!
  6 个评论
Walter Roberson
Walter Roberson 2022-3-10
You would create either a 500 x 7000 or 7000 x 500 array (different toolbox functions need different ways.)
You would also want a vector of length 7000 indicating which class each sample belongs to. Either you already have that information somewhere, or else it is implicit, such as knowing that (for example) you might have 7 classes with 1000 samples each. You could then use
C = reshape(repmat(categorical(1:NumberOfCategories), 7000/NumberOfCategories, 1),[],1) %OR
C = reshape(repmat(categorical(1:NumberOfCategories), 1, 7000/NumberOfCategories),[],1)
depending how the data is arranged.
Kuno Bruswachtl
Kuno Bruswachtl 2022-3-10
I think I got it now!
I really have to thank you Walter for your help and time. It means a lot to me, you made my day!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Gaussian Process Regression 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by