could to create the categorical values for 2x2 cell array

I having cell array of 15x1. A (input training data for clustering)=15×1 cell array
{2×1 double}
{2×1 double}
{2×1 double}
{2×1 double}
{2×1 double}
{2×2 double}
{2×2 double}
{2×2 double}
{2×2 double}
{2×2 double}
{2×3 double}
{2×3 double}
{2×3 double}
{2×3 double}
{2×3 double}
B(targets for clustering) needs to be in the following manner.
[ 1
1
1
1
1
1 1
1 2
2 1
2 1
1 2
1 2 2
2 1 1
1 3 2
1 1 2
2 2 1]
Could you please help me to get it.

댓글 수: 1

Feel free to reopen this question to edit it and make it more clear.

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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 23일
B = cellfun(@convert_to_categorical, A, 'uniform', 0);
function C = convert_to_categorical(M)
if iscell(M)
C = cellfun(@convert_to_categorical, M, 'uniform', 0);
else
C = categorical(M);
end
end

댓글 수: 6

I want to have B as follows
B(targets for clustering)
[ 1 for {2×1 double}
1 for {2×1 double}
1 for {2×1 double}
1 for {2×1 double}
1 for {2×1 double}
1 1 for {2×2 double}
1 2 for {2×2 double}
2 1 for {2×2 double}
2 1 for {2×2double}
1 2 for {2×2 double}
1 2 2 for {2×3 double}
2 1 1 for {2×3 double}
1 3 2 for {2×3double}
1 1 2 for {2×3 double}
2 2 1] for {2×3double}
Could you please help me to get it.
When you look at the data at B{12} compared to B{13} how can you tell whether the targets should be [2 1 1] or [1 3 2] ?
jaah navi
jaah navi 2021년 6월 23일
편집: Walter Roberson 2021년 6월 23일
sorry I made a mistake actually my targets are
[ 1
1
1
1
1
1 1
1 2
2 1
2 1
1 2
1 2 2
2 1 1
1 3 2
1 1 2
2 2 1]
which are collected before
but I doesn't know how to train the model based on the inputs containing cell array with its corresponding targets shown above.
Could you please help me to organise it.
Sorry, I still have no idea how the content of B{12} leads you to know to use [2 1 1] but the content of B{13} leads you to know to use [1 3 2] as the targets.
If you (somehow) knew you had
targ = { 1
1
1
1
1
[1 1]
[1 2]
[2 1]
[2 1]
[1 2]
[1 2 2]
[2 1 1]
[1 3 2]
[1 1 2]
[2 2 1]
}
and then you would
ctarg = cellfun(@categorical, targ, 'uniform', 0);
after which you would pass ctarg in as the target data.
i used ctarg(B) command for my targets. thanks for it.
But when I implement it to train the model using the following code
A
B
inputSize = 2;
numHiddenUnits = 100;
numClasses = 3;
layers = [ ...
sequenceInputLayer(inputSize)
fullyConnectedLayer(3)
reluLayer
regressionLayer]
maxEpochs = 50;
miniBatchSize = 50;
options = trainingOptions('adam', ...
'ExecutionEnvironment','cpu', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'Plots','training-progress');
net = trainNetwork(XTrainCopy,ctarg,layers,options);
i am getting error stating Invalid training data. Responses must be a matrix of numeric responses, or a N-by-1 cell array of sequences, where N is the number of sequences. The feature dimension of all sequences must be the same.
Error in seven (line 21)
net = trainNetwork(A,B,layers,options);
Caused by:
Error using nnet.internal.cnn.util.NetworkDataValidator/assertValidSequenceResponse (line
356)
Invalid training data. Responses must be a matrix of numeric responses, or a N-by-1 cell
array of sequences, where N is the number of sequences. The feature dimension of all
sequences must be the same.
Could you please help me to overcome it.
If my code is wrong please guide me how to model the code to train my inputs and targets.

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

카테고리

태그

질문:

2021년 6월 23일

편집:

2021년 6월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by