How do I onehotencode a table without encoding variable names?

When I try to onehotencode a table, the onehotencoder also encodes the variable names in addition to the category labels. I don't want this. I only want to encode the category labels.
I attached the table I want to onehotencode and the table that results when I execute this code:
B = table();
for i = 1:size(MyTable,2)
B = [B, onehotencode(MyTable(:,i))];
end
As you can see from the resultant table, category variable names are also encoded.
Thank you!

回答 (1 件)

KSSV
KSSV 2023 年 2 月 21 日
編集済み: KSSV 2023 年 2 月 21 日

0 投票

B = table();
for i = 1:size(MyTable,2)
B = [B, onehotencode(MyTable.(i))];
end
You may consider using width instead of size(MyTable,2)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

質問済み:

2023 年 2 月 21 日

編集済み:

2023 年 2 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by