Decision Tree to If-Else Rules

4 vues (au cours des 30 derniers jours)
Amrit Kumar Verma
Amrit Kumar Verma le 6 Mar 2019
Is there any method to convert directly the decision tree from Classification Tree Viewer to If-Else rules ?
  1 commentaire
Mario Buser
Mario Buser le 9 Juil 2019
Would be interested in a solution as well. WEKA, for example, is able to export if/else statements.

Connectez-vous pour commenter.

Réponses (1)

Koorosh Aslansefat
Koorosh Aslansefat le 20 Mai 2020
I am not sure what exactly you want but the following code can be useful considering that you saved the decision tree as "tc".
CP = tc.CutPoint;
NC = tc.NodeClass;
for ii = 1:size(CP,1)
if ~isnan(CP(ii))
fprintf('if x%d < %f then node %d elseif x%d >= %f then node %d else %d \n',str2num(NC{ii}),CP(ii),ii+1,str2num(NC{ii}),CP(ii), ii+2,ii)
elseif isnan(CP(ii))
fprintf('Class = %d \n',str2num(NC{ii}))
end
end
This equal to veiw(tc)

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by