# inferring most important features

Given a set of $$n$$ instances. For each instance I have a feature vector consisting of $$m$$ (numerical) features ($$x_1$$, $$x_2$$,...,$$x_m$$), n>>m. Moreover, for each instance I have a numerical score $$y$$ (observable). I would like to:

1. find out which subset of features, or linear combination thereof, explains the scores the best.
2. create a nice visualization for this.

I have been pointed to Principal Component Analysis (PCA). The problem with PCA is that it only takes the feature vectors into account; PCA does not relate the features to the numerical score $$y$$.

Practical application: Given a large number of problem instances (e.g. traveling salesman problems) and some algorithm to solve the problem. Each time we solve the instance we can measure the total time (=score) it took to solve the instance. Moreover, for each instance we can obtain a number of features, e.g. size of te instance, graph diameter, etc. Which of these features explain the computation time best?

• By "instances" do you mean observations (i.e. usually "rows" of data)? Commented Nov 24, 2018 at 4:14
• Can you not use a regression modelling setting and then perform some form of model selection? I guess what type of modelling you use will depend on whether you can assume linearity or nonlinearity of the relationship between each feature and y controlling for the remaining features. For linearity, linear regression modelling would do. For nonlinearity, generalized additive modelling could be an option. Commented Nov 24, 2018 at 4:15
• Presuming you have fewer predictors than instances (i.e., m < n), you could perform model selection based on the BIC criterion, which is suitable in explanatory settings. As far as the visualization of the final model goes, effect plots could work - they would enable you to display the effect of each feature on y after controlling for the remaing features included in the final model. See socialsciences.mcmaster.ca/jfox/Papers/…. Commented Nov 24, 2018 at 4:23
• Could you clarify the type of relationship between the scores and input features (e.g. is it linear)? It's hard to tell from the phrasing in (1) (e.g. you might be considering scores to be a nonlinear function of a linear combination of features). Also, do you have a particular metric in mind for "best explaining the scores'? Commented Nov 24, 2018 at 12:34
• I think you need a feature selection algorithm: en.wikipedia.org/wiki/Feature_selection Commented Nov 25, 2018 at 15:37

There is a lot of options, it depends what exactly do you want.

Feature importance or permutation importance

Both methods tells you which features are most important for the model. It is a number for each feature. It is calculated after the model is fitted. It doesn't tell you anything about which values of a feature implies what scores.

In sklearn most modelz has model.feature_importances_. Sum of all feature importances is 1.

Permutation importance is calculated for a fitted model. It tells you how much the metric worsens if you shuffle the feature column.

Pseudo-code:

    model.fit()
base_score = model.score(x_dev, y_dev)
for i in range(nr_features):
x_dev_copy = copy(x_dev)
x_dev_copy[:, i] = shuffle(x_dev_copy[:, i])
perm_score = model.score(x_dev_copy, y_dev)
perm_imp[i] = (perm_score - base_score) / base_score