ML之DT:基于DT决策树算法(对比是否经特征筛选FS处理)对Titanic(泰坦尼克号)数据集进行二分类预测


一登录
一登录 2022-09-19 15:28:30 52055
分类专栏: 资讯

ML之DT:基于DT决策树算法(对比是否经特征筛选FS处理)对Titanic(泰坦尼克号)数据集进行二分类预测

目录

输出结果

设计思路

核心代码


输出结果

初步处理后的 X_train: (984, 474) 
   (0, 0)    31.19418104265403
  (0, 78)    1.0
  (0, 82)    1.0
  (0, 366)    1.0
  (0, 391)    1.0
  (0, 435)    1.0
  (0, 437)    1.0
  (0, 473)    1.0
  (1, 0)    31.19418104265403
  (1, 73)    1.0
  (1, 79)    1.0
  (1, 296)    1.0
  (1, 389)    1.0
  (1, 397)    1.0
  (1, 436)    1.0
  (1, 446)    1.0
  (2, 0)    31.19418104265403
  (2, 78)    1.0
  (2, 82)    1.0
  (2, 366)    1.0
  (2, 391)    1.0
  (2, 435)    1.0
  (2, 437)    1.0
  (2, 473)    1.0
  (3, 0)    32.0
  :    :
  (980, 473)    1.0
  (981, 0)    12.0
  (981, 73)    1.0
  (981, 81)    1.0
  (981, 84)    1.0
  (981, 390)    1.0
  (981, 435)    1.0
  (981, 436)    1.0
  (981, 473)    1.0
  (982, 0)    18.0
  (982, 78)    1.0
  (982, 81)    1.0
  (982, 277)    1.0
  (982, 390)    1.0
  (982, 435)    1.0
  (982, 437)    1.0
  (982, 473)    1.0
  (983, 0)    31.19418104265403
  (983, 78)    1.0
  (983, 82)    1.0
  (983, 366)    1.0
  (983, 391)    1.0
  (983, 435)    1.0
  (983, 436)    1.0
  (983, 473)    1.0
经过FS处理后的 X_train_fs: (984, 94) 
   (0, 93)    1.0
  (0, 85)    1.0
  (0, 83)    1.0
  (0, 76)    1.0
  (0, 71)    1.0
  (0, 27)    1.0
  (0, 24)    1.0
  (0, 0)    31.19418104265403
  (1, 84)    1.0
  (1, 74)    1.0
  (1, 63)    1.0
  (1, 25)    1.0
  (1, 19)    1.0
  (1, 0)    31.19418104265403
  (2, 93)    1.0
  (2, 85)    1.0
  (2, 83)    1.0
  (2, 76)    1.0
  (2, 71)    1.0
  (2, 27)    1.0
  (2, 24)    1.0
  (2, 0)    31.19418104265403
  (3, 93)    1.0
  (3, 85)    1.0
  (3, 83)    1.0
  :    :
  (980, 24)    1.0
  (980, 0)    31.19418104265403
  (981, 93)    1.0
  (981, 84)    1.0
  (981, 83)    1.0
  (981, 75)    1.0
  (981, 28)    1.0
  (981, 26)    1.0
  (981, 19)    1.0
  (981, 0)    12.0
  (982, 93)    1.0
  (982, 85)    1.0
  (982, 83)    1.0
  (982, 75)    1.0
  (982, 26)    1.0
  (982, 24)    1.0
  (982, 0)    18.0
  (983, 93)    1.0
  (983, 84)    1.0
  (983, 83)    1.0
  (983, 76)    1.0
  (983, 71)    1.0
  (983, 27)    1.0
  (983, 24)    1.0
  (983, 0)    31.19418104265403

设计思路

核心代码

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

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

本文链接:https://www.xckfsq.com/news/show.html?id=3286
赞同 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

加入交流群

请使用微信扫一扫!