@@ -77,6 +77,13 @@ const tooltipContent = i18n.translate(
7777 }
7878) ;
7979
80+ const calculateTotalMeanImportance = ( featureClass : ClassificationTotalFeatureImportance ) => {
81+ return featureClass . classes . reduce (
82+ ( runningSum , fc ) => runningSum + fc . importance . mean_magnitude ,
83+ 0
84+ ) ;
85+ } ;
86+
8087export const FeatureImportanceSummaryPanel : FC < FeatureImportanceSummaryPanelProps > = ( {
8188 totalFeatureImportance,
8289} ) => {
@@ -128,17 +135,25 @@ export const FeatureImportanceSummaryPanel: FC<FeatureImportanceSummaryPanelProp
128135 if ( totalFeatureImportance [ 0 ] . classes . length > 2 ) {
129136 classificationType = 'multiclass_classification' ;
130137
131- ( totalFeatureImportance as ClassificationTotalFeatureImportance [ ] ) . forEach ( ( feature ) => {
132- feature . classes
133- . sort ( ( a , b ) => a . importance . mean_magnitude - b . importance . mean_magnitude )
134- . forEach ( ( featureClass ) => {
135- sortedData . push ( {
138+ ( totalFeatureImportance as ClassificationTotalFeatureImportance [ ] )
139+ . sort (
140+ ( prevFeature , currentFeature ) =>
141+ calculateTotalMeanImportance ( currentFeature ) -
142+ calculateTotalMeanImportance ( prevFeature )
143+ )
144+ . forEach ( ( feature ) => {
145+ const sortedFeatureClass = feature . classes . sort (
146+ ( a , b ) => b . importance . mean_magnitude - a . importance . mean_magnitude
147+ ) ;
148+ sortedData . push (
149+ ...sortedFeatureClass . map ( ( featureClass ) => ( {
136150 featureName : feature . feature_name ,
137151 meanImportance : featureClass . importance . mean_magnitude ,
138152 className : featureClass . class_name ,
139- } ) ;
140- } ) ;
141- } ) ;
153+ } ) )
154+ ) ;
155+ } ) ;
156+
142157 _barSeriesSpec = {
143158 xAccessor : 'featureName' ,
144159 yAccessors : [ 'meanImportance' ] ,
@@ -151,16 +166,16 @@ export const FeatureImportanceSummaryPanel: FC<FeatureImportanceSummaryPanelProp
151166 if ( isRegressionTotalFeatureImportance ( totalFeatureImportance [ 0 ] ) ) {
152167 classificationType = 'regression' ;
153168
154- sortedData = ( totalFeatureImportance as RegressionTotalFeatureImportance [ ] ) . map (
155- ( d : RegressionTotalFeatureImportance ) => ( {
169+ sortedData = ( totalFeatureImportance as RegressionTotalFeatureImportance [ ] )
170+ . map ( ( d : RegressionTotalFeatureImportance ) => ( {
156171 featureName : d . feature_name ,
157172 meanImportance : d . importance . mean_magnitude ,
158- } )
159- ) ;
173+ } ) )
174+ . sort ( ( a , b ) => b . meanImportance - a . meanImportance ) ;
160175 }
161176
162177 // sort from largest importance at top to smallest importance at bottom
163- sortedData = sortedData . sort ( ( a , b ) => b . meanImportance - a . meanImportance ) ;
178+ // sortedData = sortedData.sort((a, b) => b.meanImportance - a.meanImportance);
164179
165180 // only show legend if it's a multiclass
166181 const _showLegend = classificationType === 'multiclass_classification' ;
0 commit comments