栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Scikit-learn计算信息增益

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Scikit-learn计算信息增益

您可以使用scikit-learn的

mutual_info_classif

示例

from sklearn.datasets import fetch_20newsgroupsfrom sklearn.feature_selection import mutual_info_classiffrom sklearn.feature_extraction.text import CountVectorizercategories = ['talk.religion.misc',   'comp.graphics', 'sci.space']newsgroups_train = fetch_20newsgroups(subset='train',     categories=categories)X, Y = newsgroups_train.data, newsgroups_train.targetcv = CountVectorizer(max_df=0.95, min_df=2,    max_features=10000,    stop_words='english')X_vec = cv.fit_transform(X)res = dict(zip(cv.get_feature_names(),    mutual_info_classif(X_vec, Y, discrete_features=True)    ))print(res)

这将输出每个属性的字典,即词汇表中的项作为键,其信息增益作为值

这是输出的样本

{'bible': 0.072327479595571439, 'christ': 0.057293733680219089, 'christian': 0.12862867565281702, 'christians': 0.068511328611810071, 'file': 0.048056478042481157, 'god': 0.12252523919766867, 'gov': 0.053547274485785577, 'graphics': 0.13044709565039875, 'jesus': 0.09245436105573257, 'launch': 0.059882179387444862, 'moon': 0.064977781072557236, 'morality': 0.050235104394123153, 'nasa': 0.11146392824624819, 'orbit': 0.087254803670582998, 'people': 0.068118370234354936, 'prb': 0.049176995204404481, 'religion': 0.067695617096125316, 'shuttle': 0.053440976618359261, 'space': 0.20115901737978983, 'thanks': 0.060202010019767334}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/625055.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号