How to assign corresponding label to dataset

조회 수: 9 (최근 30일)
婧怡 王
婧怡 王 2021년 6월 30일
댓글: 婧怡 王 2021년 7월 2일
I have loaded a dataset, there are three classes as follows:
and I need to have the corresponding label set in order to training data with LSTM, but I don't know how to get a N*1categorical array like this:
How can I do this? I really need your help.

답변 (1개)

Seth Furman
Seth Furman 2021년 7월 1일
We can create categorical arrays using the categorical function.
Assuming SR, VF, and VT are cell arrays of character vectors we can call categorical with a value set. For example,
% Example data
SR = {'N','A','N','N'};
VF = {'N','N','N'};
VT = {'A','N'};
% Convert SR, VF, and VT into categorical arrays
valueset = {'N','A'};
SR = categorical(SR,valueset)
SR = 1×4 categorical array
N A N N
VF = categorical(VF,valueset)
VF = 1×3 categorical array
N N N
VT = categorical(VT,valueset)
VT = 1×2 categorical array
A N
Assuming SR, VF, and VT are NOT cell arrays of character vectors, but can be concatenated, we can call categorical with a value set and a set of corresponding category names. For example,
% Example data
SR = {0,1,0,0};
VF = {0,0,0};
VT = {1,0};
% Convert SR, VF, and VT into categorical arrays
valueset = [0 1];
catnames = {'N','A'};
SR = categorical([SR{:}],valueset,catnames)
SR = 1×4 categorical array
N A N N
VF = categorical([VF{:}],valueset,catnames)
VF = 1×3 categorical array
N N N
VT = categorical([VT{:}],valueset,catnames)
VT = 1×2 categorical array
A N
  댓글 수: 1
婧怡 王
婧怡 王 2021년 7월 2일
Thank you so much, the answer is very helpful for me.

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by