{"id":170,"date":"2023-08-01T17:01:19","date_gmt":"2023-08-01T09:01:19","guid":{"rendered":"http:\/\/lingbo.online\/?p=170"},"modified":"2023-08-17T17:34:49","modified_gmt":"2023-08-17T09:34:49","slug":"feature_engineer","status":"publish","type":"post","link":"https:\/\/lingbo.online\/index.php\/algorithm_learning\/feature_engineer\/","title":{"rendered":"\u6570\u636e\u6316\u6398\u5165\u95e8\u57fa\u7840\u2014\u2014\u7279\u5f81\u5de5\u7a0b"},"content":{"rendered":"<p>\u672c\u6587\u53c2\u8003<a href=\"https:\/\/tianchi.aliyun.com\/competition\/entrance\/231784\/forum\" title=\"\u300a\u96f6\u57fa\u7840\u5165\u95e8\u6570\u636e\u6316\u6398 - \u4e8c\u624b\u8f66\u4ea4\u6613\u4ef7\u683c\u9884\u6d4b\u300b\" target=\"_blank\"  rel=\"nofollow\" >\u300a\u96f6\u57fa\u7840\u5165\u95e8\u6570\u636e\u6316\u6398 - \u4e8c\u624b\u8f66\u4ea4\u6613\u4ef7\u683c\u9884\u6d4b\u300b<\/a>\u90e8\u5206\u5185\u5bb9\u548c\u4ee3\u7801\uff0c\u6570\u636e\u96c6\u4e3a\u81ea\u5efa\u6570\u636e\u96c6\u3002\u8bfb\u8005\u53ef\u4f7f\u7528\u539f\u6587\u6570\u636e\u96c6\u8fdb\u884c\u9605\u8bfb\u8bd5\u9a8c\u3002<\/p>\n<h3>\u5e38\u89c1\u7279\u5f81\u5de5\u7a0b<\/h3>\n<h4>\u5f02\u5e38\u5904\u7406<\/h4>\n<ul>\n<li>\u901a\u8fc7\u7bb1\u578b\u56fe\uff08\u62163-Sigma\uff09\u5206\u6790\u5220\u9664\u5f02\u5e38\u503c\uff1b<\/li>\n<li>BOX-COX\u8f6c\u6362\uff08\u5904\u7406\u6709\u504f\u5206\u5e03\uff09\uff1b<\/li>\n<li>\u957f\u5c3e\u622a\u65ad\uff1b<\/li>\n<\/ul>\n<h4>\u7279\u5f81\u5f52\u4e00\u5316\/\u6807\u51c6\u5316<\/h4>\n<ul>\n<li>\u6807\u51c6\u5316\uff08\u8f6c\u6362\u4e3a\u6807\u51c6\u6b63\u6001\u5206\u5e03\uff09\uff1b<\/li>\n<li>\u5f52\u4e00\u5316\uff08\u8f6c\u6362\u5230[0,1]\u533a\u95f4\uff09\uff1b<\/li>\n<li>\u9488\u5bf9\u5e42\u5f8b\u5206\u5e03\uff0c\u53ef\u4ee5\u91c7\u7528\u516c\u5f0f\uff1a<span class=\"katex-eq\" data-katex-display=\"false\">log(\/frac{1+x}{1+median})<\/span><\/li>\n<\/ul>\n<h4>\u6570\u636e\u5206\u6876<\/h4>\n<ul>\n<li>\u7b49\u9891\u5206\u6876\uff1b<\/li>\n<li>\u7b49\u8ddd\u5206\u6876\uff1b<\/li>\n<li>Best-KS\u5206\u6876\uff08\u7c7b\u4f3c\u5229\u7528\u57fa\u5c3c\u6307\u6570\u8fdb\u884c\u4e8c\u5206\u7c7b\uff09\uff1b<\/li>\n<li>\u5361\u65b9\u5206\u6876\uff1b<\/li>\n<\/ul>\n<h4>\u7f3a\u5931\u503c\u5904\u7406\uff1a<\/h4>\n<ul>\n<li>\u4e0d\u5904\u7406\uff08\u9488\u5bf9\u7c7b\u4f3cXGBoost\u7b49\u6811\u6a21\u578b\uff09<\/li>\n<li>\u5220\u9664\uff08\u7f3a\u5931\u6570\u636e\u592a\u591a\uff09<\/li>\n<li>\u63d2\u503c\u8865\u5168\uff0c\u5305\u62ec\u5747\u503c\/\u4e2d\u4f4d\u6570\/\u4f17\u6570\/\u5efa\u6a21\u9884\u6d4b\/\u591a\u91cd\u63d2\u8865\/\u538b\u7f29\u611f\u77e5\u8865\u5168\/\u77e9\u9635\u8865\u5168\u7b49\uff1b<\/li>\n<li>\u5206\u7bb1\uff0c\u7f3a\u5931\u503c\u4e00\u4e2a\u7bb1\uff1b<\/li>\n<\/ul>\n<h4>\u7279\u5f81\u6784\u9020<\/h4>\n<ul>\n<li>\u6784\u9020\u7edf\u8ba1\u91cf\u7279\u5f81\uff0c\u62a5\u544a\u8ba1\u6570\u3001\u6c42\u548c\u3001\u6bd4\u4f8b\u3001\u6807\u51c6\u5dee\u7b49\uff1b<\/li>\n<li>\u65f6\u95f4\u7279\u5f81\uff0c\u5305\u62ec\u76f8\u5bf9\u65f6\u95f4\u548c\u7edd\u5bf9\u65f6\u95f4\uff0c\u8282\u5047\u65e5\uff0c\u53cc\u4f11\u65e5\u7b49\uff1b<\/li>\n<li>\u5730\u7406\u4fe1\u606f\uff0c\u5305\u62ec\u5206\u7bb1\uff0c\u5206\u5e03\u7f16\u7801\u7b49\uff1b<\/li>\n<li>\u975e\u7ebf\u6027\u53d8\u6362\uff0c\u5305\u62eclog\/\u5e73\u65b9\/\u6839\u53f7\u7b49\uff1b<\/li>\n<li>\u7279\u5f81\u7ec4\u5408\uff0c\u7279\u5f81\u4ea4\u53c9<\/li>\n<\/ul>\n<h4>\u7279\u5f81\u7b5b\u9009<\/h4>\n<ul>\n<li>\u8fc7\u6ee4\u5f0f\uff08filter\uff09\uff1a\u5148\u5bf9\u6570\u636e\u8fdb\u884c\u7279\u5f81\u9009\u62e9\uff0c\u7136\u540e\u5728\u8bad\u7ec3\u5b66\u4e60\u5668\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u6709 Relief\/\u65b9\u5dee\u9009\u62e9\u6cd5\/\u76f8\u5173\u7cfb\u6570\u6cd5\/\u5361\u65b9\u68c0\u9a8c\u6cd5\/\u4e92\u4fe1\u606f\u6cd5\uff1b<\/li>\n<li>\u5305\u88f9\u5f0f\uff08wrapper\uff09\uff1a\u76f4\u63a5\u628a\u6700\u7ec8\u8981\u4f7f\u7528\u7684\u5b66\u4e60\u5668\u6027\u80fd\u4f5c\u4e3a\u7279\u5f81\u5b50\u96c6\u7684\u8bc4\u4ef7\u51c6\u5219\uff0c\u5e38\u89c1\u65b9\u6cd5\u6709LVM\uff08Las Vegas Wrapper\uff09\uff1b<\/li>\n<li>\u5d4c\u5165\u5f0f\uff08embedding\uff09\uff1a\u7ed3\u5408\u8fc7\u6ee4\u5f0f\u548c\u5305\u88f9\u5f0f\uff0c\u5b66\u4e60\u5668\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u81ea\u52a8\u8fdb\u884c\u4e86\u7279\u5f81\u9009\u62e9\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u6709lasso\u56de\u5f52\uff1b<\/li>\n<\/ul>\n<h4>\u964d\u7ef4<\/h4>\n<ul>\n<li>PCA\/LDA\/ICA;<\/li>\n<li>\u7279\u5f81\u9009\u62e9<\/li>\n<\/ul>\n<h3>\u90e8\u5206\u7279\u5f81\u5de5\u7a0b\u5b9e\u73b0\u4ee3\u7801<\/h3>\n<h4>\u901a\u8fc7\u7bb1\u7ebf\u56fe\u5220\u9664\u5f02\u5e38\u503c<\/h4>\n<p>\u5728\u7bb1\u578b\u56fe\u4e2d\uff0c\u6570\u636e\u88ab\u4ece\u5927\u5230\u5c0f\u6309\u987a\u5e8f\u6392\u5217\uff0c\u56fe\u4e2d\u51fa\u73b0\u7684\u5143\u7d20\u4ee3\u8868\u542b\u4e49\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u4e0a\u56db\u5206\u4f4d\u6570Q3\uff1a75%\u5206\u4f4d\u70b9\u6240\u5bf9\u5e94\u7684\u503c<\/li>\n<li>\u4e2d\u4f4d\u6570Q2\uff1a50%\u5206\u4f4d\u70b9\u5bf9\u5e94\u7684\u503c<\/li>\n<li>\u4e0b\u56db\u5206\u4f4d\u6570Q1\uff1a25%\u5206\u4f4d\u70b9\u6240\u5bf9\u5e94\u7684\u503c<\/li>\n<li>\u4e0a\u8fb9\u7f18\uff08\u987b\uff09\uff1a<span class=\"katex-eq\" data-katex-display=\"false\">Q3+1.5(Q3-Q1)<\/span><\/li>\n<li>\u4e0b\u8fb9\u7f18\uff08\u987b\uff09\uff1a<span class=\"katex-eq\" data-katex-display=\"false\">Q1+1.5(Q3-Q1)<\/span><\/li>\n<\/ul>\n<p><figure id=\"attachment_173\" aria-describedby=\"caption-attachment-173\" style=\"width: 529px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lingbo.online\/wp-content\/uploads\/2023\/07\/\u7bb1\u7ebf\u56fe.png\" alt=\"\" width=\"529\" height=\"379\" class=\"size-full wp-image-173\" srcset=\"http:\/\/youpaiyun.lingbo.online\/2023\/07\/\u7bb1\u7ebf\u56fe.png 529w, http:\/\/youpaiyun.lingbo.online\/2023\/07\/\u7bb1\u7ebf\u56fe-300x215.png 300w\" sizes=\"auto, (max-width: 529px) 100vw, 529px\" \/><figcaption id=\"caption-attachment-173\" class=\"wp-caption-text\">\u5178\u578b\u7bb1\u7ebf\u56fe<\/figcaption><\/figure><br \/>\n\u90a3\u4e48\uff0c\u5728\u7bb1\u7ebf\u56fe\u4e2d\uff0c\u4f4d\u4e8e\u5408\u7406\u8303\u56f4\u7684x\u503c\u4e3a\uff1a<\/p>\n<p>$$Q1-1.5(Q3-Q1)\\leqslant x \\leqslant Q3+1.5(Q3-Q1)$$<\/p>\n<p>\u548c\u4f7f\u75283\u03c3\u51c6\u5219\u5254\u9664\u5f02\u5e38\u503c\u76f8\u6bd4\uff0c\u7bb1\u7ebf\u56fe\u4e0d\u9700\u8981\u6570\u636e\u670d\u4ece\u6b63\u6001\u5206\u5e03\uff0c\u80fd\u771f\u5b9e\u76f4\u89c2\u7684\u8868\u73b0\u6570\u636e\u5f62\u72b6\uff1b\u7bb1\u7ebf\u56fe\u4ee5\u56db\u5206\u4f4d\u6570\u548c\u56db\u5206\u4f4d\u8ddd\u4f5c\u4e3a\u5224\u65ad\u5f02\u5e38\u503c\u7684\u6807\u51c6\uff0c\u56db\u5206\u4f4d\u6570\u5177\u6709\u4e00\u5b9a\u7684\u8010\u6297\u6027\uff0c\u591a\u8fbe25%\u7684\u6570\u636e\u53ef\u4ee5\u53d8\u5f97\u4efb\u610f\u8fdc\u800c\u4e0d\u4f1a\u5f88\u5927\u5730\u6270\u52a8\u56db\u5206\u4f4d\u6570\uff0c\u4f7f\u5f97\u5f02\u5e38\u503c\u65e0\u6cd5\u5bf9\u6570\u636e\u5f62\u72b6\u9020\u6210\u5de8\u5927\u5f71\u54cd\uff0c\u56e0\u6b64\u7bb1\u5f62\u56fe\u8bc6\u522b\u5f02\u5e38\u503c\u7684\u7ed3\u679c\u6bd4\u8f83\u5ba2\u89c2\u3002<\/p>\n<p>\u4e0b\u9762\u7ed9\u51fa\u4f7f\u7528\u7bb1\u7ebf\u56fe\u8fdb\u884c\u5f02\u5e38\u503c\u5254\u9664\u7684\u4ee3\u7801\u5757\uff1a<\/p>\n<pre><code class=\"language-python\">def outliers_proc(data, col_name, scale=3):\n    &quot;&quot;&quot;\n    \u7528\u4e8e\u6e05\u6d17\u5f02\u5e38\u503c\uff0c\u9ed8\u8ba4\u7528 box_plot\uff08scale=3\uff09\u8fdb\u884c\u6e05\u6d17\n    :param data: \u63a5\u6536 pandas \u6570\u636e\u683c\u5f0f\n    :param col_name: pandas \u5217\u540d\n    :param scale: \u5c3a\u5ea6\n    :return:\n    &quot;&quot;&quot;\n\n    def box_plot_outliers(data_ser, box_scale):\n        &quot;&quot;&quot;\n        \u5229\u7528\u7bb1\u7ebf\u56fe\u53bb\u9664\u5f02\u5e38\u503c\n        :param data_ser: \u63a5\u6536 pandas.Series \u6570\u636e\u683c\u5f0f\n        :param box_scale: \u7bb1\u7ebf\u56fe\u5c3a\u5ea6\uff0c\n        :return:\n        &quot;&quot;&quot;\n        iqr = box_scale * (data_ser.quantile(0.75) - data_ser.quantile(0.25))\n        val_low = data_ser.quantile(0.25) - iqr\n        val_up = data_ser.quantile(0.75) + iqr\n        rule_low = (data_ser &lt; val_low)\n        rule_up = (data_ser &gt; val_up)\n        return (rule_low, rule_up), (val_low, val_up)\n\n    data_n = data.copy()\n    data_series = data_n[col_name]\n    rule, value = box_plot_outliers(data_series, box_scale=scale)\n    index = np.arange(data_series.shape[0])[rule[0] | rule[1]]\n    print(&quot;Delete number is: {}&quot;.format(len(index)))\n    data_n = data_n.drop(index)\n    data_n.reset_index(drop=True, inplace=True)\n    print(&quot;Now column number is: {}&quot;.format(data_n.shape[0]))\n    index_low = np.arange(data_series.shape[0])[rule[0]]\n    outliers = data_series.iloc[index_low]\n    print(&quot;Description of data less than the lower bound is:&quot;)\n    print(pd.Series(outliers).describe())\n    index_up = np.arange(data_series.shape[0])[rule[1]]\n    outliers = data_series.iloc[index_up]\n    print(&quot;Description of data larger than the upper bound is:&quot;)\n    print(pd.Series(outliers).describe())\n\n    fig, ax = plt.subplots(1, 2, figsize=(10, 7))\n    sns.boxplot(y=data[col_name], data=data, palette=&quot;Set1&quot;, ax=ax[0])\n    sns.boxplot(y=data_n[col_name], data=data_n, palette=&quot;Set1&quot;, ax=ax[1])\n    return data_n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u53c2\u8003\u300a\u96f6\u57fa\u7840\u5165\u95e8\u6570\u636e\u6316\u6398 &#8211; \u4e8c\u624b\u8f66\u4ea4\u6613\u4ef7\u683c\u9884\u6d4b\u300b\u90e8\u5206\u5185\u5bb9\u548c\u4ee3\u7801\uff0c\u6570\u636e\u96c6\u4e3a\u81ea\u5efa\u6570\u636e\u96c6\u3002\u8bfb\u8005\u53ef\u4f7f\u7528\u539f\u6587\u6570\u636e\u96c6\u8fdb\u884c\u9605\u8bfb\u8bd5\u9a8c\u3002 \u5e38\u89c1 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[2],"tags":[16],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-algorithm_learning","tag-16"],"_links":{"self":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":6,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/posts\/170\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lingbo.online\/index.php\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}