本文整理汇总了Python中sklearn.feature_selection.rfe.RFE.fit_transform方法的典型用法代码示例。如果您正苦于以下问题:Python RFE.fit_transform方法的具体用法?Python RFE.fit_transform怎么用?Python RFE.fit_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.feature_selection.rfe.RFE
的用法示例。
在下文中一共展示了RFE.fit_transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fs_rfe
# 需要导入模块: from sklearn.feature_selection.rfe import RFE [as 别名]
# 或者: from sklearn.feature_selection.rfe.RFE import fit_transform [as 别名]
def _fs_rfe(self, data, labels, plot_filename, n_features=10):
svc = SVC(kernel="linear", C=1)
transformer = RFE(estimator=svc, n_features_to_select=n_features, step=1)
data = transformer.fit_transform(data, labels)
attributes = OrderedDict()
#produce a plot if requested and supported (for RFE)
if plot_filename:
try:
grid_scores = transformer.grid_scores_
except:
return transformer, data, attributes
plt.figure()
plt.xlabel("Number of features selected")
plt.ylabel("Cross validation score (nb of correct classifications)")
plt.plot(range(1, len(grid_scores) + 1), transformer.grid_scores)
plt.savefig(plot_filename, bbox_inches='tight')
#put ranks in an array, so that we can get them in the log file
for i, rank_strings in enumerate(transformer.ranking_):
attributes["RFE_rank_f{}".format(i)] = rank_strings
for i, rank_strings in enumerate(transformer.support_):
attributes["RFE_mask_f{}".format(i)] = rank_strings
return transformer, data, attributes