zoukankan      html  css  js  c++  java
  • sklearn中xgboost模块中plot_importance函数(特征重要性)

    # -*- coding: utf-8 -*-
    """
    ###############################################################################
    # 作者:wanglei5205
    # 邮箱:wanglei5205@126.com
    # 代码:http://github.com/wanglei5205
    # 博客:http://cnblogs.com/wanglei5205
    # 目的:学习xgboost的plot_importance函数
    # 官方API文档:http://xgboost.readthedocs.io/en/latest/python/python_api.html#module-xgboost.training
    ###############################################################################
    """
    ### load module
    import matplotlib.pyplot as plt
    from sklearn import datasets
    from sklearn.model_selection import train_test_split
    from sklearn.metrics import accuracy_score
    from xgboost import XGBClassifier
    from xgboost import plot_importance
    
    ### load datasets
    digits = datasets.load_digits()
    
    ### data analysis
    print(digits.data.shape)
    print(digits.target.shape)
    
    ### data split
    x_train,x_test,y_train,y_test = train_test_split(digits.data,
                                                     digits.target,
                                                     test_size = 0.3,
                                                     random_state = 33)
    
    model = XGBClassifier()
    model.fit(x_train,y_train)
    
    ### plot feature importance
    fig,ax = plt.subplots(figsize=(15,15))
    plot_importance(model,
                    height=0.5,
                    ax=ax,
                    max_num_features=64)
    plt.show()
    
    ### make prediction for test data
    y_pred = model.predict(x_test)
    
    ### model evaluate
    accuracy = accuracy_score(y_test,y_pred)
    print("accuarcy: %.2f%%" % (accuracy*100.0))
    """
    95.0%
    """
    

      

  • 相关阅读:
    CBP是什么?
    编码器变换及量化的流程?
    CABAC与CAVLC有什么区别?
    如何在JM8.6编码端提取QDCT?
    宏块都有哪些类型?
    H264帧间预测流程?
    H264子宏块的划分有哪些?
    H264提供了哪些帧内预测?
    加强预测编码?
    centos7 下通过nginx+uwsgi部署django应用
  • 原文地址:https://www.cnblogs.com/Allen-rg/p/9520285.html
Copyright © 2011-2022 走看看