How to assign numbers to categorical values in a dataset?
10 次查看(过去 30 天)
显示 更早的评论
I'm preparing a dataset for machine learning. The dataset contains a column name "Holiday". The column contains more than a million row of values. It is categorical in nature and contains 4 unique values - 0 (as a string), a, b, c.
I want to assign the values 0 to 0 and 1 to the rest of them - a, b and c. How do I do that? Is there a readymade function?
0 个评论
采纳的回答
Adam Danz
2020-5-18
编辑:Adam Danz
2020-5-18
If you want to return logical values,
dummyVars = Holiday ~= '0'; % Holiday is categorical
If you want to return integer values,
dummyVars = double(Holiday ~= '0'); % Holiday is categorical
Note that any value of Holiday that doesn't equal 0 will be assigned a value of 1.
4 个评论
Adam Danz
2020-5-18
In that case, you can use
[groups, groupID] = findgroups(Holiday)
or
[groupID, groups] = grp2idx(a); % requires stats & ML toolbox
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calendar 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!