{"id":98993,"date":"2022-03-15T23:17:32","date_gmt":"2022-03-15T15:17:32","guid":{"rendered":"http:\/\/www.zhushiyao.com\/?p=98993"},"modified":"2022-03-15T23:18:01","modified_gmt":"2022-03-15T15:18:01","slug":"16491bc223","status":"publish","type":"post","link":"http:\/\/www.zhushiyao.com\/?p=98993","title":{"rendered":"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09"},"content":{"rendered":"<div class=\"bpp-post-content\">\n<section style=\"font-size: 16px; padding-right: 10px; padding-left: 10px; word-break: break-word; text-align: left; line-height: 1.75; color: #595959; font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light; letter-spacing: 0.5px; background-size: 20px 20px; background-position: center center;\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u672c\u7bc7\u548c\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e2a\u7ecf\u5178\u7684\u5f02\u5e38\u68c0\u6d4b\u7b97\u6cd5\uff1a\u5c40\u90e8\u79bb\u7fa4\u56e0\u5b50(Local Outlier Factor)\uff0c\u7b80\u79f0<strong>LOF\u7b97\u6cd5<\/strong>\u3002<\/p>\n<h2 style=\"font-weight: bold; color: black; font-size: 22px; margin-top: 20px; margin-right: 10px;\"><span style=\"font-size: 18px; display: inline-block; padding-left: 10px; border-left: 5px solid #2e9afe; color: #282828;\">\u80cc\u666f<\/span><\/h2>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">Local Outlier Factor\uff08LOF\uff09\u662f\u57fa\u4e8e\u5bc6\u5ea6\u7684\u7ecf\u5178\u7b97\u6cd5\uff08Breuning et. al. 2000\uff09, \u6587\u7ae0\u53d1\u8868\u4e8e SIGMOD 2000, \u5230\u76ee\u524d\u5df2\u7ecf\u6709 3000+ \u7684\u5f15\u7528\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u5728 LOF \u4e4b\u524d\u7684\u5f02\u5e38\u68c0\u6d4b\u7b97\u6cd5\u5927\u591a\u662f\u57fa\u4e8e\u7edf\u8ba1\u65b9\u6cd5\u7684\uff0c\u6216\u8005\u662f\u501f\u7528\u4e86\u4e00\u4e9b\u805a\u7c7b\u7b97\u6cd5\u7528\u4e8e\u5f02\u5e38\u70b9\u7684\u8bc6\u522b\uff08\u6bd4\u5982 \uff0cDBSCAN\uff0cOPTICS\uff09\u3002\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u6709\u4e00\u4e9b\u4e0d\u5b8c\u7f8e\u7684\u5730\u65b9\uff1a<\/p>\n<ul class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px; list-style-type: circle;\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #282828;\">\u57fa\u4e8e\u7edf\u8ba1\u7684\u65b9\u6cd5\uff1a\u901a\u5e38\u9700\u8981\u5047\u8bbe\u6570\u636e\u670d\u4ece\u7279\u5b9a\u7684\u6982\u7387\u5206\u5e03\uff0c\u8fd9\u4e2a\u5047\u8bbe\u5f80\u5f80\u662f\u4e0d\u6210\u7acb\u7684\u3002<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #282828;\">\u805a\u7c7b\u65b9\u6cd5\uff1a\u901a\u5e38\u53ea\u80fd\u7ed9\u51fa 0\/1 \u7684\u5224\u65ad\uff08\u5373\uff1a\u662f\u4e0d\u662f\u5f02\u5e38\u70b9\uff09\uff0c\u4e0d\u80fd\u91cf\u5316\u6bcf\u4e2a\u6570\u636e\u70b9\u7684\u5f02\u5e38\u7a0b\u5ea6\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>\u76f8\u6bd4\u8f83\u800c\u8a00\uff0c\u57fa\u4e8e\u5bc6\u5ea6\u7684LOF\u7b97\u6cd5\u8981\u66f4\u7b80\u5355\u3001\u76f4\u89c2\u3002\u5b83\u4e0d\u9700\u8981\u5bf9\u6570\u636e\u7684\u5206\u5e03\u505a\u592a\u591a\u8981\u6c42\uff0c\u8fd8\u80fd\u91cf\u5316\u6bcf\u4e2a\u6570\u636e\u70b9\u7684\u5f02\u5e38\u7a0b\u5ea6\uff08outlierness\uff09\u3002<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u4e0b\u9762\u5f00\u59cb\u6b63\u5f0f\u4ecb\u7ecdLOF\u7b97\u6cd5\u3002<\/p>\n<h2 style=\"font-weight: bold; color: black; font-size: 22px; margin-top: 20px; margin-right: 10px;\"><span style=\"font-size: 18px; display: inline-block; padding-left: 10px; border-left: 5px solid #2e9afe; color: #282828;\">LOF \u7b97\u6cd5<\/span><\/h2>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u9996\u5148\uff0c\u57fa\u4e8e\u5bc6\u5ea6\u7684\u79bb\u7fa4\u70b9\u68c0\u6d4b\u65b9\u6cd5\u6709\u4e00\u4e2a\u57fa\u672c\u5047\u8bbe\uff1a<strong>\u975e\u79bb\u7fa4\u70b9\u5bf9\u8c61\u5468\u56f4\u7684\u5bc6\u5ea6\u4e0e\u5176\u90bb\u57df\u5468\u56f4\u7684\u5bc6\u5ea6\u7c7b\u4f3c\uff0c\u800c\u79bb\u7fa4\u70b9\u5bf9\u8c61\u5468\u56f4\u7684\u5bc6\u5ea6\u663e\u8457\u4e0d\u540c\u4e8e\u5176\u90bb\u57df\u5468\u56f4\u7684\u5bc6\u5ea6\u3002<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u4ec0\u4e48\u610f\u601d\u5462\uff1f\u770b\u4e0b\u9762\u56fe\u7247\u611f\u53d7\u4e0b\u3002<\/p>\n<figure style=\"margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"border-radius: 6px; display: block; margin: 20px auto; object-fit: contain;\" title=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2022\/03\/4-1647357452.png\" alt=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" \/><\/figure>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u96c6\u7fa4 <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">C1<\/code> \u5305\u542b\u4e86 400 \u591a\u4e2a\u70b9\uff0c\u96c6\u7fa4 <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">C2<\/code> \u5305\u542b 100 \u4e2a\u70b9\u3002<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">C1<\/code> \u548c <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">C2<\/code> \u90fd\u662f\u4e00\u7c7b\u96c6\u7fa4\u70b9\uff0c\u533a\u522b\u662f <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">C1<\/code> \u4f4d\u7f6e\u6bd4\u8f83\u96c6\u4e2d\uff0c\u6216\u8005\u8bf4\u5bc6\u5ea6\u6bd4\u8f83\u5927\u3002\u800c\u50cf <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">o1<\/code>\u3001<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">o2<\/code>\u70b9\u5747\u4e3a\u5f02\u5e38\u70b9\uff0c\u56e0\u4e3a\u57fa\u4e8e\u6211\u4eec\u7684\u5047\u8bbe\uff0c\u8fd9\u4e24\u4e2a\u70b9\u5468\u56f4\u7684\u5bc6\u5ea6\u663e\u8457\u4e0d\u540c\u4e8e\u5468\u56f4\u70b9\u7684\u5bc6\u5ea6\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>LOF \u5c31\u662f\u57fa\u4e8e\u5bc6\u5ea6\u6765\u5224\u65ad\u5f02\u5e38\u70b9\u7684\uff0c\u901a\u8fc7\u7ed9\u6bcf\u4e2a\u6570\u636e\u70b9\u90fd\u5206\u914d\u4e00\u4e2a\u4f9d\u8d56\u4e8e\u90bb\u57df\u5bc6\u5ea6\u7684\u79bb\u7fa4\u56e0\u5b50 LOF\uff0c\u8fdb\u800c\u5224\u65ad\u8be5\u6570\u636e\u70b9\u662f\u5426\u4e3a\u79bb\u7fa4\u70b9\u3002<\/strong> \u5982\u679c \uff0c\u5219\u8be5\u70b9\u4e3a\u79bb\u7fa4\u70b9\uff0c\u5982\u679c \uff0c\u5219\u8be5\u70b9\u4e3a\u6b63\u5e38\u6570\u636e\u70b9\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u90a3\u4ec0\u4e48\u662fLOF\u5462\uff1f<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u4e86\u89e3LOF\u524d\uff0c\u5fc5\u987b\u5148\u77e5\u9053\u4e00\u4e0b\u51e0\u4e2a\u57fa\u672c\u6982\u5ff5\uff0c\u56e0\u4e3aLOF\u662f\u57fa\u4e8e\u8fd9\u51e0\u4e2a\u6982\u5ff5\u800c\u6765\u7684\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>1. k\u90bb\u8fd1\u8ddd\u79bb<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u5728\u8ddd\u79bb\u6570\u636e\u70b9 \u6700\u8fd1\u7684\u51e0\u4e2a\u70b9\u4e2d\uff0c\u7b2c \u4e2a\u6700\u8fd1\u7684\u70b9\u8ddf\u70b9 \u4e4b\u95f4\u7684\u8ddd\u79bb\u79f0\u4e3a\u70b9 \u7684 K-\u90bb\u8fd1\u8ddd\u79bb\uff0c\u8bb0\u4e3a k-distance (p)\uff0c\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<section style=\"text-align: center; overflow: auto;\" role=\"presentation\"><\/section>\n<blockquote style=\"border-top: none; border-right: none; border-bottom: none; font-size: 0.9em; overflow: auto; color: #6a737d; padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px; text-size-adjust: 100%; line-height: 1.55em; box-sizing: inherit; background: #fafafa; border-left-width: 2px; border-left-color: #2e9afe;\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; letter-spacing: 1px; word-spacing: 2px; line-height: 26px; color: #595959; font-size: 13px;\">\u70b9 \u4e3a\u8ddd\u79bb\u70b9 \u6700\u8fd1\u7684\u7b2c \u4e2a\u70b9\u3002<\/p>\n<\/blockquote>\n<figure style=\"margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"border-radius: 6px; display: block; margin: 20px auto; object-fit: contain;\" title=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2022\/03\/1-1647357452.png\" alt=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" \/><\/figure>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u6bd4\u5982\u4e0a\u56fe\u4e2d\uff0c\u8ddd\u79bb\u70b9 \u6700\u8fd1\u7684\u7b2c \u4e2a\u70b9\u662f\u70b9 \u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u8fd9\u91cc\u7684\u8ddd\u79bb\u8ba1\u7b97\u53ef\u4ee5\u91c7\u7528\u6b27\u5f0f\u8ddd\u79bb\u3001\u6c49\u660e\u8ddd\u79bb\u3001\u9a6c\u6c0f\u8ddd\u79bb\u7b49\u7b49\u3002\u6bd4\u5982\u7528\u6b27\u5f0f\u8ddd\u79bb\u7684\u8ba1\u7b97\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<section style=\"text-align: center; overflow: auto;\" role=\"presentation\"><embed style=\"vertical-align: -2.864ex; width: 35.27ex; height: auto; max-width: 300% !important;\" src=\"https:\/\/mmbiz.qlogo.cn\/mmbiz_svg\/Hp9HAaP9GFAk4e4NCyIrQ09sYTSfZpg3fvYk3RxCuq0KyXrSPS6wgW05htIKmkuOdmhOe9k5grnFKxqnKwHHLib7BxUCIIIvE\/0?wx_fmt=svg\" width=\"300\" height=\"150\"><\/embed><\/section>\n<blockquote style=\"border-top: none; border-right: none; border-bottom: none; font-size: 0.9em; overflow: auto; color: #6a737d; padding: 10px 10px 10px 20px; margin-bottom: 20px; margin-top: 20px; text-size-adjust: 100%; line-height: 1.55em; box-sizing: inherit; background: #fafafa; border-left-width: 2px; border-left-color: #2e9afe;\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; letter-spacing: 1px; word-spacing: 2px; line-height: 26px; color: #595959; font-size: 13px;\">\u8fd9\u91cc\u7684\u91cd\u70b9\u662f\u627e\u5230\u7b2c \u4e2a\u6700\u8fd1\u7684\u90a3\u4e2a\u70b9\uff0c\u7136\u540e\u5e26\u516c\u5f0f\u8ba1\u7b97\u8ddd\u79bb\u3002<\/p>\n<\/blockquote>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>2. k\u8ddd\u79bb\u9886\u57df<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u4ee5\u70b9 \u4e3a\u5706\u5fc3\uff0c\u4ee5k\u90bb\u8fd1\u8ddd\u79bb \u4e3a\u534a\u5f84\u753b\u5706\uff0c\u8fd9\u4e2a\u5706\u4ee5\u5185\u7684\u8303\u56f4\u5c31\u662fk\u8ddd\u79bb\u9886\u57df\uff0c\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<section style=\"text-align: center; overflow: auto;\" role=\"presentation\"><embed style=\"vertical-align: -0.791ex; width: 28.21ex; height: auto; max-width: 300% !important;\" src=\"https:\/\/mmbiz.qlogo.cn\/mmbiz_svg\/Hp9HAaP9GFAk4e4NCyIrQ09sYTSfZpg3tBbrDZOF0zrfibBfDdAg6ubmzoKsl0WMxnWPibvC5RRgPVR4P2HLz2VnYzp2XdfjwM\/0?wx_fmt=svg\" width=\"300\" height=\"150\"><\/embed><\/section>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u8fd8\u662f\u4e0a\u56fe\u6240\u793a\uff0c\u5047\u8bbek=4\uff0c\u90a3\u4e48\u70b9 1-6 \u5747\u662f\u90bb\u57df\u8303\u56f4\u5185\u7684\u70b9\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>3. \u53ef\u8fbe\u8ddd\u79bb<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u8fd9\u4e2a\u53ef\u8fbe\u8ddd\u79bb\u5927\u5bb6\u9700\u8981\u7559\u610f\u70b9\uff0c\u70b9 \u5230\u70b9 \u7684\u7b2c \u53ef\u8fbe\u8ddd\u79bb\uff1a<\/p>\n<section style=\"text-align: center; overflow: auto;\" role=\"presentation\"><embed style=\"vertical-align: -0.791ex; width: 41.587ex; height: auto; max-width: 300% !important;\" src=\"https:\/\/mmbiz.qlogo.cn\/mmbiz_svg\/Hp9HAaP9GFAk4e4NCyIrQ09sYTSfZpg3ib7LrbxSDOwPzMPJaQpzzNUTV4iblrrpBkmKs7hOmc9ymeDM57JqBxcJpXey5eXwoY\/0?wx_fmt=svg\" width=\"300\" height=\"150\"><\/embed><\/section>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u8fd9\u91cc\u8ba1\u7b97 \u5230\u70b9 \u7684\u7b2c \u53ef\u8fbe\u8ddd\u79bb\uff0c\u4f46\u662f\u8981\u4ee5\u70b9 \u4e3a\u4e2d\u5fc3\uff0c\u53d6\u4e00\u4e2a\u6700\u5927\u503c\uff0c\u4e5f\u5c31\u662f\u5728\u70b9 \u4e0e \u7684\u8ddd\u79bb\u3001\u8ddd\u79bb\u70b9 \u6700\u8fd1\u7684\u7b2c \u4e2a\u70b9\u8ddd\u79bb\u4e2d\u53d6\u8f83\u5927\u7684\u4e00\u4e2a\uff0c\u5982\u56fe\u4e0b\u6240\u793a\u3002<\/p>\n<figure style=\"margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"border-radius: 6px; display: block; margin: 20px auto; object-fit: contain;\" title=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2022\/03\/0-1647357452.png\" alt=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" \/><\/figure>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u8ddd\u79bb \u8fdc\uff0c\u90a3\u4e48\u4e24\u8005\u4e4b\u95f4\u7684\u53ef\u8fbe\u8ddd\u79bb\u5c31\u662f\u5b83\u4eec\u7684\u5b9e\u9645\u8ddd\u79bb\u3002\u5982\u679c\u8ddd\u79bb\u8db3\u591f\u8fd1\uff0c\u5982\u70b9 \uff0c\u5b9e\u9645\u8ddd\u79bb\u5c06\u88ab \u7684 \u8ddd\u79bb\u4ee3\u66ff\u3002\u6240\u6709 \u63a5\u8fd1 \u7684\u7edf\u8ba1\u6ce2\u52a8 \u53ef\u4ee5\u663e\u8457\u51cf\u5c11\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570 \u6765\u63a7\u5236\uff0c \u503c\u8d8a\u9ad8\uff0c\u540c\u4e00\u90bb\u57df\u5185\u7684\u70b9\u7684\u53ef\u8fbe\u8ddd\u79bb\u8d8a\u76f8\u4f3c\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>4. \u5c40\u90e8\u53ef\u8fbe\u5bc6\u5ea6<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u5148\u7ed9\u51fa\u516c\u5f0f\u3002<\/p>\n<section style=\"text-align: center; overflow: auto;\" role=\"presentation\"><embed style=\"vertical-align: -3.97ex; width: 31.442ex; height: auto; max-width: 300% !important;\" src=\"https:\/\/mmbiz.qlogo.cn\/mmbiz_svg\/Hp9HAaP9GFAk4e4NCyIrQ09sYTSfZpg3aVkcVHia6MHRK6gNNOK2peYp5ibk2vgqken7tMLwo0lsUnkM3stmYN3VYsVETVdd20\/0?wx_fmt=svg\" width=\"300\" height=\"150\"><\/embed><\/section>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u6570\u636e\u70b9 \u7684\u5c40\u90e8\u53ef\u8fbe\u5bc6\u5ea6\u5c31\u662f\u57fa\u4e8e \u7684\u6700\u8fd1\u90bb\u7684\u5e73\u5747\u53ef\u8fbe\u8ddd\u79bb\u7684\u5012\u6570\u3002\u8ddd\u79bb\u8d8a\u5927\uff0c\u5bc6\u5ea6\u8d8a\u5c0f\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>5. \u5c40\u90e8\u5f02\u5e38\u56e0\u5b50<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u6839\u636e\u5c40\u90e8\u53ef\u8fbe\u5bc6\u5ea6\u7684\u5b9a\u4e49\uff0c\u5982\u679c\u4e00\u4e2a\u6570\u636e\u70b9\u8ddf\u5176\u4ed6\u70b9\u6bd4\u8f83\u758f\u8fdc\u7684\u8bdd\uff0c\u90a3\u4e48\u663e\u7136\u5b83\u7684\u5c40\u90e8\u53ef\u8fbe\u5bc6\u5ea6\u5c31\u5c0f\u3002<strong>\u4f46LOF\u7b97\u6cd5\u8861\u91cf\u4e00\u4e2a\u6570\u636e\u70b9\u7684\u5f02\u5e38\u7a0b\u5ea6\uff0c\u5e76\u4e0d\u662f\u770b\u5b83\u7684\u7edd\u5bf9\u5c40\u90e8\u5bc6\u5ea6\uff0c\u800c\u662f\u770b\u5b83\u8ddf\u5468\u56f4\u90bb\u8fd1\u7684\u6570\u636e\u70b9\u7684\u76f8\u5bf9\u5bc6\u5ea6\u3002<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u53ef\u4ee5\u5141\u8bb8\u6570\u636e\u5206\u5e03\u4e0d\u5747\u5300\u3001\u5bc6\u5ea6\u4e0d\u540c\u7684\u60c5\u51b5\u3002\u5c40\u90e8\u5f02\u5e38\u56e0\u5b50\u5373\u662f\u7528\u5c40\u90e8\u76f8\u5bf9\u5bc6\u5ea6\u6765\u5b9a\u4e49\u7684\u3002\u6570\u636e\u70b9 \u7684\u5c40\u90e8\u76f8\u5bf9\u5bc6\u5ea6\uff08\u5c40\u90e8\u5f02\u5e38\u56e0\u5b50\uff09\u4e3a\u70b9 \u90bb\u57df\u5185\u70b9\u7684\u5e73\u5747\u5c40\u90e8\u53ef\u8fbe\u5bc6\u5ea6\u8ddf\u6570\u636e\u70b9 \u7684\u5c40\u90e8\u53ef\u8fbe\u5bc6\u5ea6\u7684\u6bd4\u503c\uff0c\u5373\uff1a<\/p>\n<section style=\"text-align: center; overflow: auto;\" role=\"presentation\"><embed style=\"vertical-align: -2.172ex; width: 55.597ex; height: auto; max-width: 300% !important;\" src=\"https:\/\/mmbiz.qlogo.cn\/mmbiz_svg\/Hp9HAaP9GFAk4e4NCyIrQ09sYTSfZpg3IBiaIicKOx5lZejaXia7GAxWTkvcDrHMflY1dQblRzAlMkGOiaWcyFCAd2PA7VCjibGzib\/0?wx_fmt=svg\" width=\"300\" height=\"150\"><\/embed><\/section>\n<h2 style=\"font-weight: bold; color: black; font-size: 22px; margin-top: 20px; margin-right: 10px;\"><span style=\"font-size: 18px; display: inline-block; padding-left: 10px; border-left: 5px solid #2e9afe; color: #282828;\">LOF\u7b97\u6cd5\u6d41\u7a0b<\/span><\/h2>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u4e86\u89e3\u4e86 LOF \u7684\u5b9a\u4e49\u4ee5\u540e\uff0c\u6574\u4e2a\u7b97\u6cd5\u4e5f\u5c31\u663e\u800c\u6613\u89c1\u4e86\uff1a<\/p>\n<ol class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px;\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #282828;\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; font-size: 16px; word-spacing: 2px;\">\u5bf9\u4e8e\u6bcf\u4e2a\u6570\u636e\u70b9\uff0c\u8ba1\u7b97\u5b83\u4e0e\u5176\u5b83\u6240\u6709\u70b9\u7684\u8ddd\u79bb\uff0c\u5e76\u6309\u4ece\u8fd1\u5230\u8fdc\u6392\u5e8f\uff1b<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #282828;\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; font-size: 16px; word-spacing: 2px;\">\u5bf9\u4e8e\u6bcf\u4e2a\u6570\u636e\u70b9\uff0c\u627e\u5230\u5b83\u7684 k-nearest-neighbor\uff0c\u8ba1\u7b97 LOF \u5f97\u5206;<\/p>\n<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #282828;\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; font-size: 16px; word-spacing: 2px;\">\u5982\u679cLOF\u503c\u8d8a\u5927\uff0c\u8bf4\u660e\u8d8a\u5f02\u5e38\uff0c\u53cd\u4e4b\u5982\u679c\u8d8a\u5c0f\uff0c\u8bf4\u660e\u8d8a\u8d8b\u4e8e\u6b63\u5e38\u3002<\/p>\n<\/section>\n<\/li>\n<\/ol>\n<figure style=\"margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"border-radius: 6px; display: block; margin: 20px auto; object-fit: contain;\" title=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2022\/03\/10-1647357452.png\" alt=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" \/><\/figure>\n<h2 style=\"font-weight: bold; color: black; font-size: 22px; margin-top: 20px; margin-right: 10px;\"><span style=\"font-size: 18px; display: inline-block; padding-left: 10px; border-left: 5px solid #2e9afe; color: #282828;\">LOF\u4f18\u7f3a\u70b9<\/span><\/h2>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>\u4f18\u70b9<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">LOF \u7684\u4e00\u4e2a\u4f18\u70b9\u662f\u5b83\u540c\u65f6\u8003\u8651\u4e86\u6570\u636e\u96c6\u7684\u5c40\u90e8\u548c\u5168\u5c40\u5c5e\u6027\u3002\u5f02\u5e38\u503c\u4e0d\u662f\u6309\u7edd\u5bf9\u503c\u786e\u5b9a\u7684\uff0c\u800c\u662f\u76f8\u5bf9\u4e8e\u5b83\u4eec\u7684\u90bb\u57df\u70b9\u5bc6\u5ea6\u786e\u5b9a\u7684\u3002\u5f53\u6570\u636e\u96c6\u4e2d\u5b58\u5728\u4e0d\u540c\u5bc6\u5ea6\u7684\u4e0d\u540c\u96c6\u7fa4\u65f6\uff0cLOF\u8868\u73b0\u826f\u597d\uff0c\u6bd4\u8f83\u9002\u7528\u4e8e\u4e2d\u7b49\u9ad8\u7ef4\u7684\u6570\u636e\u96c6\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>\u7f3a\u70b9<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">LOF\u7b97\u6cd5\u4e2d\u5173\u4e8e\u5c40\u90e8\u53ef\u8fbe\u5bc6\u5ea6\u7684\u5b9a\u4e49\u5176\u5b9e\u6697\u542b\u4e86\u4e00\u4e2a\u5047\u8bbe\uff0c\u5373\uff1a<strong>\u4e0d\u5b58\u5728\u5927\u4e8e\u7b49\u4e8e k \u4e2a\u91cd\u590d\u7684\u70b9\u3002<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u5f53\u8fd9\u6837\u7684\u91cd\u590d\u70b9\u5b58\u5728\u7684\u65f6\u5019\uff0c\u8fd9\u4e9b\u70b9\u7684\u5e73\u5747\u53ef\u8fbe\u8ddd\u79bb\u4e3a\u96f6\uff0c\u5c40\u90e8\u53ef\u8fbe\u5bc6\u5ea6\u5c31\u53d8\u4e3a\u65e0\u7a77\u5927\uff0c\u4f1a\u7ed9\u8ba1\u7b97\u5e26\u6765\u4e00\u4e9b\u9ebb\u70e6\u3002\u5728\u5b9e\u9645\u5e94\u7528\u65f6\uff0c\u4e3a\u4e86\u907f\u514d\u8fd9\u6837\u7684\u60c5\u51b5\u51fa\u73b0\uff0c\u53ef\u4ee5\u628a k-distance \u6539\u4e3a k-distinct-distance\uff0c\u4e0d\u8003\u8651\u91cd\u590d\u7684\u60c5\u51b5\u3002\u6216\u8005\uff0c\u8fd8\u53ef\u4ee5\u8003\u8651\u7ed9\u53ef\u8fbe\u8ddd\u79bb\u90fd\u52a0\u4e00\u4e2a\u5f88\u5c0f\u7684\u503c\uff0c\u907f\u514d\u53ef\u8fbe\u8ddd\u79bb\u7b49\u4e8e\u96f6\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u53e6\u5916\uff0cLOF \u7b97\u6cd5\u9700\u8981\u8ba1\u7b97\u6570\u636e\u70b9\u4e24\u4e24\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u9020\u6210\u6574\u4e2a\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \u3002\u4e3a\u4e86\u63d0\u9ad8\u7b97\u6cd5\u6548\u7387\uff0c\u540e\u7eed\u6709\u7b97\u6cd5\u5c1d\u8bd5\u6539\u8fdb\u3002FastLOF \uff08Goldstein\uff0c2012\uff09\u5148\u5c06\u6574\u4e2a\u6570\u636e\u968f\u673a\u7684\u5206\u6210\u591a\u4e2a\u5b50\u96c6\uff0c\u7136\u540e\u5728\u6bcf\u4e2a\u5b50\u96c6\u91cc\u8ba1\u7b97 LOF \u503c\u3002\u5bf9\u4e8e\u90a3\u4e9b LOF \u5f02\u5e38\u5f97\u5206\u5c0f\u4e8e\u7b49\u4e8e 1 \u7684\uff0c\u4ece\u6570\u636e\u96c6\u91cc\u5254\u9664\uff0c\u5269\u4e0b\u7684\u5728\u4e0b\u4e00\u8f6e\u5bfb\u627e\u66f4\u5408\u9002\u7684 nearest-neighbor\uff0c\u5e76\u66f4\u65b0 LOF \u503c\u3002<\/p>\n<h2 style=\"font-weight: bold; color: black; font-size: 22px; margin-top: 20px; margin-right: 10px;\"><span style=\"font-size: 18px; display: inline-block; padding-left: 10px; border-left: 5px solid #2e9afe; color: #282828;\">Python \u5b9e\u73b0 LOF<\/span><\/h2>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u6709\u4e24\u4e2a\u5e93\u53ef\u4ee5\u8ba1\u7b97LOF\uff0c\u5206\u522b\u662f<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">PyOD<\/code>\u548c<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">Sklearn<\/code>\uff0c\u4e0b\u9762\u5206\u522b\u4ecb\u7ecd\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u4f7f\u7528<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">pyod<\/code>\u81ea\u5e26\u7684\u65b9\u6cd5\u751f\u6210200\u4e2a\u8bad\u7ec3\u6837\u672c\u548c100\u4e2a\u6d4b\u8bd5\u6837\u672c\u7684\u6570\u636e\u96c6\u3002\u6b63\u6001\u6837\u672c\u7531\u591a\u5143\u9ad8\u65af\u5206\u5e03\u751f\u6210\uff0c\u5f02\u5e38\u6837\u672c\u662f\u4f7f\u7528\u5747\u5300\u5206\u5e03\u751f\u6210\u7684\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u8bad\u7ec3\u548c\u6d4b\u8bd5\u6570\u636e\u96c6\u90fd\u6709 5 \u4e2a\u7279\u5f81\uff0c10% \u7684\u884c\u88ab\u6807\u8bb0\u4e3a\u5f02\u5e38\u3002\u5e76\u4e14\u5728\u6570\u636e\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e9b\u968f\u673a\u566a\u58f0\uff0c\u8ba9\u5b8c\u7f8e\u5206\u79bb\u6b63\u5e38\u70b9\u548c\u5f02\u5e38\u70b9\u53d8\u5f97\u7a0d\u5fae\u56f0\u96be\u4e00\u4e9b\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #333333; background: #f8f8f8; display: -webkit-box; font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px;\"><span style=\"font-weight: bold; line-height: 26px;\">from<\/span>\u00a0pyod.utils.data\u00a0<span style=\"font-weight: bold; line-height: 26px;\">import<\/span>\u00a0generate_data\n<span style=\"font-weight: bold; line-height: 26px;\">import<\/span>\u00a0numpy\u00a0<span style=\"font-weight: bold; line-height: 26px;\">as<\/span>\u00a0np\nX_train,\u00a0y_train,\u00a0X_test,\u00a0y_test\u00a0=\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0generate_data(n_train=<span style=\"color: #008080; line-height: 26px;\">200<\/span>,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0n_test=<span style=\"color: #008080; line-height: 26px;\">100<\/span>,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0n_features=<span style=\"color: #008080; line-height: 26px;\">5<\/span>,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0contamination=<span style=\"color: #008080; line-height: 26px;\">0.1<\/span>,\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0random_state=<span style=\"color: #008080; line-height: 26px;\">3<\/span>)\u00a0\nX_train\u00a0=\u00a0X_train\u00a0*\u00a0np.random.uniform(<span style=\"color: #008080; line-height: 26px;\">0<\/span>,\u00a0<span style=\"color: #008080; line-height: 26px;\">1<\/span>,\u00a0size=X_train.shape)\nX_test\u00a0=\u00a0X_test\u00a0*\u00a0np.random.uniform(<span style=\"color: #008080; line-height: 26px;\">0<\/span>,<span style=\"color: #008080; line-height: 26px;\">1<\/span>,\u00a0size=X_test.shape)\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>PyOD<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u4e0b\u9762\u5c06\u8bad\u7ec3\u6570\u636e\u62df\u5408\u4e86 LOF \u6a21\u578b\u5e76\u5c06\u5176\u5e94\u7528\u4e8e\u5408\u6210\u6d4b\u8bd5\u6570\u636e\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u5728 <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">PyOD<\/code> \u4e2d\uff0c\u6709\u4e24\u4e2a\u5173\u952e\u65b9\u6cd5\uff1a<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">decision_function<\/code> \u548c <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">predict<\/code>\u3002<\/p>\n<ul class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px; font-size: 15px; list-style-type: circle;\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #282828;\">decision_function\uff1a\u8fd4\u56de\u6bcf\u4e00\u884c\u7684\u5f02\u5e38\u5206\u6570<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #282828;\">predict\uff1a\u8fd4\u56de\u4e00\u4e2a\u7531 0 \u548c 1 \u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u6307\u793a\u6bcf\u4e00\u884c\u88ab\u9884\u6d4b\u4e3a\u6b63\u5e38 (0) \u8fd8\u662f\u5f02\u5e38\u503c (1)<\/section>\n<\/li>\n<\/ul>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #333333; background: #f8f8f8; display: -webkit-box; font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px;\"><span style=\"font-weight: bold; line-height: 26px;\">from<\/span>\u00a0pyod.models.lof\u00a0<span style=\"font-weight: bold; line-height: 26px;\">import<\/span>\u00a0LOF\nclf_name\u00a0=\u00a0<span style=\"color: #d14; line-height: 26px;\">'LOF'<\/span>\nclf\u00a0=\u00a0LOF()\nclf.fit(X_train)\n\ntest_scores\u00a0=\u00a0clf.decision_function(X_test)\n\nroc\u00a0=\u00a0round(roc_auc_score(y_test,\u00a0test_scores),\u00a0ndigits=<span style=\"color: #008080; line-height: 26px;\">4<\/span>)\nprn\u00a0=\u00a0round(precision_n_scores(y_test,\u00a0test_scores),\u00a0ndigits=<span style=\"color: #008080; line-height: 26px;\">4<\/span>)\n\nprint(<span style=\"color: #d14; line-height: 26px;\">f'<span style=\"color: #333333; line-height: 26px;\">{clf_name}<\/span>\u00a0ROC:<span style=\"color: #333333; line-height: 26px;\">{roc}<\/span>,\u00a0precision\u00a0@\u00a0rank\u00a0n:<span style=\"color: #333333; line-height: 26px;\">{prn}<\/span>'<\/span>)\n&gt;&gt;\u00a0LOF\u00a0ROC:<span style=\"color: #008080; line-height: 26px;\">0.9656<\/span>,\u00a0precision\u00a0@\u00a0rank\u00a0n:<span style=\"color: #008080; line-height: 26px;\">0.8<\/span>\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u53ef\u4ee5\u901a\u8fc7 LOF \u6a21\u578b\u65b9\u6cd5\u67e5\u770b LOF \u5206\u6570\u7684\u5206\u5e03\u3002\u5728\u4e0b\u56fe\u4e2d\u770b\u5230\u6b63\u5e38\u6570\u636e\uff08\u84dd\u8272\uff09\u7684\u5206\u6570\u805a\u96c6\u5728 1.0 \u5de6\u53f3\u3002\u79bb\u7fa4\u6570\u636e\u70b9\uff08\u6a59\u8272\uff09\u7684\u5f97\u5206\u5747\u5927\u4e8e 1.0\uff0c\u4e00\u822c\u9ad8\u4e8e\u6b63\u5e38\u6570\u636e\u3002<\/p>\n<figure style=\"margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"border-radius: 6px; display: block; margin: 20px auto; object-fit: contain;\" title=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2022\/03\/3-1647357452.png\" alt=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" \/><\/figure>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong>Sklearn<\/strong><\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u5728<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">scikit-learn<\/code>\u4e2d\u5b9e\u73b0 <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">LOF<\/code> \u8fdb\u884c\u5f02\u5e38\u68c0\u6d4b\u65f6\uff0c\u6709\u4e24\u79cd\u6a21\u5f0f\u9009\u62e9\uff1a\u5f02\u5e38\u68c0\u6d4b\u6a21\u5f0f <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">(novelty=False)<\/code> \u548c novelty\u68c0\u6d4b\u6a21\u5f0f <code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">(novelty=True)<\/code>\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u5728\u5f02\u5e38\u68c0\u6d4b\u6a21\u5f0f\u4e0b\uff0c\u53ea\u6709<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">fit_predict<\/code>\u751f\u6210\u79bb\u7fa4\u70b9\u9884\u6d4b\u7684\u65b9\u6cd5\u53ef\u7528\u3002\u53ef\u4ee5\u4f7f\u7528<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">negative_outlier_factor_<\/code>\u5c5e\u6027\u68c0\u7d22\u8bad\u7ec3\u6570\u636e\u7684\u5f02\u5e38\u503c\u5206\u6570\uff0c\u4f46\u65e0\u6cd5\u4e3a\u672a\u89c1\u8fc7\u7684\u6570\u636e\u751f\u6210\u5206\u6570\u3002\u6a21\u578b\u4f1a\u6839\u636e<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">contamination<\/code>\u53c2\u6570\uff08\u9ed8\u8ba4\u503c\u4e3a 0.1\uff09\u81ea\u52a8\u9009\u62e9\u5f02\u5e38\u503c\u7684\u9608\u503c\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #333333; background: #f8f8f8; display: -webkit-box; font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px;\"><span style=\"font-weight: bold; line-height: 26px;\">import<\/span>\u00a0matplotlib.pyplot\u00a0<span style=\"font-weight: bold; line-height: 26px;\">as<\/span>\u00a0plt\n\ndetector\u00a0=\u00a0LOF()\nscores\u00a0=\u00a0detector.fit(X_train).decision_function(X_test)\n\nsns.distplot(scores[y_test==<span style=\"color: #008080; line-height: 26px;\">0<\/span>],\u00a0label=<span style=\"color: #d14; line-height: 26px;\">\"inlier\u00a0scores\"<\/span>)\nsns.distplot(scores[y_test==<span style=\"color: #008080; line-height: 26px;\">1<\/span>],\u00a0label=<span style=\"color: #d14; line-height: 26px;\">\"outlier\u00a0scores\"<\/span>).set_title(<span style=\"color: #d14; line-height: 26px;\">\"Distribution\u00a0of\u00a0Outlier\u00a0Scores\u00a0from\u00a0LOF\u00a0Detector\"<\/span>)\nplt.legend()\nplt.xlabel(<span style=\"color: #d14; line-height: 26px;\">\"Outlier\u00a0score\"<\/span>)\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u5728novelty\u68c0\u6d4b\u6a21\u5f0f\u4e0b\uff0c\u53ea\u6709<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">decision_function<\/code>\u7528\u4e8e\u751f\u6210\u5f02\u5e38\u503c\u53ef\u7528\u3002<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">fit_predict<\/code>\u65b9\u6cd5\u4e0d\u53ef\u7528\uff0c\u4f46<code style=\"padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all; color: #595959; font-size: 13px; letter-spacing: 0.5px;\">predict<\/code>\u65b9\u6cd5\u53ef\u7528\u4e8e\u751f\u6210\u5f02\u5e38\u503c\u9884\u6d4b\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px;\"><code style=\"overflow-x: auto; padding: 16px; color: #333333; background: #f8f8f8; display: -webkit-box; font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px;\">clf\u00a0=\u00a0LocalOutlierFactor(novelty=<span style=\"color: #008080; line-height: 26px;\">True<\/span>)\nclf\u00a0=\u00a0clf.fit(X_train)\ntest_scores\u00a0=\u00a0clf.decision_function(X_test)\n\ntest_scores\u00a0=\u00a0<span style=\"color: #008080; line-height: 26px;\">-1<\/span>*test_scores\n\nroc\u00a0=\u00a0round(roc_auc_score(y_test,\u00a0test_scores),\u00a0ndigits=<span style=\"color: #008080; line-height: 26px;\">4<\/span>)\nprn\u00a0=\u00a0round(precision_n_scores(y_test,\u00a0test_scores),\u00a0ndigits=<span style=\"color: #008080; line-height: 26px;\">4<\/span>)\n\nprint(<span style=\"color: #d14; line-height: 26px;\">f'<span style=\"color: #333333; line-height: 26px;\">{clf_name}<\/span>\u00a0ROC:<span style=\"color: #333333; line-height: 26px;\">{roc}<\/span>,\u00a0precision\u00a0@\u00a0rank\u00a0n:<span style=\"color: #333333; line-height: 26px;\">{prn}<\/span>'<\/span>)\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\">\u8be5\u6a21\u5f0f\u4e0b\u6a21\u578b\u7684\u5f02\u5e38\u503c\u5206\u6570\u88ab\u53cd\u8f6c\uff0c\u5f02\u5e38\u503c\u7684\u5206\u6570\u4f4e\u4e8e\u6b63\u5e38\u503c\u3002<\/p>\n<figure style=\"margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img\" style=\"border-radius: 6px; display: block; margin: 20px auto; object-fit: contain;\" title=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2022\/03\/9-1647357452-1.png\" alt=\"\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\" \/><\/figure>\n<section style=\"padding-top: 8px; padding-bottom: 8px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px; line-height: 2em;\">\u5b9e\u6218\u7cfb\u5217\u7684\u5168\u90e8\u5b8c\u6574\u4ee3\u7801\u53ef\u89c1\u6211\u7684GitHub\uff1a<span style=\"font-size: 14px;\">https:\/\/github.com\/xiaoyusmd\/PythonDataScience<\/span><\/section>\n<p style=\"padding-top: 8px; padding-bottom: 8px; line-height: 26px; color: #282828; margin-top: 10px; margin-bottom: 10px; letter-spacing: 1px; word-spacing: 2px;\"><strong><strong style=\"color: #282828; font-family: Optima-Regular, Optima, PingFangTC-Light, PingFangSC-light, PingFangTC-light; font-size: 16px; letter-spacing: 1px; text-align: left; white-space: normal; word-spacing: 2px;\">\u8f6c\u81ea\uff1ahttps:\/\/mp.weixin.qq.com\/s\/9ANa5QKV65ZEWCaisWDjEA<br \/>\n<\/strong><\/strong><\/p>\n<\/section>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u548c\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e2a\u7ecf\u5178\u7684\u5f02\u5e38\u68c0\u6d4b\u7b97\u6cd5\uff1a\u5c40\u90e8\u79bb\u7fa4\u56e0\u5b50(Local Outlier Factor)\uff0c\u7b80\u79f0LOF\u7b97\u6cd5 &hellip; <a href=\"http:\/\/www.zhushiyao.com\/?p=98993\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u4e00\u6587\u8bfb\u61c2\u5f02\u5e38\u68c0\u6d4b LOF \u7b97\u6cd5\uff08Python\u4ee3\u7801\uff09\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[8],"_links":{"self":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/98993"}],"collection":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=98993"}],"version-history":[{"count":2,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/98993\/revisions"}],"predecessor-version":[{"id":99004,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/98993\/revisions\/99004"}],"wp:attachment":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=98993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=98993"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=98993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}