Advertisement

Python 机器学习中的卡方检验及LabelEncoder与One-hot编码结合XGBoost模型

阅读量:

一、统计学核心概念与应用

1. crosstable

复制代码
    # 计数
    ct = pd.crosstab(label, feature, margins=True)
    # 比例
    ct_prob = contingency_table.div(ct['All'], axis=0)
    
    
      
      
      
      
    

2. 卡方检验

复制代码
    # p-value
    scipy.stats.chi2_contingency(cross_table)[1]
    # chi^2
    scipy.stats.chi2_contingency(cross_table)[0]
    
    
      
      
      
      
    

SelectKBest特征选择方法

复制代码
    from sklearn.feature_selection import SelectKBest
    from sklearn.feature_selection import chi2
    skb = SelectKBest(chi2, k=2)
    skb = skb.fit(cols, feat)

全部评论 (0)

还没有任何评论哟~