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

简介: 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








设计思路

image.png


核心代码

class SelectPercentile Found at: sklearn.feature_selection.univariate_selection

class SelectPercentile(_BaseFilter):

   """Select features according to a percentile of the highest scores.

 

   Read more in the :ref:`User Guide <univariate_feature_selection>`.

 

   Parameters

   ----------

   score_func : callable

   Function taking two arrays X and y, and returning a pair of arrays

   (scores, pvalues) or a single array with scores.

   Default is f_classif (see below "See also"). The default function only

   works with classification tasks.

 

   percentile : int, optional, default=10

   Percent of features to keep.

 

   Attributes

   ----------

   scores_ : array-like, shape=(n_features,)

   Scores of features.

 

   pvalues_ : array-like, shape=(n_features,)

   p-values of feature scores, None if `score_func` returned only scores.

 

   Notes

   -----

   Ties between features with equal scores will be broken in an unspecified

   way.

 

   See also

   --------

   f_classif: ANOVA F-value between label/feature for classification tasks.

   mutual_info_classif: Mutual information for a discrete target.

   chi2: Chi-squared stats of non-negative features for classification tasks.

   f_regression: F-value between label/feature for regression tasks.

   mutual_info_regression: Mutual information for a continuous target.

   SelectKBest: Select features based on the k highest scores.

   SelectFpr: Select features based on a false positive rate test.

   SelectFdr: Select features based on an estimated false discovery rate.

   SelectFwe: Select features based on family-wise error rate.

   GenericUnivariateSelect: Univariate feature selector with configurable mode.

   """

   def __init__(self, score_func=f_classif, percentile=10):

       super(SelectPercentile, self).__init__(score_func)

       self.percentile = percentile

 

   def _check_params(self, X, y):

       if not 0 <= self.percentile <= 100:

           raise ValueError(

               "percentile should be >=0, <=100; got %r" % self.percentile)

 

   def _get_support_mask(self):

       check_is_fitted(self, 'scores_')

       # Cater for NaNs

       if self.percentile == 100:

           return np.ones(len(self.scores_), dtype=np.bool)

       elif self.percentile == 0:

           return np.zeros(len(self.scores_), dtype=np.bool)

       scores = _clean_nans(self.scores_)

       treshold = stats.scoreatpercentile(scores,

           100 - self.percentile)

       mask = scores > treshold

       ties = np.where(scores == treshold)[0]

       if len(ties):

           max_feats = int(len(scores) * self.percentile / 100)

           kept_ties = ties[:max_feats - mask.sum()]

           mask[kept_ties] = True

       return mask



相关文章
|
27天前
|
机器学习/深度学习 算法 调度
14种智能算法优化BP神经网络(14种方法)实现数据预测分类研究(Matlab代码实现)
14种智能算法优化BP神经网络(14种方法)实现数据预测分类研究(Matlab代码实现)
167 0
|
2月前
|
机器学习/深度学习 Dragonfly 人工智能
基于蜻蜓算法优化支持向量机(DA-SVM)的数据多特征分类预测研究(Matlab代码实现)
基于蜻蜓算法优化支持向量机(DA-SVM)的数据多特征分类预测研究(Matlab代码实现)
|
4天前
|
存储 机器学习/深度学习 监控
网络管理监控软件的 C# 区间树性能阈值查询算法
针对网络管理监控软件的高效区间查询需求,本文提出基于区间树的优化方案。传统线性遍历效率低,10万条数据查询超800ms,难以满足实时性要求。区间树以平衡二叉搜索树结构,结合节点最大值剪枝策略,将查询复杂度从O(N)降至O(logN+K),显著提升性能。通过C#实现,支持按指标类型分组建树、增量插入与多维度联合查询,在10万记录下查询耗时仅约2.8ms,内存占用降低35%。测试表明,该方案有效解决高负载场景下的响应延迟问题,助力管理员快速定位异常设备,提升运维效率与系统稳定性。
30 4
|
2月前
|
机器学习/深度学习 传感器 数据采集
【23年新算法】基于鱼鹰算法OOA-Transformer-BiLSTM多特征分类预测附Matlab代码 (多输入单输出)(Matlab代码实现)
【23年新算法】基于鱼鹰算法OOA-Transformer-BiLSTM多特征分类预测附Matlab代码 (多输入单输出)(Matlab代码实现)
185 0
|
3月前
|
监控 算法 安全
基于 C# 基数树算法的网络屏幕监控敏感词检测技术研究
随着数字化办公和网络交互迅猛发展,网络屏幕监控成为信息安全的关键。基数树(Trie Tree)凭借高效的字符串处理能力,在敏感词检测中表现出色。结合C#语言,可构建高时效、高准确率的敏感词识别模块,提升网络安全防护能力。
90 2
|
3月前
|
机器学习/深度学习 人工智能 算法
AP聚类算法实现三维数据点分类
AP聚类算法实现三维数据点分类
131 0
|
4月前
|
机器学习/深度学习 算法 搜索推荐
决策树算法如何读懂你的购物心理?一文看懂背后的科学
"你为什么总能收到刚好符合需求的商品推荐?你有没有好奇过,为什么刚浏览过的商品就出现了折扣通知?
|
14天前
|
传感器 机器学习/深度学习 编解码
MATLAB|主动噪声和振动控制算法——对较大的次级路径变化具有鲁棒性
MATLAB|主动噪声和振动控制算法——对较大的次级路径变化具有鲁棒性
124 3
|
19天前
|
存储 编解码 算法
【多光谱滤波器阵列设计的最优球体填充】使用MSFA设计方法进行各种重建算法时,图像质量可以提高至多2 dB,并在光谱相似性方面实现了显著提升(Matlab代码实现)
【多光谱滤波器阵列设计的最优球体填充】使用MSFA设计方法进行各种重建算法时,图像质量可以提高至多2 dB,并在光谱相似性方面实现了显著提升(Matlab代码实现)
|
8天前
|
机器学习/深度学习 算法 数据可视化
基于MVO多元宇宙优化的DBSCAN聚类算法matlab仿真
本程序基于MATLAB实现MVO优化的DBSCAN聚类算法,通过多元宇宙优化自动搜索最优参数Eps与MinPts,提升聚类精度。对比传统DBSCAN,MVO-DBSCAN有效克服参数依赖问题,适应复杂数据分布,增强鲁棒性,适用于非均匀密度数据集的高效聚类分析。

热门文章

最新文章