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



目录
打赏
0
0
0
0
1043
分享
相关文章
Video-T1:视频生成实时手术刀!清华腾讯「帧树算法」终结闪烁抖动
清华大学与腾讯联合推出的Video-T1技术,通过测试时扩展(TTS)和Tree-of-Frames方法,显著提升视频生成的连贯性与文本匹配度,为影视制作、游戏开发等领域带来突破性解决方案。
67 4
Video-T1:视频生成实时手术刀!清华腾讯「帧树算法」终结闪烁抖动
K-means聚类算法是机器学习中常用的一种聚类方法,通过将数据集划分为K个簇来简化数据结构
K-means聚类算法是机器学习中常用的一种聚类方法,通过将数据集划分为K个簇来简化数据结构。本文介绍了K-means算法的基本原理,包括初始化、数据点分配与簇中心更新等步骤,以及如何在Python中实现该算法,最后讨论了其优缺点及应用场景。
274 6
利用SVM(支持向量机)分类算法对鸢尾花数据集进行分类
本文介绍了如何使用支持向量机(SVM)算法对鸢尾花数据集进行分类。作者通过Python的sklearn库加载数据,并利用pandas、matplotlib等工具进行数据分析和可视化。
251 70
|
1月前
|
算法系列之数据结构-Huffman树
Huffman树(哈夫曼树)又称最优二叉树,是一种带权路径长度最短的二叉树,常用于信息传输、数据压缩等方面。它的构造基于字符出现的频率,通过将频率较低的字符组合在一起,最终形成一棵树。在Huffman树中,每个叶节点代表一个字符,而每个字符的编码则是从根节点到叶节点的路径所对应的二进制序列。
50 3
 算法系列之数据结构-Huffman树
【C++数据结构——树】二叉树的遍历算法(头歌教学实验平台习题) 【合集】
本任务旨在实现二叉树的遍历,包括先序、中序、后序和层次遍历。首先介绍了二叉树的基本概念与结构定义,并通过C++代码示例展示了如何定义二叉树节点及构建二叉树。接着详细讲解了四种遍历方法的递归实现逻辑,以及层次遍历中队列的应用。最后提供了测试用例和预期输出,确保代码正确性。通过这些内容,帮助读者理解并掌握二叉树遍历的核心思想与实现技巧。
96 2
|
5月前
|
树的遍历算法有哪些?
不同的遍历算法适用于不同的应用场景。深度优先搜索常用于搜索、路径查找等问题;广度优先搜索则在图的最短路径、层次相关的问题中较为常用;而二叉搜索树的遍历在数据排序、查找等方面有重要应用。
102 2
深入探索机器学习中的决策树算法
深入探索机器学习中的决策树算法
82 0
数据结构与算法学习二一:多路查找树、二叉树与B树、2-3树、B+树、B*树。(本章为了解基本知识即可,不做代码学习)
这篇文章主要介绍了多路查找树的基本概念,包括二叉树的局限性、多叉树的优化、B树及其变体(如2-3树、B+树、B*树)的特点和应用,旨在帮助读者理解这些数据结构在文件系统和数据库系统中的重要性和效率。
56 0
数据结构与算法学习二一:多路查找树、二叉树与B树、2-3树、B+树、B*树。(本章为了解基本知识即可,不做代码学习)
探索机器学习中的决策树算法
【10月更文挑战第29天】本文将深入浅出地介绍决策树算法,一种在机器学习中广泛使用的分类和回归方法。我们将从基础概念出发,逐步深入到算法的实际应用,最后通过一个代码示例来直观展示如何利用决策树解决实际问题。无论你是机器学习的初学者还是希望深化理解的开发者,这篇文章都将为你提供有价值的见解和指导。
106 0
前端常用算法全解:特征梳理、复杂度比较、分类解读与示例展示
前端常用算法全解:特征梳理、复杂度比较、分类解读与示例展示
90 0

热门文章

最新文章