Onehotencode function is giving more columns which are filled with zeros than the number of categories.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Yagiz Dereboy
el 9 de Sept. de 2021
Respondida: Yagiz Dereboy
el 11 de Sept. de 2021
a = readtable("mushrooms.csv");
aa = categorical(table2array(a));
b = onehotencode(aa(:,1),2);
first column has 2 categories but function creates 23 columns. Which is also the total number of columns in variable a. Also other variables behave the same too and seemingly 2 spesific column in each onehotencoded variable has the true onehotencoded variables. Can you help me please?
0 comentarios
Respuesta aceptada
Mohammad Sami
el 10 de Sept. de 2021
Because you are converting the entire matrix in to a categorical matrix, the categories for the entire matrix are common. If you want to have different categories for each column. you will have to convert each columm to caterogical separately.
a = repmat(1:10,10,1);
b = categorical(a)
categories(b(:,1))
c = array2table(a);
c = varfun(@categorical,c)
categories(c{:,1})
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Image Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!