代码之家  ›  专栏  ›  技术社区  ›  crabcanon

Scikit学习支持向量机特征名称

  •  0
  • crabcanon  · 技术社区  · 7 年前

    我正在使用Scikit learn开发一个支持向量机分类器。我有378个特征,在拟合分类器后,我发现我的数据的最佳特征数是41。我现在想知道这41个功能到底是什么。为了对每个功能的重要性进行排序,我使用了:

    selector.ranking_ 
    

    array([294, 285, 265, 239, 345, 240, 231, 282, 284, 341, 344, 244, 224,
       123, 151, 194, 190, 161, 170, 219, 227, 283, 275, 121, 177, 140,
       164, 353, 185, 230, 293, 320, 256,  37,   4, 321, 322, 267, 327,
       273, 206, 241, 169, 110, 147, 323, 242, 168,  24, 301,  19, 204,
        69, 297, 362, 281, 257, 334, 108,  73, 325, 326, 331, 268, 207,
       272, 274, 348,  39,  61, 243, 324, 189, 134, 142, 181,  23,  99,
       356, 247, 276, 205,  27,  72, 221, 339, 149,  43,  54, 103, 238,
       192, 143,  84, 114, 154,   9,  32,  75, 178, 291, 158, 237, 328,
       292,  81,  85, 264, 337,  97,  68,  31,  44, 234, 352, 302, 193,
        82,  52,  45,  60, 355, 132,  83, 258, 233, 223, 277, 288, 340,
       342, 236, 232, 104, 126, 179, 162, 152, 173, 222, 235, 278, 269,
        14, 171, 138, 163, 367, 102, 119, 309, 308, 129,  42, 200, 280,
        93,  55,  62,  47, 213, 175,   6,  26, 116,  66, 165, 128,  88,
        29, 307, 306, 208, 167, 279, 199, 130, 191,   5,  25, 131,  67,
        87,  46, 370, 172, 259, 166, 378,  76,   3, 153, 148, 218, 262,
        95, 120, 144, 125, 260, 330, 251, 209,  89,  91, 118,   2, 101,
        48, 212, 186, 263, 217,  77,  65,  28,  78, 329, 261, 176, 150,
       349, 117,  90,  34, 365, 298, 296, 228, 225, 216, 198, 311, 300,
       304, 310, 317, 315, 109, 314,   1,  86, 299, 295, 229, 226, 343,
       364,  63, 133, 303, 305, 318, 316, 366, 157, 156,  49, 359, 290,
       188, 248, 174, 245, 203, 336, 215, 319, 250, 124, 135, 201,  33,
       187, 289, 220, 350, 202, 246, 214, 338, 249, 335, 363, 184, 136,
        41, 351,  80,  53, 145, 313, 183, 287, 211, 271,  96, 107,  74,
       127,  16,  22, 312, 146, 286, 182, 270, 210, 346,  40,  15, 266,
       347,   7,  17, 195,  70,  51, 113, 100, 180,  50, 122,  18,  11,
       141,  94, 105, 159, 357, 368,  92,  64, 358, 196, 253,  79,  21,
        59,  13, 111,  10, 252, 197,  56,   8, 361,  58,  57,  30, 371,
       254, 333,  35,  20, 139, 155, 332, 255, 360,  38,  71, 115, 354,
       112,  12, 137, 160, 369,  36,  98, 106, 372, 373, 374, 375, 376, 377])
    

    我的每个功能都有一个功能名称(而不仅仅是一个数字)。我可以查看索引并将每个数字映射到其各自的功能名称,但有378个功能有点繁琐。有没有一种方法可以简单地列出特征名称而不是列索引号?

    谢谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Florian H    7 年前

    假设你正在使用熊猫,你可以做如下事情:

    for col_num in selector.ranking_ :
        print(yourDataFrame.columns[col_num])
    

    除非我们不知道您的想法,否则其他选择很难确定 selector from sklearn.feature_selection import SelectKBest 你可以做s.th。例如:

    mask = selector.get_support() #list of booleans
        new_features = [] #becomes the list of your K best features in the following loop
    
        for bool, feature in zip(mask, feature_names):
            if bool:
                new_features.append(feature)