1.输出XGBoost特征的重要性 from matplotlib import pyplot pyplot.bar(range(len(model_XGB.feature_importances_)), model_XGB.feature_importances_) pyplot.show() XGBoost 特征重要性绘图 也可以使用XGBoost内置的特征重要性绘图函数 # plot feature importance using built-in function from xgboo
在XGBoost中提供了三种特征重要性的计算方法: ‘weight’ - the number of times a feature is used to split the data across all trees. ‘gain’ - the average gain of the feature when it is used in trees ‘cover’ - the average coverage of the feature when it is used in trees 简单
show the code: # Plot training deviance def plot_training_deviance(clf, n_estimators, X_test, y_test): # compute test set deviance test_score = np.zeros((n_estimators,), dtype=np.float64) for i, y_pred in enumerate(clf.staged_predict(X_test)): test_s
代码如下所示: # -*- coding: utf-8 -*- #导入需要的包 import matplotlib.pyplot as plt from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.metrics import roc_auc_score from xgboost import XGBClassifier from xgboost import
欢迎关注博主主页,学习python视频资源 https://blog.csdn.net/q383700092/article/details/53763328 调参后结果非常理想 from sklearn.model_selection import GridSearchCV from sklearn.datasets import load_breast_cancer from xgboost import XGBClassifier from sklearn.model_selection