Feature importance
evaluate_feature_importance(model, x_test, y_test, feature_names, n_repeats=50, random_state=None)
Evaluate the feature importance of a sklearn classifier or regressor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
BaseEstimator
|
A trained and fitted Sklearn model. |
required |
x_test |
ndarray
|
Testing feature data (X data need to be normalized / standardized). |
required |
y_test |
ndarray
|
Testing label data. |
required |
feature_names |
Sequence[str]
|
Names of the feature columns. |
required |
n_repeats |
int
|
Number of iteration used when calculate feature importance. Defaults to 50. |
50
|
random_state |
Optional[int]
|
random state for repeatability of results. Optional parameter. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
A dataframe containing features and their importance. |
dict
|
A dictionary containing importance mean, importance std, and overall importance. |
Raises:
Type | Description |
---|---|
InvalidDatasetException
|
Either array is empty. |
InvalidParameterValueException
|
Value for 'n_repeats' is not at least one. |
Source code in eis_toolkit/exploratory_analyses/feature_importance.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|