I found the function term_importances unnecessarily complicated. Within the loop, there are 3 branches. To my mind, the function is more understandable if we simply pull out the if clauses.
This handles the pathological case of having only a single class for importance_type="min_max" by an early return.
I dropped the use of itemset, as its use is discouraged in the documentation. It makes the code harder to read, and I cannot imagine a case where its performance matters.
I found the function
term_importances
unnecessarily complicated. Within the loop, there are 3 branches. To my mind, the function is more understandable if we simply pull out the if clauses.This handles the pathological case of having only a single class for
importance_type="min_max"
by an early return.I dropped the use of itemset, as its use is discouraged in the documentation. It makes the code harder to read, and I cannot imagine a case where its performance matters.