{"id":554108,"date":"2025-04-03T08:14:14","date_gmt":"2025-04-03T07:14:14","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=pycharm&#038;p=554108"},"modified":"2025-04-03T08:14:22","modified_gmt":"2025-04-03T07:14:22","slug":"anomaly-detection-in-time-series","status":"publish","type":"pycharm","link":"https:\/\/blog.jetbrains.com\/zh-hans\/pycharm\/2025\/04\/anomaly-detection-in-time-series\/","title":{"rendered":"\u65f6\u95f4\u5e8f\u5217\u4e2d\u7684\u5f02\u5e38\u68c0\u6d4b"},"content":{"rendered":"<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-556345 size-full\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/04\/pc-featured_blog_1280x720_en-2.png\" alt=\"\" width=\"2560\" height=\"1440\" \/><\/figure>\n<p>\u5982\u4f55\u8bc6\u522b\u6570\u636e\u4e2d\u53ef\u80fd\u63ed\u793a\u5173\u952e\u95ee\u9898\u6216\u9690\u85cf\u673a\u9047\u7684\u5f02\u5e38\u6a21\u5f0f\uff1f <a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-machine-learning\/\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-machine-learning\/\">\u5f02\u5e38\u68c0\u6d4b<\/a>\u6709\u52a9\u4e8e\u8bc6\u522b\u4e25\u91cd\u504f\u79bb\u5e38\u89c4\u7684\u6570\u636e\u3002 \u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7531\u4e00\u6bb5\u65f6\u95f4\u5185\u6536\u96c6\u7684\u6570\u636e\u7ec4\u6210\uff0c\u901a\u5e38\u5305\u62ec\u8d8b\u52bf\u548c\u5b63\u8282\u6027\u6a21\u5f0f\u3002 \u5f53\u6a21\u5f0f\u88ab\u6253\u4e71\u65f6\uff0c\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u4e2d\u5c31\u4f1a\u51fa\u73b0\u5f02\u5e38\uff0c\u5f02\u5e38\u68c0\u6d4b\u4e5f\u56e0\u6b64\u6210\u4e3a\u9500\u552e\u3001\u91d1\u878d\u3001\u5236\u9020\u548c\u533b\u7597\u7b49\u884c\u4e1a\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<p>\u7531\u4e8e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5177\u6709\u5b63\u8282\u6027\u548c\u8d8b\u52bf\u7b49\u7279\u5f81\uff0c\u9700\u8981\u4e13\u95e8\u7684\u65b9\u6cd5\u6765\u6709\u6548\u68c0\u6d4b\u5f02\u5e38\u3002 \u5728\u8fd9\u7bc7\u535a\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u4e00\u4e9b\u6d41\u884c\u7684\u65f6\u95f4\u5e8f\u5217\u5f02\u5e38\u68c0\u6d4b\u65b9\u6cd5\uff0c\u5305\u62ec STL \u5206\u89e3\u548c LSTM \u9884\u6d4b\uff0c\u5e76\u63d0\u4f9b\u8be6\u7ec6\u7684\u4ee3\u7801\u793a\u4f8b\u5e2e\u52a9\u60a8\u5165\u95e8\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u4f01\u4e1a\u4e2d\u7684\u65f6\u95f4\u5e8f\u5217\u5f02\u5e38\u68c0\u6d4b<\/h2>\n<p>\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5bf9\u8bb8\u591a\u4f01\u4e1a\u548c\u670d\u52a1\u81f3\u5173\u91cd\u8981\u3002 \u8bb8\u591a\u4f01\u4e1a\u4f7f\u7528\u65f6\u95f4\u6233\u8bb0\u5f55\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u6570\u636e\uff0c\u7531\u6b64\u5206\u6790\u53d8\u5316\u548c\u6bd4\u8f83\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u6570\u636e\u3002 \u65f6\u95f4\u5e8f\u5217\u5728\u6bd4\u8f83\u4e00\u5b9a\u65f6\u6bb5\u5185\u7684\u4e00\u5b9a\u6570\u91cf\u65f6\u5f88\u6709\u7528\uff0c\u4f8b\u5982\uff0c\u5728\u6570\u636e\u8868\u73b0\u51fa\u5b63\u8282\u6027\u7279\u5f81\u7684\u540c\u6bd4\u6bd4\u8f83\u4e2d\u3002<\/p>\n<p><strong>\u9500\u552e\u76d1\u6d4b<\/strong><\/p>\n<p>\u9500\u552e\u6570\u636e\u662f\u5e26\u6709\u5b63\u8282\u6027\u7279\u5f81\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u6700\u5e38\u89c1\u793a\u4f8b\u4e4b\u4e00\u3002 \u8bb8\u591a\u9500\u552e\u989d\u4f1a\u53d7\u5230\u5e74\u5ea6\u5047\u671f\u548c\u5e74\u4e2d\u65f6\u95f4\u7684\u5f71\u54cd\uff0c\u56e0\u6b64\u5982\u679c\u4e0d\u8003\u8651\u5b63\u8282\u6027\u56e0\u7d20\uff0c\u5c31\u5f88\u96be\u5f97\u51fa\u6709\u5173\u9500\u552e\u6570\u636e\u7684\u7ed3\u8bba\u3002 \u5206\u6790\u548c\u67e5\u627e\u9500\u552e\u6570\u636e\u5f02\u5e38\u7684\u5e38\u7528\u65b9\u6cd5\u662f STL \u5206\u89e3\uff0c\u6211\u4eec\u5c06<a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/#stl-beehive\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/#stl-beehive\">\u5728\u8fd9\u7bc7\u535a\u6587\u7684\u540e\u7eed\u90e8\u5206<\/a>\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p><strong>\u91d1\u878d<\/strong><\/p>\n<p>\u4ea4\u6613\u548c\u80a1\u7968\u4ef7\u683c\u7b49\u91d1\u878d\u6570\u636e\u662f\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u5178\u578b\u793a\u4f8b\u3002 \u5728\u91d1\u878d\u884c\u4e1a\uff0c\u5206\u6790\u548c\u68c0\u6d4b\u8fd9\u4e9b\u6570\u636e\u4e2d\u7684\u5f02\u5e38\u662f\u4e00\u79cd\u5e38\u89c1\u505a\u6cd5\u3002 \u4f8b\u5982\uff0c\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u6a21\u578b\u53ef\u7528\u4e8e\u81ea\u52a8\u4ea4\u6613\u3002 <a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/#lstm-stock\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/#lstm-stock\">\u5728\u8fd9\u7bc7\u535a\u6587\u7684\u540e\u7eed\u90e8\u5206<\/a>\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u8bc6\u522b\u80a1\u7968\u6570\u636e\u4e2d\u7684\u5f02\u5e38\u3002<\/p>\n<p><strong>\u5236\u9020\u4e1a<\/strong><\/p>\n<p>\u65f6\u95f4\u5e8f\u5217\u5f02\u5e38\u68c0\u6d4b\u7684\u53e6\u4e00\u4e2a\u7528\u4f8b\u662f\u76d1\u6d4b\u751f\u4ea7\u7ebf\u4e2d\u7684\u7f3a\u9677\u3002 \u673a\u5668\u901a\u5e38\u53d7\u5230\u76d1\u63a7\uff0c\u63d0\u4f9b\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002 \u5c06\u6f5c\u5728\u6545\u969c\u544a\u77e5\u7ba1\u7406\u5c42\u81f3\u5173\u91cd\u8981\uff0c\u800c\u5f02\u5e38\u68c0\u6d4b\u53d1\u6325\u7740\u5173\u952e\u4f5c\u7528\u3002<\/p>\n<p><strong>\u533b\u5b66\u548c\u533b\u7597<\/strong><\/p>\n<p>\u5728\u533b\u5b66\u548c\u533b\u7597\u9886\u57df\uff0c\u4eba\u4f53\u751f\u547d\u4f53\u5f81\u53d7\u5230\u76d1\u6d4b\uff0c\u5f02\u5e38\u4f1a\u88ab\u68c0\u51fa\u3002 \u8fd9\u5728\u533b\u5b66\u7814\u7a76\u4e2d\u5df2\u7ecf\u76f8\u5f53\u91cd\u8981\uff0c\u4f46\u5bf9\u8bca\u65ad\u6765\u8bf4\u5219\u662f\u5fc5\u4e0d\u53ef\u5c11\u3002 \u5982\u679c\u533b\u9662\u4e2d\u7684\u60a3\u8005\u751f\u547d\u4f53\u5f81\u51fa\u73b0\u5f02\u5e38\u4f46\u6ca1\u6709\u5f97\u5230\u53ca\u65f6\u6cbb\u7597\uff0c\u540e\u679c\u53ef\u80fd\u662f\u81f4\u547d\u7684\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u5e94\u8be5\u4f7f\u7528\u7279\u6b8a\u65b9\u6cd5\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u5f02\u5e38\u68c0\u6d4b\uff1f<\/h2>\n<p>\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u7279\u6b8a\u4e4b\u5904\u5728\u4e8e\uff0c\u5b83\u6709\u65f6\u4e0d\u80fd\u50cf\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\u90a3\u6837\u5904\u7406\u3002 \u4f8b\u5982\uff0c\u5f53\u6211\u4eec\u5c06\u8bad\u7ec3\u6d4b\u8bd5\u5206\u5272\u5e94\u7528\u4e8e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u65f6\uff0c\u6570\u636e\u7684\u987a\u5e8f\u76f8\u5173\u6027\u8d28\u610f\u5473\u7740\u6211\u4eec\u65e0\u6cd5\u5bf9\u5176\u8fdb\u884c\u91cd\u6392\u3002 \u5c06\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5e94\u7528\u4e8e\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u65f6\u4e5f\u662f\u8fd9\u6837\u3002 \u901a\u5e38\u4f7f\u7528\u5faa\u73af\u795e\u7ecf\u7f51\u7edc (RNN) \u8003\u8651\u987a\u5e8f\u5173\u7cfb\uff0c\u5c06\u8bad\u7ec3\u6570\u636e\u4f5c\u4e3a\u65f6\u95f4\u7a97\u53e3\u8f93\u5165\uff0c\u4fdd\u7559\u5176\u4e2d\u4e8b\u4ef6\u7684\u987a\u5e8f\u3002<\/p>\n<p>\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u7279\u6b8a\u6027\u8fd8\u5728\u4e8e\uff0c\u5b83\u901a\u5e38\u5177\u6709\u6211\u4eec\u65e0\u6cd5\u5ffd\u89c6\u7684\u5b63\u8282\u6027\u548c\u8d8b\u52bf\u3002 \u5e38\u89c1\u7684\u5b63\u8282\u6027\u53ef\u4ee5\u8868\u73b0\u4e3a 24 \u5c0f\u65f6\u5468\u671f\u30017 \u5929\u5468\u671f\u6216 12 \u4e2a\u6708\u5468\u671f\u7b49\u3002 \u53ea\u6709\u8003\u8651\u5230\u5b63\u8282\u6027\u548c\u8d8b\u52bf\u4e4b\u540e\u624d\u80fd\u786e\u5b9a\u5f02\u5e38\uff0c<a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/#stl-beehive\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/#stl-beehive\">\u5982\u4ee5\u4e0b\u793a\u4f8b\u6240\u793a<\/a>\u3002\u00a0<\/p>\n<h2 class=\"wp-block-heading\">\u7528\u4e8e\u65f6\u95f4\u5e8f\u5217\u5f02\u5e38\u68c0\u6d4b\u7684\u65b9\u6cd5<\/h2>\n<p>\u7531\u4e8e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u7279\u6b8a\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u7279\u6b8a\u65b9\u6cd5\u68c0\u6d4b\u5176\u4e2d\u7684\u5f02\u5e38\u3002 \u6839\u636e\u6570\u636e\u7c7b\u578b\uff0c\u6211\u4eec\u5728\u4e0a\u4e00\u7bc7<a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-machine-learning\/\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-machine-learning\/\">\u5173\u4e8e\u5f02\u5e38\u68c0\u6d4b\u7684\u535a\u6587<\/a>\u4e2d\u63d0\u5230\u7684\u4e00\u4e9b\u65b9\u6cd5\u548c\u7b97\u6cd5\u4e5f\u53ef\u7528\u4e8e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002 \u4e0d\u8fc7\uff0c\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5f02\u5e38\u68c0\u6d4b\u7684\u7a33\u5065\u6027\u53ef\u80fd\u4e0d\u5982\u4e13\u4e3a\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u8bbe\u8ba1\u7684\u65b9\u6cd5\u3002 \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u7ed3\u5408\u91c7\u7528\u591a\u79cd\u68c0\u6d4b\u65b9\u6cd5\u91cd\u65b0\u786e\u8ba4\u68c0\u6d4b\u7ed3\u679c\uff0c\u907f\u514d\u8bef\u62a5\u6216\u6f0f\u62a5\u3002<\/p>\n<h3 class=\"wp-block-heading\">STL \u5206\u89e3<\/h3>\n<p>\u5904\u7406\u5177\u6709\u5b63\u8282\u6027\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u6700\u6d41\u884c\u65b9\u5f0f\u4e4b\u4e00\u662f STL \u5206\u89e3 \u2013 \u4f7f\u7528 LOESS\uff08\u5c40\u90e8\u4f30\u8ba1\u6563\u70b9\u56fe\u5e73\u6ed1\uff09\u8fdb\u884c\u5b63\u8282\u6027\u8d8b\u52bf\u5206\u89e3\u3002 \u8fd9\u79cd\u65b9\u6cd5\u4f7f\u7528\u5b63\u8282\u6027\u4f30\u8ba1\uff08\u63d0\u4f9b\u6216\u4f7f\u7528\u7b97\u6cd5\u786e\u5b9a\u65f6\u6bb5\uff09\u3001\u8d8b\u52bf\uff08\u4f30\u8ba1\uff09\u548c\u6b8b\u5dee\uff08\u6570\u636e\u4e2d\u7684\u566a\u58f0\uff09\u5206\u89e3\u65f6\u95f4\u5e8f\u5217\u3002 \u63d0\u4f9b <a href=\"https:\/\/www.statsmodels.org\/stable\/examples\/notebooks\/generated\/stl_decomposition.html\" target=\"_blank\" rel=\"noopener\">STL \u5206\u89e3\u5de5\u5177<\/a>\u7684 <a href=\"https:\/\/www.jetbrains.com.cn\/help\/pycharm\/python.html\" target=\"_blank\" rel=\"noopener\">Python<\/a> \u5e93\u662f <a href=\"https:\/\/www.statsmodels.org\/stable\/index.html\" target=\"_blank\" rel=\"noopener\">statsmodels<\/a> \u5e93\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539263\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-70.png\" alt=\"STL \u5206\u89e3\" width=\"1600\" height=\"900\" \/><\/figure>\n<p>\u5f53\u6b8b\u5dee\u8d85\u8fc7\u67d0\u4e2a\u9608\u503c\u65f6\uff0c\u5c31\u4f1a\u68c0\u6d4b\u5230\u5f02\u5e38\u3002\u00a0<\/p>\n<h3 id=\"stl-beehive\" class=\"wp-block-heading\">\u5728\u8702\u5de2\u6570\u636e\u4e0a\u4f7f\u7528 STL \u5206\u89e3<\/h3>\n<p>\u5728\u4e4b\u524d\u7684<a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-machine-learning\/\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-machine-learning\/\">\u535a\u6587<\/a>\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <a href=\"https:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.svm.OneClassSVM.html\" target=\"_blank\" rel=\"noopener\">OneClassSVM<\/a> \u548c <a href=\"https:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.ensemble.IsolationForest.html\" target=\"_blank\" rel=\"noopener\">IsolationForest<\/a> \u65b9\u6cd5\u63a2\u7a76\u4e86\u8702\u5de2\u4e2d\u7684\u5f02\u5e38\u68c0\u6d4b\u3002\u00a0<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528 statsmodels \u5e93\u63d0\u4f9b\u7684 <code>STL<\/code> \u7c7b\u5c06<a href=\"https:\/\/www.kaggle.com\/datasets\/vivovinco\/beehives\" target=\"_blank\" rel=\"noopener\">\u8702\u5de2\u6570\u636e<\/a>\u4f5c\u4e3a\u65f6\u95f4\u5e8f\u5217\u8fdb\u884c\u5206\u6790\u3002 \u9996\u5148\uff0c\u4f7f\u7528\u6b64\u6587\u4ef6\u8bbe\u7f6e\u73af\u5883\uff1a<a href=\"https:\/\/github.com\/Cheukting\/anomaly-detection\/blob\/main\/requirements.txt\" target=\"_blank\" rel=\"noopener\">requirements.txt<\/a>\u3002\u00a0<\/p>\n<h4 class=\"wp-block-heading\"><strong>1. \u5b89\u88c5\u5e93<\/strong><\/h4>\n<p>\u7531\u4e8e\u6211\u4eec\u53ea\u4f7f\u7528 Scikit-learn \u63d0\u4f9b\u7684\u6a21\u578b\uff0c\u6211\u4eec\u9700\u8981\u4ece PyPI \u5b89\u88c5 statsmodels\u3002 \u5728 <a href=\"https:\/\/www.jetbrains.com.cn\/pycharm\/data-science\/\" target=\"_blank\" rel=\"noreferrer noopener\">PyCharm<\/a> \u4e2d\u8fd9\u5f88\u5bb9\u6613\u3002<\/p>\n<div class=\"buttons\">\n<div class=\"buttons__row\"><a class=\"btn\" href=\"https:\/\/www.jetbrains.com.cn\/pycharm\/data-science\/\" target=\"\" rel=\"noopener\">\u514d\u8d39\u5f00\u59cb\u4f7f\u7528 PyCharm Pro<\/a><\/div>\n<\/div>\n<p>\u8f6c\u5230 <em>Python <\/em><a href=\"https:\/\/www.jetbrains.com.cn\/help\/pycharm\/installing-uninstalling-and-upgrading-packages.html\" target=\"_blank\" rel=\"noopener\"><em>Package<\/em><\/a>\uff08Python \u8f6f\u4ef6\u5305\uff09\u7a97\u53e3\uff08\u9009\u62e9 IDE \u5de6\u4fa7\u5e95\u90e8\u7684\u56fe\u6807\uff09\uff0c\u5728\u641c\u7d22\u6846\u4e2d\u8f93\u5165 statsmodels\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539351\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-76.png\" alt=\"PyCharm \u4e2d\u7684 Statsmodels\" width=\"1600\" height=\"630\" \/><\/figure>\n<p>\u60a8\u53ef\u4ee5\u5728\u53f3\u4fa7\u770b\u5230\u8f6f\u4ef6\u5305\u7684\u6240\u6709\u4fe1\u606f\u3002 \u8981\u5b89\u88c5\uff0c\u53ea\u9700\u70b9\u51fb <em>Install package<\/em>\uff08\u5b89\u88c5\u8f6f\u4ef6\u5305\uff09\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>2. \u521b\u5efa Jupyter Notebook<\/strong><\/h4>\n<p>\u4e3a\u4e86\u8fdb\u4e00\u6b65\u7814\u7a76\u6570\u636e\u96c6\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a <a href=\"https:\/\/www.jetbrains.com.cn\/help\/pycharm\/jupyter-notebook-support.html\" target=\"_blank\" rel=\"noopener\">Jupyter Notebook<\/a>\uff0c\u5229\u7528 PyCharm \u7684 Jupyter Notebook \u73af\u5883\u63d0\u4f9b\u7684\u5de5\u5177\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539362\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-77.png\" alt=\"\u5728 PyCharm \u4e2d\u521b\u5efa Jupyter Notebook\" width=\"1098\" height=\"410\" \/><\/figure>\n<p>\u6211\u4eec\u5c06\u5bfc\u5165 <a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2024\/10\/data-exploration-with-pandas\/\">pandas<\/a> \u5e76\u52a0\u8f7d <code>.csv<\/code> \u6587\u4ef6\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd\n\ndf = pd.read_csv('..\/data\/Hive17.csv', sep=\";\")\ndf = df.dropna()\ndf<\/pre>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539310\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-73.png\" alt=\"\u5728 PyCharm \u4e2d\u5bfc\u5165 pandas\" width=\"1600\" height=\"930\" \/><\/figure>\n<h4 class=\"wp-block-heading\"><strong>3. \u4ee5\u56fe\u5f62\u5f62\u5f0f\u68c0\u67e5\u6570\u636e<\/strong><\/h4>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u80fd\u591f\u4ee5\u56fe\u5f62\u5f62\u5f0f\u68c0\u67e5\u6570\u636e\u3002 \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u60f3\u67e5\u770b\u8702\u5de2 17 \u7684\u6e29\u5ea6\u5728\u4e00\u6bb5\u65f6\u95f4\u5185\u7684\u53d8\u5316\u3002 \u5728 DataFrame \u68c0\u67e5\u5668\u4e2d\u70b9\u51fb <em>Chart view<\/em>\uff08\u56fe\u8868\u89c6\u56fe\uff09\uff0c\u7136\u540e\u5728\u5e8f\u5217\u8bbe\u7f6e\u4e2d\u9009\u62e9 <em>T17<\/em> \u4f5c\u4e3a y \u8f74\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539299\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-2.gif\" alt=\"\u5728 PyCharm \u4e2d\u4ee5\u56fe\u5f62\u5f62\u5f0f\u68c0\u67e5\u6570\u636e\" width=\"720\" height=\"290\" \/><\/figure>\n<p>\u4f7f\u7528\u65f6\u95f4\u5e8f\u5217\u8868\u793a\u65f6\uff0c\u6e29\u5ea6\u6709\u5f88\u591a\u8d77\u4f0f\u3002 \u8fd9\u8868\u660e\u884c\u4e3a\u5177\u6709\u5468\u671f\u6027\uff0c\u5f88\u53ef\u80fd\u662f\u7531\u4e8e\u663c\u591c\u5faa\u73af\uff0c\u56e0\u6b64\u53ef\u4ee5\u5b89\u5168\u5047\u8bbe\u6e29\u5ea6\u6709\u4e00\u4e2a 24 \u5c0f\u65f6\u7684\u5468\u671f\u3002\u00a0<\/p>\n<p>\u5176\u6b21\uff0c\u6e29\u5ea6\u968f\u65f6\u95f4\u63a8\u79fb\u5448\u4e0b\u964d\u8d8b\u52bf\u3002 \u5982\u679c\u60a8\u68c0\u67e5 <em>DateTime<\/em> \u5217\uff0c\u53ef\u4ee5\u770b\u5230\u4ece 8 \u6708\u5230 11 \u6708\u7684\u65e5\u671f\u8303\u56f4\u3002 \u7531\u4e8e<a href=\"https:\/\/www.kaggle.com\/datasets\/vivovinco\/beehives\/data\" target=\"_blank\" rel=\"noopener\">\u6570\u636e\u96c6\u7684 Kaggle \u9875\u9762<\/a>\u8868\u660e\u6570\u636e\u662f\u5728\u571f\u8033\u5176\u6536\u96c6\uff0c\u4ece\u590f\u5b63\u5230\u79cb\u5b63\u7684\u8fc7\u6e21\u53ef\u4ee5\u89e3\u91ca\u6211\u4eec\u89c2\u5bdf\u5230\u7684\u6e29\u5ea6\u968f\u65f6\u95f4\u4e0b\u964d\u7684\u73b0\u8c61\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>4. \u65f6\u95f4\u5e8f\u5217\u5206\u89e3<\/strong><\/h4>\n<p>\u4e3a\u4e86\u7406\u89e3\u65f6\u95f4\u5e8f\u5217\u548c\u68c0\u6d4b\u5f02\u5e38\uff0c\u6211\u4eec\u5c06\u6267\u884c STL \u5206\u89e3\uff0c\u4ece statsmodels \u5bfc\u5165 <code>STL<\/code> \u7c7b\u5e76\u4f7f\u7528\u6211\u4eec\u7684\u6e29\u5ea6\u6570\u636e\u8fdb\u884c\u62df\u5408\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from statsmodels.tsa.seasonal import STL\n\nstl = STL(df[\"T17\"], period=24, robust=True) \nresult = stl.fit()<\/pre>\n<p>\u6211\u4eec\u5fc5\u987b\u63d0\u4f9b\u4e00\u4e2a\u65f6\u6bb5\u624d\u80fd\u4f7f\u5206\u89e3\u53d1\u6325\u4f5c\u7528\u3002 \u5982\u524d\u6240\u8ff0\uff0c\u53ef\u4ee5\u5b89\u5168\u5047\u8bbe\u4e00\u4e2a 24 \u5c0f\u65f6\u7684\u5468\u671f\u3002<\/p>\n<p>\u6839\u636e\u6587\u6863\uff0c<code>STL<\/code> \u5c06\u65f6\u95f4\u5e8f\u5217\u5206\u89e3\u4e3a\u4e09\u4e2a\u90e8\u5206\uff1a\u8d8b\u52bf\u3001\u5b63\u8282\u548c\u6b8b\u5dee\u3002 \u4e3a\u4e86\u66f4\u6e05\u695a\u5730\u67e5\u770b\u5206\u89e3\u7ed3\u679c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684 <code>plot<\/code> \u65b9\u6cd5\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">result.plot()<\/pre>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539541\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/Time-series-decomposition.png\" alt=\"\u65f6\u95f4\u5e8f\u5217\u5206\u89e3\" width=\"1600\" height=\"1100\" \/><\/figure>\n<p>\u60a8\u53ef\u4ee5\u770b\u5230 <em>Trend<\/em>\uff08\u8d8b\u52bf\uff09\u548c <em>Season<\/em>\uff08\u5b63\u8282\uff09\u56fe\u4f3c\u4e4e\u4e0e\u4e0a\u9762\u7684\u5047\u8bbe\u4e00\u81f4\u3002 \u4e0d\u8fc7\uff0c\u6211\u4eec\u611f\u5174\u8da3\u7684\u662f\u5e95\u90e8\u7684\u6b8b\u5dee\u56fe\uff0c\u5373\u6ca1\u6709\u8d8b\u52bf\u548c\u5b63\u8282\u53d8\u5316\u7684\u539f\u59cb\u5e8f\u5217\u3002 \u6b8b\u5dee\u4e2d\u4efb\u4f55\u6781\u9ad8\u6216\u6781\u4f4e\u7684\u503c\u90fd\u8868\u793a\u5f02\u5e38\u3002<\/p>\n<h4 id=\"anomaly-threshold\" class=\"wp-block-heading\"><strong>5. \u5f02\u5e38\u9608\u503c<\/strong><\/h4>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u8981\u786e\u5b9a\u6b8b\u5dee\u7684\u54ea\u4e9b\u503c\u662f\u5f02\u5e38\u3002 \u4e3a\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u6b8b\u5dee\u76f4\u65b9\u56fe\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">result.resid.plot.hist()<\/pre>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539375\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-78.png\" alt=\"PyCharm \u4e2d\u7684\u5f02\u5e38\u9608\u503c\" width=\"1328\" height=\"1048\" \/><\/figure>\n<p>\u8fd9\u53ef\u4ee5\u88ab\u89c6\u4e3a\u56f4\u7ed5 0 \u7684\u6b63\u6001\u5206\u5e03\uff0c\u5728 5 \u4ee5\u4e0a\u548c -5 \u4ee5\u4e0b\u6709\u957f\u5c3e\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u9608\u503c\u8bbe\u4e3a 5\u3002<\/p>\n<p>\u4e3a\u4e86\u663e\u793a\u539f\u59cb\u65f6\u95f4\u5e8f\u5217\u4e0a\u7684\u5f02\u5e38\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u56fe\u5f62\u4e2d\u5c06\u5b83\u4eec\u5168\u90e8\u6807\u6210\u7ea2\u8272\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import matplotlib.pyplot as plt\n\nthreshold = 5\nanomalies_filter = result.resid.apply(lambda x: True if abs(x) &gt; threshold else False)\nanomalies = df[\"T17\"][anomalies_filter]\n\nplt.figure(figsize=(14, 8))\nplt.scatter(x=anomalies.index, y=anomalies, color=\"red\", label=\"anomalies\")\nplt.plot(df.index, df['T17'], color='blue')\nplt.title('Temperatures in Hive 17')\nplt.xlabel('Hours')\nplt.ylabel('Temperature')\nplt.legend()\nplt.show()<\/pre>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539386\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-79.png\" alt=\"PyCharm \u4e2d\u539f\u59cb\u65f6\u95f4\u5e8f\u5217\u7684\u5f02\u5e38\" width=\"1600\" height=\"976\" \/><\/figure>\n<p>\u5982\u679c\u6ca1\u6709 STL \u5206\u89e3\uff0c\u5c31\u5f88\u96be\u5728\u7531\u65f6\u6bb5\u548c\u8d8b\u52bf\u7ec4\u6210\u7684\u65f6\u95f4\u5e8f\u5217\u4e2d\u8bc6\u522b\u8fd9\u4e9b\u5f02\u5e38\u3002<\/p>\n<h3 class=\"wp-block-heading\">LSTM \u9884\u6d4b<\/h3>\n<p>\u68c0\u6d4b\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5f02\u5e38\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f\u662f\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u65b9\u6cd5\u5bf9\u5e8f\u5217\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\uff0c\u4f30\u8ba1\u6570\u636e\u70b9\u7684\u7ed3\u679c\u3002 \u5982\u679c\u4f30\u8ba1\u503c\u4e0e\u5b9e\u9645\u6570\u636e\u70b9\u76f8\u5dee\u5f88\u5927\uff0c\u90a3\u4e48\u8fd9\u53ef\u80fd\u5c31\u662f\u5f02\u5e38\u6570\u636e\u7684\u8ff9\u8c61\u3002<\/p>\n<p>\u6267\u884c\u5e8f\u5217\u6570\u636e\u9884\u6d4b\u7684\u6d41\u884c\u6df1\u5ea6\u5b66\u4e60\u7b97\u6cd5\u4e4b\u4e00\u662f\u957f\u77ed\u671f\u8bb0\u5fc6 (LSTM) \u6a21\u578b\uff0c\u5b83\u662f\u4e00\u79cd\u5faa\u73af\u795e\u7ecf\u7f51\u7edc (RNN)\u3002 LSTM \u6a21\u578b\u5177\u6709\u8f93\u5165\u95e8\u3001\u9057\u5fd8\u95e8\u548c\u8f93\u51fa\u95e8\uff0c\u5b83\u4eec\u662f\u6570\u5b57\u77e9\u9635\u3002 \u8fd9\u5c06\u786e\u4fdd\u91cd\u8981\u4fe1\u606f\u5728\u6570\u636e\u7684\u4e0b\u4e00\u6b21\u8fed\u4ee3\u4e2d\u5f97\u5230\u4f20\u9012\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539580\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/LSTM-memory-cell.png\" alt=\"LSTM \u8bb0\u5fc6\u5355\u5143\" width=\"1600\" height=\"900\" \/><\/figure>\n<p>\u7531\u4e8e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u662f\u987a\u5e8f\u6570\u636e\uff0c\u5373\u6570\u636e\u70b9\u7684\u987a\u5e8f\u662f\u8fde\u7eed\u7684\u4e14\u4e0d\u5e94\u8be5\u88ab\u91cd\u6392\uff0cLSTM \u6a21\u578b\u662f\u9884\u6d4b\u7279\u5b9a\u65f6\u95f4\u7684\u7ed3\u679c\u7684\u6709\u6548\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u3002 \u8fd9\u4e00\u9884\u6d4b\u53ef\u4ee5\u4e0e\u5b9e\u9645\u6570\u636e\u8fdb\u884c\u6bd4\u8f83\uff0c\u7531\u9608\u503c\u786e\u5b9a\u5b9e\u9645\u6570\u636e\u662f\u5426\u5f02\u5e38\u3002<\/p>\n<h3 id=\"lstm-stock\" class=\"wp-block-heading\">\u5bf9\u80a1\u7968\u4ef7\u683c\u4f7f\u7528 LSTM \u9884\u6d4b<\/h3>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u5f00\u59cb\u4e00\u4e2a\u65b0\u7684 Jupyter \u9879\u76ee\uff0c\u68c0\u6d4b\u8fc7\u53bb 5 \u5e74 Apple \u80a1\u4ef7\u7684\u5f02\u5e38\u3002 <a href=\"https:\/\/www.nasdaq.com\/market-activity\/stocks\/aapl\/historical?page=1&amp;rows_per_page=25&amp;timeline=y5\" target=\"_blank\" rel=\"noopener\">\u80a1\u7968\u4ef7\u683c\u6570\u636e\u96c6<\/a>\u663e\u793a\u7684\u662f\u6700\u65b0\u6570\u636e\u3002 \u5982\u679c\u60a8\u60f3\u8ddf\u968f\u535a\u6587\u64cd\u4f5c\uff0c\u53ef\u4ee5<a href=\"https:\/\/github.com\/Cheukting\/lstm_anomaly_detection\/tree\/main\/data\" target=\"_blank\" rel=\"noopener\">\u4e0b\u8f7d\u6211\u4eec\u4f7f\u7528\u7684\u6570\u636e\u96c6<\/a>\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>1. \u5f00\u59cb\u4e00\u4e2a Jupyter \u9879\u76ee<\/strong><\/h4>\n<p>\u5f00\u59cb\u65b0\u9879\u76ee\u65f6\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u521b\u5efa\u4e00\u4e2a\u9488\u5bf9\u6570\u636e\u79d1\u5b66\u4f18\u5316\u7684 Jupyter \u9879\u76ee\u3002 \u5728 <em>New Project<\/em>\uff08\u65b0\u5efa\u9879\u76ee\uff09\u7a97\u53e3\u4e2d\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a Git \u4ed3\u5e93\u5e76\u786e\u5b9a\u4f7f\u7528\u54ea\u4e2a conda \u5b89\u88c5\u6765\u7ba1\u7406\u73af\u5883\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539627\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/Jupyter-project-in-PyCharm.png\" alt=\"\u5728 PyCharm \u4e2d\u5f00\u59cb Jupyter \u9879\u76ee\" width=\"1592\" height=\"1282\" \/><\/figure>\n<p>\u5f00\u59cb\u9879\u76ee\u540e\uff0c\u60a8\u5c06\u770b\u5230\u4e00\u4e2a\u793a\u4f8b Notebook\u3002 \u4e3a\u672c\u7ec3\u4e60\u65b0\u5efa\u4e00\u4e2a Jupyter Notebook\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539604\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-4.gif\" alt=\"PyCharm \u4e2d\u7684\u793a\u4f8b Notebook\" width=\"716\" height=\"382\" \/><\/figure>\n<p>\u7136\u540e\uff0c\u8bbe\u7f6e <code>requirements.txt<\/code>\u3002 \u6211\u4eec\u9700\u8981 pandas\u3001matplotlib \u548c PyTorch\uff08\u5728 PyPI \u4e0a\u540d\u4e3a torch\uff09\u3002 \u7531\u4e8e conda \u73af\u5883\u4e2d\u4e0d\u5305\u542b PyTorch\uff0cPyCharm \u4f1a\u544a\u8bc9\u6211\u4eec\u7f3a\u5c11\u8f6f\u4ef6\u5305\u3002 \u8981\u5b89\u88c5\u8f6f\u4ef6\u5305\uff0c\u70b9\u51fb\u706f\u6ce1\u5e76\u9009\u62e9 <em>Install all missing packages<\/em>\uff08\u5b89\u88c5\u6240\u6709\u7f3a\u5931\u7684\u8f6f\u4ef6\u5305\uff09\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539615\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-5.gif\" alt=\"\u5728 PyCharm \u4e2d\u5b89\u88c5\u6240\u6709\u7f3a\u5931\u7684\u8f6f\u4ef6\u5305\" width=\"1358\" height=\"762\" \/><\/figure>\n<h4 class=\"wp-block-heading\"><strong>2. \u52a0\u8f7d\u548c\u68c0\u67e5\u6570\u636e<\/strong><\/h4>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u6570\u636e\u96c6 <a href=\"https:\/\/github.com\/Cheukting\/lstm_anomaly_detection\/tree\/main\/data\" target=\"_blank\" rel=\"noopener\">apple_stock_5y.csv<\/a> \u653e\u5165 data \u6587\u4ef6\u5939\uff0c\u5e76\u5c06\u5176\u52a0\u8f7d\u4e3a pandas DataFrame \u8fdb\u884c\u68c0\u67e5\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd\n \ndf = pd.read_csv('data\/apple_stock_5y.csv')\ndf<\/pre>\n<p>\u901a\u8fc7\u4ea4\u4e92\u5f0f\u8868\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u662f\u5426\u6709\u6570\u636e\u7f3a\u5931\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539640\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-6.gif\" alt=\"\" width=\"824\" height=\"442\" \/><\/figure>\n<p>\u6ca1\u6709\u7f3a\u5931\u6570\u636e\uff0c\u4f46\u6709\u4e00\u4e2a\u95ee\u9898 \u2013 \u6211\u4eec\u60f3\u4f7f\u7528 <em>Close\/Last<\/em> \u4ef7\u683c\uff0c\u4f46\u5b83\u4e0d\u662f\u6570\u5b57\u6570\u636e\u7c7b\u578b\u3002 \u6211\u4eec\u8fdb\u884c\u8f6c\u6362\u5e76\u518d\u6b21\u68c0\u67e5\u6570\u636e\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">df[\"Close\/Last\"] = df[\"Close\/Last\"].apply(lambda x: float(x[1:]))\ndf<\/pre>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ea4\u4e92\u5f0f\u8868\u68c0\u67e5\u4ef7\u683c\u3002 \u70b9\u51fb\u5de6\u4fa7\u7684\u7ed8\u56fe\u56fe\u6807\uff0c\u5c06\u521b\u5efa\u4e00\u4e2a\u7ed8\u56fe\u3002 \u5b83\u9ed8\u8ba4\u4f7f\u7528 <em>Date<\/em> \u4f5c\u4e3a x \u8f74\uff0c\u4f7f\u7528 <em>Volume<\/em> \u4f5c\u4e3a y \u8f74\u3002 \u7531\u4e8e\u6211\u4eec\u60f3\u67e5\u770b <em>Close\/Last<\/em> \u4ef7\u683c\uff0c\u70b9\u51fb\u53f3\u4fa7\u7684\u9f7f\u8f6e\u56fe\u6807\u8fdb\u5165\u8bbe\u7f6e\uff0c\u7136\u540e\u9009\u62e9 <em>Close\/Last<\/em> \u4f5c\u4e3a y \u8f74\u3002<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539652\" style=\"aspect-ratio: 1.8662790697674418; width: 642px; height: auto;\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-7.gif\" alt=\"\" width=\"642\" height=\"344\" \/><\/figure>\n<h4 class=\"wp-block-heading\"><strong>3. \u4e3a LSTM \u51c6\u5907\u8bad\u7ec3\u6570\u636e<\/strong><\/h4>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u51c6\u5907\u5728 LSTM \u6a21\u578b\u4e2d\u4f7f\u7528\u7684\u8bad\u7ec3\u6570\u636e\u3002 \u6211\u4eec\u9700\u8981\u51c6\u5907\u4e00\u4e2a\u5411\u91cf\uff08\u7279\u5f81 X\uff09\u5e8f\u5217\uff08\u6bcf\u4e2a\u5411\u91cf\u4ee3\u8868\u4e00\u4e2a\u65f6\u95f4\u7a97\u53e3\uff09\u6765\u9884\u6d4b\u4e0b\u4e00\u4e2a\u4ef7\u683c\u3002 \u4e0b\u4e00\u4e2a\u4ef7\u683c\u5c06\u5f62\u6210\u53e6\u4e00\u4e2a\u5e8f\u5217\uff08\u76ee\u6807 y\uff09\u3002 \u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>lookback<\/code> \u53d8\u91cf\u9009\u62e9\u6b64\u65f6\u95f4\u7a97\u53e3\u7684\u5927\u5c0f\u3002 \u4ee5\u4e0b\u4ee3\u7801\u5c06\u521b\u5efa\u5e8f\u5217 X \u548c y\uff0c\u968f\u540e\u5b83\u4eec\u5c06\u88ab\u8f6c\u6362\u4e3a PyTorch \u5f20\u91cf\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import torch\n\nlookback = 5\ntimeseries = df[[\"Close\/Last\"]].values.astype('float32')\n\nX, y = [], []\nfor i in range(len(timeseries)-lookback):\n    feature = timeseries[i:i+lookback]\n    target = timeseries[i+1:i+lookback+1]\n    X.append(feature)\n    y.append(target)\n    \nX = torch.tensor(X)\ny = torch.tensor(y)\n\nprint(X.shape, y.shape)<\/pre>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u7a97\u53e3\u8d8a\u5927\uff0c\u6211\u4eec\u7684\u6a21\u578b\u5c31\u8d8a\u5927\uff0c\u56e0\u4e3a\u8f93\u5165\u5411\u91cf\u66f4\u5927\u3002 \u4e0d\u8fc7\uff0c\u7a97\u53e3\u8d8a\u5927\uff0c\u8f93\u5165\u5e8f\u5217\u5c31\u8d8a\u77ed\uff0c\u56e0\u6b64\u786e\u5b9a\u56de\u987e\u7a97\u53e3\u662f\u4e00\u4e2a\u5e73\u8861\u7684\u64cd\u4f5c\u3002 \u6211\u4eec\u5c06\u4ece 5 \u5f00\u59cb\uff0c\u4f46\u4e5f\u53ef\u4ee5\u5c1d\u8bd5\u4e0d\u540c\u7684\u6570\u503c\uff0c\u770b\u770b\u6709\u4ec0\u4e48\u4e0d\u540c\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>4. \u6784\u5efa\u548c\u8bad\u7ec3\u6a21\u578b<\/strong><\/h4>\n<p>\u5728\u8bad\u7ec3\u4e4b\u524d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 PyTorch \u4e2d\u7684 <a href=\"https:\/\/pytorch.org\/docs\/stable\/nn.html\" target=\"_blank\" rel=\"noopener\">nn \u6a21\u5757<\/a>\u521b\u5efa\u4e00\u4e2a\u7c7b\u6765\u6784\u5efa\u6a21\u578b\u3002 nn \u6a21\u5757\u63d0\u7ec4\u6210\u8981\u7d20\uff0c\u4f8b\u5982\u4e0d\u540c\u7684\u795e\u7ecf\u7f51\u7edc\u5c42\u3002 \u5728\u672c\u7ec3\u4e60\u4e2d\uff0c\u6211\u4eec\u5c06\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 <a href=\"https:\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.LSTM.html\" target=\"_blank\" rel=\"noopener\">LSTM \u5c42<\/a>\uff0c\u7136\u540e\u6784\u5efa\u4e00\u4e2a<a href=\"https:\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.Linear.html\" target=\"_blank\" rel=\"noopener\">\u7ebf\u6027\u5c42<\/a>\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import torch.nn as nn\n\nclass StockModel(nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.lstm = nn.LSTM(input_size=1, hidden_size=50, num_layers=1, batch_first=True)\n        self.linear = nn.Linear(50, 1)\n    def forward(self, x):\n        x, _ = self.lstm(x)\n        x = self.linear(x)\n        return x<\/pre>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8bad\u7ec3\u6a21\u578b\u3002 \u5728\u8bad\u7ec3\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u4f18\u5316\u5668\u3001\u4e00\u4e2a\u7528\u4e8e\u8ba1\u7b97\u9884\u6d4b\u503c\u548c\u5b9e\u9645 y \u503c\u4e4b\u95f4\u635f\u5931\u7684<a href=\"https:\/\/pytorch.org\/docs\/stable\/nn.html#loss-functions\" target=\"_blank\" rel=\"noopener\">\u635f\u5931\u51fd\u6570<\/a>\uff0c\u4ee5\u53ca\u4e00\u4e2a\u7528\u4e8e\u9988\u5165\u8bad\u7ec3\u6570\u636e\u7684<a href=\"https:\/\/pytorch.org\/docs\/stable\/data.html#data-loading-order-and-sampler\" target=\"_blank\" rel=\"noopener\">\u6570\u636e\u52a0\u8f7d\u5668<\/a>\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import numpy as np\nimport torch.optim as optim\nimport torch.utils.data as data\n\nmodel = StockModel()\noptimizer = optim.Adam(model.parameters())\nloss_fn = nn.MSELoss()\nloader = data.DataLoader(data.TensorDataset(X, y), shuffle=True, batch_size=8)<\/pre>\n<p>\u6211\u4eec\u5df2\u7ecf\u521b\u5efa\u4e86\u65f6\u95f4\u7a97\u53e3\uff0c\u6570\u636e\u52a0\u8f7d\u5668\u53ef\u4ee5\u5c06\u8f93\u5165\u91cd\u6392\u3002 \u8fd9\u4fdd\u7559\u4e86\u6bcf\u4e2a\u7a97\u53e3\u4e2d\u7684\u987a\u5e8f\u5173\u7cfb\u3002<\/p>\n<p>\u8bad\u7ec3\u4f7f\u7528\u5728\u6bcf\u4e2a\u5468\u671f\u5faa\u73af\u7684 <code>for<\/code> \u5faa\u73af\u5b8c\u6210\u3002 \u6bcf 100 \u4e2a\u5468\u671f\uff0c\u6211\u4eec\u5c06\u6253\u5370\u51fa\u635f\u5931\u5e76\u89c2\u5bdf\u6a21\u578b\u6536\u655b\u60c5\u51b5\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">n_epochs = 1000\nfor epoch in range(n_epochs):\n    model.train()\n    for X_batch, y_batch in loader:\n        y_pred = model(X_batch)\n        loss = loss_fn(y_pred, y_batch)\n        optimizer.zero_grad()\n        loss.backward()\n        optimizer.step()\n    if epoch % 100 != 0:\n        continue\n    model.eval()\n    with torch.no_grad():\n        y_pred = model(X)\n        rmse = np.sqrt(loss_fn(y_pred, y))\n    print(f\"Epoch {epoch}: RMSE {rmse:.4f}\")<\/pre>\n<p>\u6211\u4eec\u4ece 1000 \u4e2a\u5468\u671f\u5f00\u59cb\uff0c\u4f46\u6a21\u578b\u6536\u655b\u5f97\u76f8\u5f53\u5feb\u3002 \u4efb\u610f\u5c1d\u8bd5\u8bad\u7ec3\u5468\u671f\u6b21\u6570\uff0c\u83b7\u5f97\u6700\u4f73\u7ed3\u679c\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539664\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/Epochs-for-training.png\" alt=\"\u8bad\u7ec3\u5468\u671f\" width=\"1346\" height=\"1046\" \/><\/figure>\n<p>\u5728 PyCharm \u4e2d\uff0c\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\u624d\u80fd\u6267\u884c\u7684\u5355\u5143\u5c06\u63d0\u4f9b\u5269\u4f59\u65f6\u95f4\u7684\u901a\u77e5\u4ee5\u53ca\u5230\u8be5\u5355\u5143\u7684\u5feb\u6377\u65b9\u5f0f\u3002 \u5728 Jupyter Notebook \u4e2d\u8bad\u7ec3\u673a\u5668\u5b66\u4e60\u6a21\u578b\uff0c\u5c24\u5176\u662f\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u65f6\uff0c\u8fd9\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>5. \u7ed8\u5236\u9884\u6d4b\u5e76\u627e\u51fa\u8bef\u5dee<\/strong><\/h4>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u9884\u6d4b\u5e76\u5c06\u5176\u4e0e\u5b9e\u9645\u65f6\u95f4\u5e8f\u5217\u4e00\u8d77\u7ed8\u5236\u3002 \u6ce8\u610f\uff0c\u6211\u4eec\u5fc5\u987b\u521b\u5efa\u4e00\u4e2a 2D np \u5e8f\u5217\uff0c\u4ee5\u4fbf\u4e0e\u5b9e\u9645\u65f6\u95f4\u5e8f\u5217\u5339\u914d\u3002 \u5b9e\u9645\u65f6\u95f4\u5e8f\u5217\u5c06\u4e3a\u84dd\u8272\uff0c\u9884\u6d4b\u65f6\u95f4\u5e8f\u5217\u5c06\u4e3a\u7ea2\u8272\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import matplotlib.pyplot as plt\n\nwith torch.no_grad():\n    pred_series = np.ones_like(timeseries) * np.nan\n    pred_series[lookback:] = model(X)[:, -1, :]\n\nplt.plot(timeseries, c='b')\nplt.plot(pred_series, c='r')\nplt.show()<\/pre>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539687\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/Plot-the-prediction-and-find-the-errors.png\" alt=\"\u7ed8\u5236\u9884\u6d4b\u5e76\u627e\u51fa\u8bef\u5dee\" width=\"1180\" height=\"856\" \/><\/figure>\n<p>\u5982\u679c\u4ed4\u7ec6\u89c2\u5bdf\uff0c\u60a8\u4f1a\u53d1\u73b0\u9884\u6d4b\u503c\u548c\u5b9e\u9645\u503c\u5e76\u4e0d\u5b8c\u5168\u4e00\u81f4\u3002 \u4e0d\u8fc7\uff0c\u5927\u591a\u6570\u9884\u6d4b\u90fd\u5f88\u597d\u3002<\/p>\n<p>\u4e3a\u4e86\u4ed4\u7ec6\u68c0\u67e5\u8bef\u5dee\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u8bef\u5dee\u5e8f\u5217\u5e76\u4f7f\u7528\u4ea4\u4e92\u5f0f\u8868\u5bf9\u5176\u8fdb\u884c\u89c2\u5bdf\u3002 \u8fd9\u6b21\u6211\u4eec\u4f7f\u7528\u7edd\u5bf9\u8bef\u5dee\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">error = abs(timeseries-pred_series)\nerror<\/pre>\n<p>\u4f7f\u7528\u8bbe\u7f6e\u521b\u5efa\u76f4\u65b9\u56fe\uff0c\u4ee5\u7edd\u5bf9\u8bef\u5dee\u7684\u503c\u4f5c\u4e3a x \u8f74\uff0c\u4ee5\u503c\u7684\u8ba1\u6570\u4f5c\u4e3a y \u8f74\u3002<\/p>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539434\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/image-3.gif\" alt=\"\" width=\"452\" height=\"362\" \/><\/figure>\n<h4 class=\"wp-block-heading\"><strong>6. \u786e\u5b9a\u5f02\u5e38\u9608\u503c\u5e76\u76f4\u89c2\u5448\u73b0<\/strong><\/h4>\n<p>\u5927\u591a\u6570\u70b9\u7684\u7edd\u5bf9\u8bef\u5dee\u90fd\u4f1a\u5c0f\u4e8e 6\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u8bbe\u4e3a\u5f02\u5e38\u9608\u503c\u3002 \u4e0e<a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/#anomaly-threshold\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/#anomaly-threshold\">\u5904\u7406\u8702\u5de2\u5f02\u5e38\u7684\u505a\u6cd5<\/a>\u7c7b\u4f3c\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u56fe\u5f62\u4e2d\u7ed8\u5236\u5f02\u5e38\u6570\u636e\u70b9\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">threshold = 6\nerror_series = pd.Series(error.flatten())\nprice_series = pd.Series(timeseries.flatten())\n\nanomalies_filter = error_series.apply(lambda x: True if x &gt; threshold else False)\nanomalies = price_series[anomalies_filter]\n\nplt.figure(figsize=(14, 8))\nplt.scatter(x=anomalies.index, y=anomalies, color=\"red\", label=\"anomalies\")\nplt.plot(df.index, timeseries, color='blue')\nplt.title('Closing price')\nplt.xlabel('Days')\nplt.ylabel('Price')\nplt.legend()\nplt.show()<\/pre>\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-539699\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/Plot-the-anomalous-data-points-in-the-graph.png\" alt=\"\u5728\u56fe\u5f62\u4e2d\u7ed8\u5236\u5f02\u5e38\u6570\u636e\u70b9\" width=\"1600\" height=\"963\" \/><\/figure>\n<h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2>\n<p>\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u662f\u5546\u4e1a\u548c\u79d1\u5b66\u7814\u7a76\u7b49\u8bb8\u591a\u5e94\u7528\u4e2d\u4f7f\u7528\u7684\u5e38\u89c1\u6570\u636e\u5f62\u5f0f\u3002 \u7531\u4e8e\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u987a\u5e8f\u6027\uff0c\u9700\u8981\u4f7f\u7528\u7279\u6b8a\u7684\u65b9\u6cd5\u548c\u7b97\u6cd5\u6765\u5e2e\u52a9\u786e\u5b9a\u5176\u4e2d\u7684\u5f02\u5e38\u3002 \u5728\u8fd9\u7bc7\u535a\u6587\u4e2d\uff0c\u6211\u4eec\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528 STL \u5206\u89e3\u8bc6\u522b\u5f02\u5e38\u4ee5\u6d88\u9664\u5b63\u8282\u6027\u548c\u8d8b\u52bf\u3002 \u6211\u4eec\u8fd8\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u6df1\u5ea6\u5b66\u4e60\u548c LSTM \u6a21\u578b\u6bd4\u8f83\u9884\u6d4b\u4f30\u8ba1\u503c\u548c\u5b9e\u9645\u6570\u636e\u4ee5\u786e\u5b9a\u5f02\u5e38\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u4f7f\u7528 PyCharm \u68c0\u6d4b\u5f02\u5e38<\/h2>\n<p>\u4f7f\u7528 PyCharm Professional \u4e2d\u7684 Jupyter \u9879\u76ee\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u7ec4\u7ec7\u5305\u542b\u5927\u91cf\u6570\u636e\u6587\u4ef6\u548c Notebook \u7684\u5f02\u5e38\u68c0\u6d4b\u9879\u76ee\u3002 \u5728 PyCharm \u4e2d\uff0c\u53ef\u4ee5\u751f\u6210\u56fe\u5f62\u8f93\u51fa\u4ee5\u68c0\u67e5\u5f02\u5e38\uff0c\u5e76\u975e\u5e38\u65b9\u4fbf\u5730\u67e5\u770b\u7ed8\u56fe\u3002 \u5176\u4ed6\u529f\u80fd\uff0c\u4f8b\u5982\u81ea\u52a8\u8865\u5168\u5efa\u8bae\uff0c\u4f7f\u6d4f\u89c8 Scikit-learn \u6a21\u578b\u548c Matplotlib \u7ed8\u56fe\u8bbe\u7f6e\u53d8\u5f97\u975e\u5e38\u5bb9\u6613\u3002<\/p>\n<p>\u4f7f\u7528 PyCharm \u589e\u5f3a\u6570\u636e\u79d1\u5b66\u9879\u76ee\uff0c<a href=\"https:\/\/www.jetbrains.com.cn\/pycharm\/data-science\/\" target=\"_blank\" rel=\"noopener\">\u67e5\u770b\u4e3a\u7b80\u5316\u6570\u636e\u79d1\u5b66\u5de5\u4f5c\u6d41\u63d0\u4f9b\u7684\u6570\u636e\u79d1\u5b66\u529f\u80fd<\/a>\u3002<\/p>\n<div class=\"buttons\">\n<div class=\"buttons__row\"><a class=\"btn\" href=\"https:\/\/www.jetbrains.com.cn\/pycharm\/data-science\/\" target=\"\" rel=\"noopener\">\u514d\u8d39\u5f00\u59cb\u4f7f\u7528 PyCharm Pro<\/a><\/div>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>\u672c\u535a\u6587\u82f1\u6587\u539f\u4f5c\u8005\uff1a<\/p>\n\n\n    <div class=\"about-author \">\n        <div class=\"about-author__box\">\n            <div class=\"row\">\n                <div class=\"about-author__box-img\">\n                    <img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/01\/CheukTingHo-Kimono-e1738750639162-200x200.jpg\" width=\"200\" height=\"200\" alt=\"Cheuk Ting Ho\" loading=\"lazy\"  class=\"avatar avatar-200 wp-user-avatar wp-user-avatar-200 photo avatar-default\">\n                <\/div>\n                <div class=\"about-author__box-text\">\n                                            <h4>Cheuk Ting Ho<\/h4>\n                                                        <\/div>\n            <\/div>\n        <\/div>\n    <\/div>\n","protected":false},"author":1297,"featured_media":556334,"comment_status":"closed","ping_status":"closed","template":"","categories":[952,1401],"tags":[8670],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/pycharm\/554108"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/pycharm"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/types\/pycharm"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/users\/1297"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/comments?post=554108"}],"version-history":[{"count":6,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/pycharm\/554108\/revisions"}],"predecessor-version":[{"id":556360,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/pycharm\/554108\/revisions\/556360"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media\/556334"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/media?parent=554108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/categories?post=554108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/tags?post=554108"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/zh-hans\/wp-json\/wp\/v2\/cross-post-tag?post=554108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}