ML之DT:基于DT决策树算法(交叉验证FS+for遍历最佳FS)对Titanic(泰坦尼克号)数据集进行二分类预测


战斗机顺心
战斗机顺心 2022-09-19 15:27:58 49958
分类专栏: 资讯

ML之DT:基于DT决策树算法(交叉验证FS+for遍历最佳FS)对Titanic(泰坦尼克号)数据集进行二分类预测

目录

输出结果

设计思路

核心代码


输出结果

设计思路

核心代码

  1. fs = feature_selection.SelectPercentile(feature_selection.chi2, percentile = i)
  2. X_train_fs = fs.fit_transform(X_train, y_train)
  3. scores = cross_val_score(dt, X_train_fs, y_train, cv=5)
  1. class SelectPercentile(-title class_ inherited__">_BaseFilter):
  2. """Select features according to a percentile of the highest scores.
  3. Read more in the :ref:`User Guide <univariate_feature_selection>`.
  4. Parameters
  5. ----------
  6. score_func : callable
  7. Function taking two arrays X and y, and returning a pair of arrays
  8. (scores, pvalues) or a single array with scores.
  9. Default is f_classif (see below "See also"). The default function only
  10. works with classification tasks.
  11. percentile : int, optional, default=10
  12. Percent of features to keep.
  13. Attributes
  14. ----------
  15. scores_ : array-like, shape=(n_features,)
  16. Scores of features.
  17. pvalues_ : array-like, shape=(n_features,)
  18. p-values of feature scores, None if `score_func` returned only scores.
  19. Notes
  20. -----
  21. Ties between features with equal scores will be broken in an unspecified
  22. way.
  23. See also
  24. --------
  25. f_classif: ANOVA F-value between label/feature for classification tasks.
  26. mutual_info_classif: Mutual information for a discrete target.
  27. chi2: Chi-squared stats of non-negative features for classification tasks.
  28. f_regression: F-value between label/feature for regression tasks.
  29. mutual_info_regression: Mutual information for a continuous target.
  30. SelectKBest: Select features based on the k highest scores.
  31. SelectFpr: Select features based on a false positive rate test.
  32. SelectFdr: Select features based on an estimated false discovery rate.
  33. SelectFwe: Select features based on family-wise error rate.
  34. GenericUnivariateSelect: Univariate feature selector with configurable mode.
  35. """
  36. def __init__(self, score_func=f_classif, percentile=10):
  37. super(SelectPercentile, self).__init__(score_func)
  38. self.percentile = percentile
  39. def _check_params(self, X, y):
  40. if not 0 <= self.percentile <= 100:
  41. raise ValueError(
  42. "percentile should be >=0, <=100; got %r" % self.percentile)
  43. def _get_support_mask(self):
  44. check_is_fitted(self, 'scores_')
  45. Cater for NaNs
  46. if self.percentile == 100:
  47. return np.ones(len(self.scores_), dtype=np.bool)
  48. elif self.percentile == 0:
  49. return np.zeros(len(self.scores_), dtype=np.bool)
  50. scores = _clean_nans(self.scores_)
  51. treshold = stats.scoreatpercentile(scores,
  52. 100 - self.percentile)
  53. mask = scores > treshold
  54. ties = np.where(scores == treshold)[0]
  55. if len(ties):
  56. max_feats = int(len(scores) * self.percentile / 100)
  57. kept_ties = ties[:max_feats - mask.sum()]
  58. mask[kept_ties] = True
  59. return mask

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=3283
赞同 0
评论 0 条
战斗机顺心L0
粉丝 0 发表 6 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2672
【软件正版化】软件正版化工作要点  2637
统信UOS试玩黑神话:悟空  2532
信刻光盘安全隔离与信息交换系统  2216
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1092
grub引导程序无法找到指定设备和分区  743
WPS City Talk · 校招西安站来了!  15
金山办公2024算法挑战赛 | 报名截止日期更新  15
看到某国的寻呼机炸了,就问你用某水果手机发抖不?  14
有在找工作的IT人吗?  13
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
信创开放社区邀请他人注册的具体步骤如下 15
如何玩转信创开放社区—从小白进阶到专家 15
方德桌面操作系统 14
我有15积分有什么用? 13
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!