当前位置: 首页>>代码示例>>Python>>正文


Python xgboost.plot_importance方法代码示例

本文整理汇总了Python中xgboost.plot_importance方法的典型用法代码示例。如果您正苦于以下问题:Python xgboost.plot_importance方法的具体用法?Python xgboost.plot_importance怎么用?Python xgboost.plot_importance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xgboost的用法示例。


在下文中一共展示了xgboost.plot_importance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot_importance

# 需要导入模块: import xgboost [as 别名]
# 或者: from xgboost import plot_importance [as 别名]
def plot_importance(self, ax=None, height=0.2,
                        xlim=None, title='Feature importance',
                        xlabel='F score', ylabel='Features',
                        grid=True, **kwargs):

        """Plot importance based on fitted trees.

        Parameters
        ----------
        ax : matplotlib Axes, default None
            Target axes instance. If None, new figure and axes will be created.
        height : float, default 0.2
            Bar height, passed to ax.barh()
        xlim : tuple, default None
            Tuple passed to axes.xlim()
        title : str, default "Feature importance"
            Axes title. To disable, pass None.
        xlabel : str, default "F score"
            X axis title label. To disable, pass None.
        ylabel : str, default "Features"
            Y axis title label. To disable, pass None.
        kwargs :
            Other keywords passed to ax.barh()

        Returns
        -------
        ax : matplotlib Axes
        """

        import xgboost as xgb

        if not isinstance(self._df.estimator, xgb.XGBModel):
            raise ValueError('estimator must be XGBRegressor or XGBClassifier')
        # print(type(self._df.estimator.booster), self._df.estimator.booster)
        return xgb.plot_importance(self._df.estimator,
                                   ax=ax, height=height, xlim=xlim, title=title,
                                   xlabel=xlabel, ylabel=ylabel, grid=True, **kwargs) 
开发者ID:pandas-ml,项目名称:pandas-ml,代码行数:39,代码来源:base.py

示例2: plot_importance

# 需要导入模块: import xgboost [as 别名]
# 或者: from xgboost import plot_importance [as 别名]
def plot_importance(self):
        ax = xgb.plot_importance(self.model)
        self.save_topn_features()
        return ax 
开发者ID:ChenglongChen,项目名称:kaggle-HomeDepot,代码行数:6,代码来源:xgb_utils.py

示例3: save_topn_features

# 需要导入模块: import xgboost [as 别名]
# 或者: from xgboost import plot_importance [as 别名]
def save_topn_features(self, fname="XGBRegressor_topn_features.txt", topn=-1):
        ax = xgb.plot_importance(self.model)
        yticklabels = ax.get_yticklabels()[::-1]
        if topn == -1:
            topn = len(yticklabels)
        else:
            topn = min(topn, len(yticklabels))
        with open(fname, "w") as f:
            for i in range(topn):
                f.write("%s\n"%yticklabels[i].get_text()) 
开发者ID:ChenglongChen,项目名称:kaggle-HomeDepot,代码行数:12,代码来源:xgb_utils.py

示例4: run_train_validation

# 需要导入模块: import xgboost [as 别名]
# 或者: from xgboost import plot_importance [as 别名]
def run_train_validation(self):
        x_train, y_train,x_validation,y_validation = self.get_train_validationset()
        dtrain = xgb.DMatrix(x_train, label= y_train,feature_names=x_train.columns)
        dvalidation = xgb.DMatrix(x_validation, label= y_validation,feature_names=x_validation.columns)
        self.set_xgb_parameters()
        
        evals=[(dtrain,'train'),(dvalidation,'eval')]
        model = xgb.train(self.xgb_params, dtrain, evals=evals, **self.xgb_learning_params)
        xgb.plot_importance(model)
        plt.show()
         
        print "features used:\n {}".format(self.get_used_features())
         
        return 
开发者ID:LevinJ,项目名称:Supply-demand-forecasting,代码行数:16,代码来源:xgbbasemodel.py


注:本文中的xgboost.plot_importance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。