![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1677916/image.png)
Visualization of decision tree
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a table in which all of its columns are categorical variables, and the label associated with them is also a categorical variable. I use this piece of code to fit a tree to the data:
Mdld = fitctree(X,Ycat,'MaxNumSplits',5,'PredictorSelection','curvature',...
'CrossVal','on');
when I plot the tree, the variables will be converted to a ordinal variable which is hard to track back what is the original variables that I had in table X. You can see the results here:
view(Mdld.Trained{1},'Mode','graph')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/772058/image.png)
As you see, the labels are correct, but for example, in the X table, I have "Small" and "Large" categories for vessel radius, but I get 1 and 2 labels instead, for which I event do not know readily which one is which!
I could not find a way to keep the labels on the node. Can anyone help me to do so?
0 comentarios
Respuestas (1)
Aneela
el 24 de Abr. de 2024
Hi Moztaba Zarei,
I tried the below example in MATLAB.
numObservations = 100;
% Define the categorical variables
VehicleType = categorical(randi([1, 3], numObservations, 1), 1:3, {'Car', 'Truck', 'Bike'});
Color = categorical(randi([1, 3], numObservations, 1), 1:3, {'Red', 'Blue', 'Green'});
Size = categorical(randi([1, 3], numObservations, 1), 1:3, {'Small', 'Medium', 'Large'});
% Combine into a table
data = table(Size, Color);
% Display the first few rows of the dataset
head(data)
tree=fitctree(data,VehicleType);
view(tree,'Mode','graph');
I got the below tree:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1677916/image.png)
I would suggest you check the preprocessing steps of the VesselRadius and make sure the categorical values are not "1" and "2".
For more information on Categorical Predictors refer to the following MathWorks Documentation: https://in.mathworks.com/help/stats/fitctree.html#namevaluepairs:~:text=%7C%20%27all%27-,Categorical%20predictors,-list%2C%20specified%20as
0 comentarios
Ver también
Categorías
Más información sobre Descriptive Statistics and Visualization 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!