from sklearn.inspection._permutation_importance import permutation_importance
from sklearn.datasets import load_iris
from sklearn.metrics import get_scorer
from sklearn.linear_model import LogisticRegression
# 排列重要性
X, y = load_iris(return_X_y=True, as_frame=True)
lr = LogisticRegression()
lr.fit(X, y)
permutation_importance(lr, X, y, get_scorer('accuracy'))
# {'importances_mean': array([0.012 , 0.00933333, 0.56666667, 0.16133333]),
# 'importances_std': array([0.0077746 , 0.00326599, 0.04560702, 0.02124984]),
# 'importances': array([[0.02 , 0. , 0.00666667, 0.01333333, 0.02 ],
# [0.01333333, 0.00666667, 0.01333333, 0.00666667, 0.00666667],
# [0.62 , 0.52 , 0.58 , 0.60666667, 0.50666667],
# [0.2 , 0.15333333, 0.14666667, 0.14 , 0.16666667]])}
https://blog.csdn.net/u012111465/article/details/106813825