필터 지우기
필터 지우기

How to plot feature importance on x-axis and variable names on y-axis?

조회 수: 16 (최근 30일)
Devendra
Devendra 2023년 8월 8일
댓글: Devendra 2023년 8월 9일
I wish to plot variables names on y-axis and feature importance on x-axis in Random Forest Regression. Also the variables on y-axis should be in descending order according to their feature importance on x-axis. I request you to kindly suggest me how to do it. D S Chahar
  댓글 수: 1
Devendra
Devendra 2023년 8월 8일
I want to generate the feature importance plot similar to attached image. I request you all to please suggest me how to create it in matlab. Many thanks in advance.
Devendra

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2023년 8월 8일
편집: dpb 2023년 8월 8일
See barh and particularly <the example>. Use the second optional output from sort to get the order of the variables when you sort them to put in descending order to use with xticklabels to label the y-axis tick values. Or, you could convert to categorical variable type for the x-value (as ordinal to keep the sorted order) and will get the labels automagically.
nfacts=8;
features="f"+[0:nfacts-1].';
F=randi([20,125],size(features));
[F,ix]=sort(F);
hB=barh(F);
yticklabels(features(ix))
xlabel('F Score'), ylabel('Features')
hTxt=text(hB.YEndPoints,hB.XEndPoints," "+string(F),'horizontal','left','vertical','middle');
NOTA BENE: with the horiontal bar, the x,y postions for text() are y,x on the plot axes nomenclature; that's easy to confuse and the text doesn't show up or is somewhere bizarre.
  댓글 수: 3
dpb
dpb 2023년 8월 9일
"...keep the values ... up to two decimal points only"
Just replace
" "+string(F)
generating the string to write with
compose(" %0.2f",F)
The olden way was with num2str
Devendra
Devendra 2023년 8월 9일
Thanks a lot. It worked.
Devendra

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by