代码中存在多个语法错误和变量名错误,以下是修改后的代码:

import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns

xgb_imp = pd.DataFrame(np.c_[特征1, 特征2, 特征3, 特征4, 特征5, 特征6, 特征7, 特征8, 特征9]) xgb_imp.columns = ['特征1', '特征2', '特征3', '特征4', '特征5', '特征6', '特征7', '特征8', '特征9']

import_feature = pd.DataFrame({'cool': xgb_imp.columns, 'xgb': xgb_model.feature_importances_}) import_feature = import_feature.sort_values(by='xgb', ascending=False)

Num_f = 10 indices = np.argsort(import_feature['xgb'].values)[::-1][:Num_f]

fig = plt.figure(figsize=(14, 10)) g = sns.barplot(y=import_feature.iloc[indices]['cool'].values, x=import_feature.iloc[indices]['xgb'].values, orient='h') g.set_xlabel('Relative importance', fontsize=18) g.set_ylabel('Features', fontsize=18) g.tick_params(labelsize=14) sns.despine() plt.show()

修改后的代码中,首先修改了DataFrame的创建方式和列名,然后修正了变量名错误和语法错误,最后修改了绘图代码中的变量名错误和排序方式错误

xgb_imp=pdDataFramenpc_npr_特征1 特征2 特征3 特征4 特征5 特征6 特征7 特征8特征9xgb_impcolumns=colimportanceindices = npargsortimport_featurexgbvalues-1Num_f = 10dndices = indicesNum_ffig=pltfigurefigsize=1410g = snsbar

原文地址: http://www.cveoy.top/t/topic/hsuA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录