from sklearn.tree import DecisionTreeClassifierdtc = DecisionTreeClassifier() # 初始化
dtc.fit(x_train, y_train) # 训练# 获取特征权重值
weights = dtc.feature_importances_
print('>>>特征权重值\n', weights)# 索引降序排列
sort_index = np.argsort(weights)[::-1]
# 对应的特征名
name = [df.iloc[:, 1:].columns[i] for i in sort_index]
print('\n>>>索引降序排列\n', sort_index)
print('\n>>>特征名\n', name)# 可视化
plt.bar(x=name, height=weights[sort_index], color='r')
_ = plt.xticks(rotation=90)
plt.title('Feature Weights')