8000 DOC Rename features in highlight of feature importance (#17331) · scikit-learn/scikit-learn@0c84afa · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 0c84afa

Browse files
authored
DOC Rename features in highlight of feature importance (#17331)
1 parent 7494da6 commit 0c84afa

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/release_highlights/plot_release_highlights_0_22_0.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,23 @@
100100
# The :func:`inspection.permutation_importance` can be used to get an
101101
# estimate of the importance of each feature, for any fitted estimator:
102102

103+
import numpy as np
104+
import matplotlib.pyplot as plt
105+
from sklearn.datasets import make_classification
103106
from sklearn.ensemble import RandomForestClassifier
104107
from sklearn.inspection import permutation_importance
105108

106109
X, y = make_classification(random_state=0, n_features=5, n_informative=3)
110+
feature_names = np.array([f'x_{i}' for i in range(X.shape[1])])
111+
107112
rf = RandomForestClassifier(random_state=0).fit(X, y)
108113
result = permutation_importance(rf, X, y, n_repeats=10, random_state=0,
109114
n_jobs=-1)
110115

111116
fig, ax = plt.subplots()
112117
sorted_idx = result.importances_mean.argsort()
113118
ax.boxplot(result.importances[sorted_idx].T,
114-
vert=False, labels=range(X.shape[1]))
119+
vert=False, labels=feature_names[sorted_idx])
115120
ax.set_title("Permutation Importance of each feature")
116121
ax.set_ylabel("Features")
117122
fig.tight_layout()

0 commit comments

Comments
 (0)
0