{"id":564415,"date":"2025-05-21T07:28:03","date_gmt":"2025-05-21T06:28:03","guid":{"rendered":"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-time-series\/"},"modified":"2025-05-21T07:28:10","modified_gmt":"2025-05-21T06:28:10","slug":"anomaly-detection-in-time-series","status":"publish","type":"pycharm","link":"https:\/\/blog.jetbrains.com\/ja\/pycharm\/2025\/05\/anomaly-detection-in-time-series\/","title":{"rendered":"Python \u3067\u5b66\u3076\u6642\u7cfb\u5217\u306e\u7570\u5e38\u691c\u77e5"},"content":{"rendered":"<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-568796 size-full\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2025\/05\/PC-social-BlogFeatured-2560x1440-1.png\" alt=\"\" width=\"2560\" height=\"1440\" \/><\/figure>\n<p>\u91cd\u5927\u306a\u554f\u984c\u3084\u96a0\u308c\u305f\u6a5f\u4f1a\u3092\u793a\u3057\u3066\u3044\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u7570\u5e38\u306a\u30c7\u30fc\u30bf\u30d1\u30bf\u30fc\u30f3\u3092\u767a\u898b\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u306e\u3067\u3057\u3087\u3046\u304b\uff1f \u901a\u5e38\u306e\u5024\u304b\u3089\u5927\u5e45\u306b\u9038\u8131\u3057\u3066\u3044\u308b\u30c7\u30fc\u30bf\u3092\u767a\u898b\u3059\u308b\u306b\u306f\u3001<a href=\"https:\/\/blog.jetbrains.com\/ja\/pycharm\/2025\/05\/anomaly-detection-in-machine-learning\/\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/ja\/pycharm\/2025\/05\/anomaly-detection-in-machine-learning\/\">\u7570\u5e38\u691c\u77e5<\/a>\u304c\u5f79\u7acb\u3061\u307e\u3059\u3002 \u3042\u308b\u671f\u9593\u306b\u53ce\u96c6\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3067\u69cb\u6210\u3055\u308c\u308b\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306b\u306f\u3001\u30c8\u30ec\u30f3\u30c9\u3084\u5b63\u7bc0\u6027\u306e\u30d1\u30bf\u30fc\u30f3\u304c\u5f80\u3005\u306b\u3057\u3066\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002 \u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u5185\u306e\u7570\u5e38\u306f\u3053\u308c\u3089\u306e\u30d1\u30bf\u30fc\u30f3\u304c\u5909\u52d5\u3057\u305f\u3068\u304d\u306b\u767a\u751f\u3059\u308b\u305f\u3081\u3001\u7570\u5e38\u691c\u77e5\u306f\u8ca9\u58f2\u3001\u91d1\u878d\u3001\u88fd\u9020\u3001\u30d8\u30eb\u30b9\u30b1\u30a2\u306a\u3069\u306e\u696d\u754c\u3067\u91cd\u5b9d\u3055\u308c\u308b\u30c4\u30fc\u30eb\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306b\u306f\u5b63\u7bc0\u6027\u3084\u30c8\u30ec\u30f3\u30c9\u3068\u3044\u3063\u305f\u56fa\u6709\u306e\u7279\u5fb4\u304c\u3042\u308b\u305f\u3081\u3001\u7570\u5e38\u3092\u52b9\u679c\u7684\u306b\u691c\u51fa\u3059\u308b\u306b\u306f\u7279\u5225\u306a\u624b\u6cd5\u304c\u5fc5\u8981\u3067\u3059\u3002 \u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u3067\u306f\u3001STL \u5206\u89e3\u3084 LSTM \u4e88\u6e2c\u306a\u3069\u306e\u4e00\u822c\u7684\u306a\u6642\u7cfb\u5217\u306e\u7570\u5e38\u691c\u77e5\u624b\u6cd5\u3068\u3001\u4f5c\u696d\u3092\u958b\u59cb\u3059\u308b\u306e\u306b\u5f79\u7acb\u3064\u8a73\u7d30\u306a\u30b3\u30fc\u30c9\u4f8b\u3092\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u30d3\u30b8\u30cd\u30b9\u306b\u304a\u3051\u308b\u6642\u7cfb\u5217\u7570\u5e38\u691c\u77e5<\/h2>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306f\u591a\u304f\u306e\u30d3\u30b8\u30cd\u30b9\u3084\u30b5\u30fc\u30d3\u30b9\u306b\u6b20\u304b\u305b\u306a\u3044\u3082\u306e\u3067\u3059\u3002 \u591a\u304f\u306e\u30d3\u30b8\u30cd\u30b9\u3067\u306f\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u4ed8\u304d\u306e\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u3092\u8a18\u9332\u3057\u3001\u305d\u308c\u306b\u3088\u3063\u3066\u4e00\u5b9a\u671f\u9593\u5185\u306e\u5909\u5316\u3092\u5206\u6790\u3057\u3066\u30c7\u30fc\u30bf\u3092\u6bd4\u8f03\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002 \u6642\u7cfb\u5217\u306f\u3001\u30c7\u30fc\u30bf\u304c\u5b63\u7bc0\u6027\u306e\u7279\u5fb4\u3092\u793a\u3059\u524d\u5e74\u6bd4\u6bd4\u8f03\u306e\u3088\u3046\u306b\u7279\u5b9a\u671f\u9593\u306b\u304a\u3051\u308b\u7279\u5b9a\u306e\u6570\u91cf\u3092\u6bd4\u8f03\u3059\u308b\u969b\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002<\/p>\n<p><strong>\u58f2\u4e0a\u306e\u76e3\u8996<\/strong><\/p>\n<p>\u5b63\u7bc0\u6027\u306e\u3042\u308b\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306e\u4ee3\u8868\u7684\u306a\u4f8b\u306e 1 \u3064\u306b\u306f\u3001\u58f2\u4e0a\u30c7\u30fc\u30bf\u304c\u3042\u308a\u307e\u3059\u3002 \u58f2\u4e0a\u306e\u591a\u304f\u306f\u6bce\u5e74\u306e\u795d\u796d\u65e5\u3084\u5b63\u7bc0\u306b\u3088\u308b\u5f71\u97ff\u3092\u53d7\u3051\u308b\u305f\u3081\u3001\u5b63\u7bc0\u6027\u3092\u8003\u616e\u305b\u305a\u306b\u58f2\u4e0a\u30c7\u30fc\u30bf\u306b\u95a2\u3059\u308b\u7d50\u8ad6\u3092\u5c0e\u304f\u306e\u306f\u56f0\u96e3\u3067\u3059\u3002 \u305d\u306e\u305f\u3081\u3001\u58f2\u4e0a\u30c7\u30fc\u30bf\u3092\u5206\u6790\u3057\u3066\u7570\u5e38\u3092\u767a\u898b\u3059\u308b\u306b\u306f\u3001STL \u5206\u89e3\u3068\u3044\u3046\u624b\u6cd5\u304c\u7528\u3044\u3089\u308c\u308b\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002\u3053\u308c\u306b\u3064\u3044\u3066\u306f<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\">\u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u306e\u5f8c\u534a<\/a>\u3067\u8a73\u3057\u304f\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\u91d1\u878d<\/strong><\/p>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306e\u4e00\u822c\u7684\u306a\u4f8b\u306b\u306f\u3001\u53d6\u5f15\u3084\u682a\u4fa1\u3068\u3044\u3063\u305f\u91d1\u878d\u30c7\u30fc\u30bf\u304c\u3042\u308a\u307e\u3059\u3002 \u91d1\u878d\u696d\u754c\u3067\u306f\u3001\u3053\u306e\u30c7\u30fc\u30bf\u3092\u5206\u6790\u3057\u3066\u7570\u5e38\u3092\u691c\u77e5\u3059\u308b\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002 \u305f\u3068\u3048\u3070\u3001\u6642\u7cfb\u5217\u4e88\u6e2c\u30e2\u30c7\u30eb\u3092\u81ea\u52d5\u58f2\u8cb7\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\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\">\u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u306e\u5f8c\u534a<\/a>\u3067\u306f\u3001\u6642\u7cfb\u5217\u4e88\u6e2c\u3092\u4f7f\u7528\u3057\u3066\u682a\u5f0f\u30c7\u30fc\u30bf\u306e\u7570\u5e38\u3092\u767a\u898b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u88fd\u9020<\/strong><\/p>\n<p>\u6642\u7cfb\u5217\u306e\u7570\u5e38\u691c\u77e5\u306f\u3001\u751f\u7523\u30e9\u30a4\u30f3\u3067\u306e\u6b20\u9665\u306e\u76e3\u8996\u306b\u3082\u4f7f\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u6a5f\u68b0\u306f\u76e3\u8996\u3055\u308c\u3066\u304a\u308a\u3001\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u3092\u63d0\u4f9b\u3057\u3066\u3044\u308b\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002 \u6f5c\u5728\u7684\u306a\u969c\u5bb3\u3092\u7ba1\u7406\u8005\u306b\u901a\u77e5\u3067\u304d\u308b\u3053\u3068\u306f\u4e0d\u53ef\u6b20\u3067\u3042\u308a\u3001\u7570\u5e38\u691c\u77e5\u306f\u91cd\u8981\u306a\u5f79\u5272\u3092\u679c\u305f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><strong>\u533b\u7642\u3068\u30d8\u30eb\u30b9\u30b1\u30a2<\/strong><\/p>\n<p>\u533b\u7642\u3068\u30d8\u30eb\u30b9\u30b1\u30a2\u306e\u5206\u91ce\u3067\u306f\u3001\u4eba\u306e\u30d0\u30a4\u30bf\u30eb\u30b5\u30a4\u30f3\u3092\u76e3\u8996\u3057\u3066\u7570\u5e38\u3092\u691c\u77e5\u3067\u304d\u307e\u3059\u3002 \u3053\u308c\u306f\u533b\u7642\u7814\u7a76\u3067\u306f\u5341\u5206\u306b\u91cd\u8981\u306a\u3053\u3068\u3067\u3059\u304c\u3001\u8a3a\u65ad\u3067\u306f\u4e0d\u53ef\u6b20\u306a\u3053\u3068\u3067\u3059\u3002 \u5165\u9662\u60a3\u8005\u306e\u30d0\u30a4\u30bf\u30eb\u30b5\u30a4\u30f3\u306b\u7570\u5e38\u304c\u3042\u308b\u306e\u306b\u5fdc\u6025\u63aa\u7f6e\u304c\u53d6\u3089\u308c\u306a\u3044\u5834\u5408\u3001\u81f4\u547d\u7684\u306a\u7d50\u679c\u306b\u306a\u308a\u304b\u306d\u307e\u305b\u3093\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u6642\u7cfb\u5217\u7570\u5e38\u691c\u77e5\u306b\u7279\u6b8a\u306a\u624b\u6cd5\u3092\u7528\u3044\u308b\u3053\u3068\u304c\u91cd\u8981\u306a\u7406\u7531<\/h2>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306f\u3001\u4ed6\u306e\u7a2e\u985e\u306e\u30c7\u30fc\u30bf\u3068\u540c\u69d8\u306b\u6271\u3048\u306a\u3044\u3053\u3068\u304c\u3042\u308b\u70b9\u3067\u7279\u5225\u3067\u3059\u3002 \u305f\u3068\u3048\u3070\u3001\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\/\u30c6\u30b9\u30c8\u5206\u5272\u3092\u9069\u7528\u3059\u308b\u5834\u5408\u3001\u30c7\u30fc\u30bf\u306f\u6642\u9593\u7684\u306b\u9023\u7d9a\u3057\u3066\u95a2\u4fc2\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u30b7\u30e3\u30c3\u30d5\u30eb\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002 \u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u3092\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u30e2\u30c7\u30eb\u306b\u9069\u7528\u3059\u308b\u5834\u5408\u306b\u3082\u540c\u3058\u3053\u3068\u304c\u8a00\u3048\u307e\u3059\u3002 \u9023\u7d9a\u7684\u306a\u95a2\u4fc2\u6027\u3092\u8003\u616e\u3059\u308b\u306b\u306f\u56de\u5e30\u578b\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\uff08RNN\uff09\u304c\u4e00\u822c\u7684\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u30c7\u30fc\u30bf\u306f\u6642\u9593\u67a0\u3068\u3057\u3066\u5165\u529b\u3055\u308c\u3001\u305d\u306e\u4e2d\u3067\u30a4\u30d9\u30f3\u30c8\u306e\u9806\u5e8f\u304c\u4fdd\u6301\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u304c\u7279\u6b8a\u306a\u306e\u306f\u3001\u7121\u8996\u3067\u304d\u306a\u3044\u5b63\u7bc0\u6027\u3068\u30c8\u30ec\u30f3\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u591a\u3044\u304b\u3089\u3067\u3082\u3042\u308a\u307e\u3059\u3002 \u3053\u306e\u5b63\u7bc0\u6027\u306f\u3001\u4e00\u822c\u7684\u306b\u306f 24 \u6642\u9593\u30017 \u65e5\u3001\u307e\u305f\u306f 12 \u304b\u6708\u306a\u3069\u306e\u5468\u671f\u3067\u73fe\u308c\u307e\u3059\u3002 <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\">\u4ee5\u4e0b\u306e\u4f8b<\/a>\u304b\u3089\u5206\u304b\u308b\u3088\u3046\u306b\u3001\u7570\u5e38\u3092\u5224\u65ad\u3067\u304d\u308b\u306e\u306f\u5b63\u7bc0\u6027\u3068\u30c8\u30ec\u30f3\u30c9\u304c\u8003\u616e\u3055\u308c\u305f\u5f8c\u3060\u3051\u3067\u3059\u3002<\/p>\n<h2 class=\"wp-block-heading\">\u6642\u7cfb\u5217\u306e\u7570\u5e38\u691c\u77e5\u306b\u4f7f\u7528\u3055\u308c\u308b\u624b\u6cd5<\/h2>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306f\u7279\u6b8a\u3067\u3042\u308b\u305f\u3081\u3001\u305d\u306e\u4e2d\u306e\u7570\u5e38\u3092\u691c\u77e5\u3059\u308b\u305f\u3081\u306e\u7279\u5225\u306a\u624b\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002 \u30c7\u30fc\u30bf\u306e\u7a2e\u985e\u306b\u3082\u3088\u308a\u307e\u3059\u304c\u3001\u6642\u7cfb\u5217\u306b\u306f\u524d\u306e<a href=\"https:\/\/blog.jetbrains.com\/ja\/pycharm\/2025\/05\/anomaly-detection-in-machine-learning\/\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/ja\/pycharm\/2025\/05\/anomaly-detection-in-machine-learning\/\">\u7570\u5e38\u691c\u77e5\u306b\u95a2\u3059\u308b\u30d6\u30ed\u30b0\u8a18\u4e8b<\/a>\u3067\u8ff0\u3079\u305f\u3044\u304f\u3064\u304b\u306e\u624b\u6cd5\u3068\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u305f\u3060\u3057\u3001\u305d\u308c\u3089\u306e\u624b\u6cd5\u306b\u3088\u308b\u7570\u5e38\u691c\u77e5\u306f\u3001\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u7528\u306b\u7279\u5225\u306b\u8a2d\u8a08\u3055\u308c\u305f\u624b\u6cd5\u307b\u3069\u4fe1\u983c\u3067\u304d\u308b\u3082\u306e\u3067\u306f\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002 \u5834\u5408\u306b\u3088\u3063\u3066\u306f\u691c\u77e5\u624b\u6cd5\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u3057\u3001\u691c\u77e5\u7d50\u679c\u3092\u518d\u78ba\u8a8d\u3057\u3066\u507d\u967d\u6027\u3084\u507d\u9670\u6027\u306e\u8aa4\u691c\u77e5\u3092\u56de\u907f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3 class=\"wp-block-heading\">STL \u5206\u89e3<\/h3>\n<p>\u5b63\u7bc0\u6027\u304c\u542b\u307e\u308c\u308b\u6642\u7cfb\u5217\u3092\u4f7f\u7528\u3059\u308b\u6700\u3082\u4e00\u822c\u7684\u306a\u65b9\u6cd5\u306e 1 \u3064\u306b\u3001LOESS\uff08\u5c40\u6240\u63a8\u5b9a\u6563\u5e03\u56f3\u5e73\u6ed1\u5316\uff09\u3092\u4f7f\u7528\u3057\u305f\u5b63\u7bc0\u6027\u3068\u30c8\u30ec\u30f3\u30c9\u306e\u5206\u89e3\u3001\u3064\u307e\u308a STL \u5206\u89e3\u304c\u3042\u308a\u307e\u3059\u3002 \u3053\u306e\u624b\u6cd5\u3067\u306f\u3001\u6642\u7cfb\u5217\u304c\u5b63\u7bc0\u6027\u306e\u63a8\u5b9a\u5024\uff08\u6307\u5b9a\u3055\u308c\u305f\u671f\u9593\u307e\u305f\u306f\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3092\u4f7f\u7528\u3057\u3066\u6c7a\u5b9a\u3055\u308c\u305f\u671f\u9593\uff09\u3001\u30c8\u30ec\u30f3\u30c9\uff08\u63a8\u5b9a\uff09\u3001\u304a\u3088\u3073\u6b8b\u5dee\uff08\u30c7\u30fc\u30bf\u306e\u30ce\u30a4\u30ba\uff09\u3092\u4f7f\u7528\u3057\u3066\u5206\u89e3\u3055\u308c\u307e\u3059\u3002 <a href=\"https:\/\/www.statsmodels.org\/stable\/index.html\" target=\"_blank\" rel=\"noopener\">statsmodels<\/a> \u30e9\u30a4\u30d6\u30e9\u30ea\u306f\u3001<a href=\"https:\/\/www.statsmodels.org\/stable\/examples\/notebooks\/generated\/stl_decomposition.html\" target=\"_blank\" rel=\"noopener\">STL \u5206\u89e3\u30c4\u30fc\u30eb<\/a>\u3092\u63d0\u4f9b\u3059\u308b <a href=\"https:\/\/pleiades.io\/help\/pycharm\/python.html\" target=\"_blank\" rel=\"noopener\">Python<\/a> \u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\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>\u6b8b\u5dee\u304c\u3042\u308b\u7279\u5b9a\u306e\u3057\u304d\u3044\u5024\u3092\u8d85\u3048\u308b\u3068\u7570\u5e38\u304c\u691c\u77e5\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3 id=\"stl-beehive\" class=\"wp-block-heading\">\u990a\u8702\u7bb1\u30c7\u30fc\u30bf\u3067\u306e STL \u5206\u89e3\u306e\u4f7f\u7528<\/h3>\n<p>\u524d\u306e<a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2025\/01\/anomaly-detection-in-machine-learning\/\" data-type=\"link\" data-id=\"https:\/\/blog.jetbrains.com\/ja\/pycharm\/2025\/05\/anomaly-detection-in-machine-learning\/\">\u30d6\u30ed\u30b0\u8a18\u4e8b<\/a>\u3067\u306f\u3001<a href=\"https:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.svm.OneClassSVM.html\" target=\"_blank\" rel=\"noopener\">OneClassSVM<\/a> \u304a\u3088\u3073 <a href=\"https:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.ensemble.IsolationForest.html\" target=\"_blank\" rel=\"noopener\">IsolationForest<\/a> \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u305f\u990a\u8702\u7bb1\u306e\u7570\u5e38\u691c\u77e5\u306b\u3064\u3044\u3066\u63a2\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u306f\u3001statsmodels \u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u63d0\u4f9b\u3059\u308b <code>STL<\/code> \u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3001<a href=\"https:\/\/www.kaggle.com\/datasets\/vivovinco\/beehives\" target=\"_blank\" rel=\"noopener\">\u990a\u8702\u7bb1\u30c7\u30fc\u30bf<\/a>\u3092\u6642\u7cfb\u5217\u3068\u3057\u3066\u5206\u6790\u3057\u307e\u3059\u3002 \u307e\u305a\u306f\u3001\u3053\u3061\u3089\u306e <a href=\"https:\/\/github.com\/Cheukting\/anomaly-detection\/blob\/main\/requirements.txt\" target=\"_blank\" rel=\"noopener\">requirements.txt<\/a> \u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u3057\u3066\u74b0\u5883\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>1. \u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b<\/strong><\/h4>\n<p>\u3053\u308c\u307e\u3067\u306f Scikit-learn \u304c\u63d0\u4f9b\u3059\u308b\u30e2\u30c7\u30eb\u306e\u307f\u3092\u4f7f\u7528\u3057\u3066\u304d\u305f\u305f\u3081\u3001PyPI \u304b\u3089 statsmodels \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 <a href=\"https:\/\/www.jetbrains.com\/ja-jp\/pycharm\/data-science\/\" target=\"_blank\" rel=\"noreferrer noopener\">PyCharm<\/a> \u306a\u3089\u7c21\u5358\u306b\u884c\u3048\u307e\u3059\u3002<\/p>\n<div class=\"buttons\">\n<div class=\"buttons__row\"><a class=\"btn\" href=\"https:\/\/www.jetbrains.com\/ja-jp\/pycharm\/data-science\/\" target=\"\" rel=\"noopener\">PyCharm Pro \u3092\u7121\u6599\u3067\u4f7f\u3044\u59cb\u3081\u308b<\/a><\/div>\n<\/div>\n<p><em>Python <\/em><a href=\"https:\/\/pleiades.io\/help\/pycharm\/installing-uninstalling-and-upgrading-packages.html\" target=\"_blank\" rel=\"noopener\"><em>Package<\/em><\/a>\uff08Python \u30d1\u30c3\u30b1\u30fc\u30b8\uff09\u30a6\u30a3\u30f3\u30c9\u30a6\u306b\u79fb\u52d5\u3057\uff08IDE \u306e\u5de6\u4e0b\u306b\u3042\u308b\u30a2\u30a4\u30b3\u30f3\u3092\u9078\u629e\uff09\u3001\u691c\u7d22\u30dc\u30c3\u30af\u30b9\u306b\u300cstatsmodels\u300d\u3068\u5165\u529b\u3057\u307e\u3059\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 \u3067\u306e Statsmodels\" width=\"1600\" height=\"630\" \/><\/figure>\n<p>\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u95a2\u3059\u308b\u3059\u3079\u3066\u306e\u60c5\u5831\u304c\u53f3\u5074\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002 <em>Install package<\/em>\uff08\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\uff09\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>2. Jupyter \u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3092\u4f5c\u6210\u3059\u308b<\/strong><\/h4>\n<p>\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u3055\u3089\u306b\u8abf\u67fb\u3059\u308b\u305f\u3081\u3001<a href=\"https:\/\/pleiades.io\/help\/pycharm\/jupyter-notebook-support.html\" target=\"_blank\" rel=\"noopener\">Jupyter \u30ce\u30fc\u30c8\u30d6\u30c3\u30af<\/a> \u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u305d\u308c\u306b\u3088\u308a\u3001PyCharm \u306e Jupyter \u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u74b0\u5883\u304c\u63d0\u4f9b\u3059\u308b\u30c4\u30fc\u30eb\u306e\u30e1\u30ea\u30c3\u30c8\u3092\u6d3b\u7528\u3067\u304d\u307e\u3059\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=\"PyCharm \u3067 Jupyter \u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3092\u4f5c\u6210\u3059\u308b\" width=\"1098\" height=\"410\" \/><\/figure>\n<p><a href=\"https:\/\/blog.jetbrains.com\/pycharm\/2024\/10\/data-exploration-with-pandas\/\">pandas<\/a> \u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3066\u3001<code>.csv<\/code> \u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\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=\"PyCharm \u3067 pandas \u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\" width=\"1600\" height=\"930\" \/><\/figure>\n<h4 class=\"wp-block-heading\"><strong>3. \u30c7\u30fc\u30bf\u3092\u30b0\u30e9\u30d5\u5f62\u5f0f\u3067\u8abf\u3079\u308b<\/strong><\/h4>\n<p>\u30c7\u30fc\u30bf\u3092\u30b0\u30e9\u30d5\u5f62\u5f0f\u3067\u8abf\u3079\u3089\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 \u3053\u3053\u3067\u306f\u3001\u990a\u8702\u7bb1 17 \u756a\u306e\u3042\u308b\u671f\u9593\u306e\u6e29\u5ea6\u3092\u898b\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002 DataFrame \u30a4\u30f3\u30b9\u30da\u30af\u30bf\u30fc\u306e <em>Chart view<\/em>\uff08\u30c1\u30e3\u30fc\u30c8\u30d3\u30e5\u30fc\uff09\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001\u7cfb\u5217\u8a2d\u5b9a\u3067 <em>T17<\/em> \u3092 y \u8ef8\u306b\u9078\u629e\u3057\u307e\u3059\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=\"PyCharm \u3067\u30c7\u30fc\u30bf\u3092\u30b0\u30e9\u30d5\u5f62\u5f0f\u3067\u8abf\u3079\u308b\" width=\"720\" height=\"290\" \/><\/figure>\n<p>\u6642\u7cfb\u5217\u3067\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u3088\u3046\u306b\u3001\u6e29\u5ea6\u306b\u306f\u591a\u6570\u306e\u4e0a\u4e0b\u5909\u52d5\u304c\u3042\u308a\u307e\u3059\u3002 \u3053\u308c\u306f\u663c\u591c\u306e\u30b5\u30a4\u30af\u30eb\u306b\u3088\u308b\u5b9a\u671f\u7684\u306a\u632f\u308b\u821e\u3044\u3092\u793a\u3057\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u308b\u305f\u3081\u3001\u6e29\u5ea6\u306b\u306f 24 \u6642\u9593\u306e\u5468\u671f\u304c\u3042\u308b\u3068\u898b\u306a\u3057\u3066\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u6b21\u306b\u3001\u6e29\u5ea6\u304c\u7d4c\u6642\u7684\u306b\u4f4e\u4e0b\u3057\u3066\u3044\u308b\u30c8\u30ec\u30f3\u30c9\u304c\u898b\u3089\u308c\u307e\u3059\u3002 <em>DateTime<\/em> \u5217\u3092\u78ba\u8a8d\u3059\u308b\u3068\u3001\u65e5\u4ed8\u306e\u7bc4\u56f2\u304c 8 \u6708\u304b\u3089 11 \u6708\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u304c\u308f\u304b\u308a\u307e\u3059\u3002 <a href=\"https:\/\/www.kaggle.com\/datasets\/vivovinco\/beehives\/data\" target=\"_blank\" rel=\"noopener\">Kaggle \u306e\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u30da\u30fc\u30b8<\/a>\u306b\u306f\u30c8\u30eb\u30b3\u3067\u30c7\u30fc\u30bf\u304c\u53ce\u96c6\u3055\u308c\u305f\u3068\u3042\u308b\u305f\u3081\u3001\u6e29\u5ea6\u304c\u7d4c\u6642\u7684\u306b\u4f4e\u4e0b\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u89b3\u6e2c\u306f\u590f\u304b\u3089\u79cb\u3078\u306e\u5909\u5316\u306b\u3088\u308b\u3082\u306e\u3060\u3068\u8aac\u660e\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>4. \u6642\u7cfb\u5217\u306e\u5206\u89e3<\/strong><\/h4>\n<p>\u6642\u7cfb\u5217\u3092\u7406\u89e3\u3057\u3066\u7570\u5e38\u3092\u691c\u77e5\u3059\u308b\u305f\u3081\u3001statsmodels \u304b\u3089 <code>STL<\/code> \u30af\u30e9\u30b9\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3066\u305d\u308c\u3092\u6e29\u5ea6\u30c7\u30fc\u30bf\u306b\u9069\u5408\u3055\u305b\u3066\u304b\u3089 STL \u5206\u89e3\u3092\u884c\u3044\u307e\u3059\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>\u5206\u89e3\u3092\u884c\u3046\u671f\u9593\u3092\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u524d\u8ff0\u306e\u3088\u3046\u306b\u300124 \u6642\u9593\u306e\u5468\u671f\u304c\u3042\u308b\u3068\u4eee\u5b9a\u3059\u308b\u306e\u304c\u7121\u96e3\u3067\u3059\u3002<\/p>\n<p>\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3088\u308b\u3068\u3001<code>STL<\/code> \u306f\u6642\u7cfb\u5217\u3092\u30c8\u30ec\u30f3\u30c9\u3001\u5b63\u7bc0\u6027\u3001\u304a\u3088\u3073\u6b8b\u5dee\u306e 3 \u3064\u306e\u8981\u7d20\u306b\u5206\u89e3\u3057\u307e\u3059\u3002 \u5206\u89e3\u3055\u308c\u305f\u7d50\u679c\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u3001\u7d44\u307f\u8fbc\u307f\u306e <code>plot<\/code> \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\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.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=\"\u6642\u7cfb\u5217\u306e\u5206\u89e3\" width=\"1600\" height=\"1100\" \/><\/figure>\n<p><em>Trend<\/em>\uff08\u30c8\u30ec\u30f3\u30c9\uff09\u3068 <em>Season<\/em>\uff08\u5b63\u7bc0\uff09\u30d7\u30ed\u30c3\u30c8\u304c\u4e0a\u8a18\u306e\u4eee\u5b9a\u3068\u4e00\u81f4\u3057\u3066\u3044\u308b\u306e\u304c\u5206\u304b\u308a\u307e\u3059\u3002 \u305f\u3060\u3057\u3001\u95a2\u5fc3\u304c\u3042\u308b\u306e\u306f\u4e00\u756a\u4e0b\u306b\u3042\u308b\u6b8b\u5dee\u306e\u30d7\u30ed\u30c3\u30c8\u3067\u3059\u3002\u3053\u308c\u306f\u3001\u30c8\u30ec\u30f3\u30c9\u3068\u5b63\u7bc0\u6027\u306e\u5909\u5316\u304c\u542b\u307e\u308c\u306a\u3044\u672c\u6765\u306e\u7cfb\u5217\u3067\u3059\u3002 \u6b8b\u5dee\u5185\u306e\u6975\u5ea6\u306b\u9ad8\u3044\u5024\u3084\u4f4e\u3044\u5024\u306f\u7570\u5e38\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h4 id=\"anomaly-threshold\" class=\"wp-block-heading\"><strong>5. \u7570\u5e38\u306e\u3057\u304d\u3044\u5024<\/strong><\/h4>\n<p>\u6b21\u306b\u3001\u6b8b\u5dee\u306e\u3069\u306e\u5024\u3092\u7570\u5e38\u3068\u898b\u306a\u3059\u304b\u3092\u5224\u65ad\u3057\u307e\u3057\u3087\u3046\u3002 \u3053\u308c\u3092\u884c\u3046\u305f\u3081\u3001\u6b8b\u5dee\u306e\u30d2\u30b9\u30c8\u30b0\u30e9\u30e0\u3092\u78ba\u8a8d\u3057\u307e\u3059\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 \u3067\u306e\u7570\u5e38\u306e\u3057\u304d\u3044\u5024\" width=\"1328\" height=\"1048\" \/><\/figure>\n<p>\u3053\u308c\u306f\u30015 \u3088\u308a\u4e0a\u3068 -5 \u3088\u308a\u4e0b\u306b\u9577\u3044\u88fe\u3092\u6301\u3064 0 \u3092\u4e2d\u5fc3\u3068\u3059\u308b\u6b63\u898f\u5206\u5e03\u3067\u3042\u308b\u3068\u898b\u306a\u305b\u308b\u305f\u3081\u3001\u3057\u304d\u3044\u5024\u3092 5 \u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u672c\u6765\u306e\u6642\u7cfb\u5217\u3067\u7570\u5e38\u3092\u793a\u3059\u305f\u3081\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066\u30b0\u30e9\u30d5\u5185\u306e\u3059\u3079\u3066\u306e\u7570\u5e38\u3092\u8d64\u304f\u3057\u307e\u3057\u3087\u3046\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\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 \u3067\u898b\u308b\u672c\u6765\u306e\u6642\u7cfb\u5217\u306e\u7570\u5e38\" width=\"1600\" height=\"976\" \/><\/figure>\n<p>STL \u5206\u89e3\u3092\u884c\u308f\u306a\u3044\u5834\u5408\u3001\u671f\u9593\u3068\u30c8\u30ec\u30f3\u30c9\u3067\u69cb\u6210\u3055\u308c\u308b\u6642\u7cfb\u5217\u5185\u3067\u3053\u308c\u3089\u306e\u7570\u5e38\u3092\u767a\u898b\u3059\u308b\u306e\u306f\u975e\u5e38\u306b\u56f0\u96e3\u3067\u3059\u3002<\/p>\n<h3 class=\"wp-block-heading\">LSTM \u306b\u3088\u308b\u4e88\u6e2c<\/h3>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u5185\u306e\u7570\u5e38\u3092\u691c\u77e5\u3059\u308b\u65b9\u6cd5\u306b\u306f\u3001\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u306e\u624b\u6cd5\u3092\u4f7f\u7528\u3057\u3066\u7cfb\u5217\u306b\u5bfe\u3057\u3066\u6642\u7cfb\u5217\u4e88\u6e2c\u3092\u884c\u3044\u3001\u30c7\u30fc\u30bf\u30dd\u30a4\u30f3\u30c8\u306e\u7d50\u679c\u3092\u4e88\u6e2c\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002 \u4e88\u6e2c\u304c\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u30dd\u30a4\u30f3\u30c8\u3068\u5927\u304d\u304f\u7570\u306a\u3063\u3066\u3044\u308b\u5834\u5408\u3001\u305d\u308c\u306f\u7570\u5e38\u306e\u3042\u308b\u30c7\u30fc\u30bf\u306e\u5146\u5019\u3060\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u9023\u7d9a\u7684\u30c7\u30fc\u30bf\u306e\u4e88\u6e2c\u3092\u5b9f\u884c\u3059\u308b\u306e\u306b\u4e00\u822c\u7684\u306a\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306e 1 \u3064\u306b\u3001\u56de\u5e30\u578b\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\uff08RNN\uff09\u306e\u4e00\u7a2e\u3067\u3042\u308b\u9577\u30fb\u77ed\u671f\u8a18\u61b6\uff08LSTM\uff09\u30e2\u30c7\u30eb\u304c\u3042\u308a\u307e\u3059\u3002 LSTM \u30e2\u30c7\u30eb\u306b\u306f\u5165\u529b\u30b2\u30fc\u30c8\u3001\u5fd8\u5374\u30b2\u30fc\u30c8\u3001\u304a\u3088\u3073\u51fa\u529b\u30b2\u30fc\u30c8\u304c\u3042\u308a\u3001\u3053\u308c\u3089\u306f\u6570\u5024\u884c\u5217\u3067\u3059\u3002 \u3053\u308c\u306b\u3088\u308a\u3001\u30c7\u30fc\u30bf\u306e\u6b21\u306e\u53cd\u5fa9\u51e6\u7406\u306b\u91cd\u8981\u306a\u60c5\u5831\u304c\u78ba\u5b9f\u306b\u6e21\u3055\u308c\u307e\u3059\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 \u30bb\u30eb\" width=\"1600\" height=\"900\" \/><\/figure>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306f\u9023\u7d9a\u3057\u305f\u30c7\u30fc\u30bf\uff08\u30c7\u30fc\u30bf\u30dd\u30a4\u30f3\u30c8\u306e\u9806\u5e8f\u304c\u9023\u7d9a\u3057\u3066\u3044\u308b\u30c7\u30fc\u30bf\uff09\u3067\u3042\u308a\u3001\u30b7\u30e3\u30c3\u30d5\u30eb\u3067\u304d\u307e\u305b\u3093\u3002LSTM \u30e2\u30c7\u30eb\u306f\u3042\u308b\u7279\u5b9a\u306e\u6642\u9593\u306e\u51fa\u529b\u3092\u4e88\u6e2c\u3059\u308b\u306e\u306b\u52b9\u679c\u7684\u306a\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u30e2\u30c7\u30eb\u3067\u3059\u3002 \u3053\u306e\u4e88\u6e2c\u3092\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u3068\u6bd4\u8f03\u3059\u308b\u3068\u3001\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u304c\u7570\u5e38\u304b\u3069\u3046\u304b\u3092\u5224\u65ad\u3059\u308b\u305f\u3081\u306e\u3057\u304d\u3044\u5024\u3092\u8a2d\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3 id=\"lstm-stock\" class=\"wp-block-heading\">\u682a\u4fa1\u306b\u5bfe\u3059\u308b LSTM \u4e88\u6e2c\u306e\u4f7f\u7528<\/h3>\n<p>\u3067\u306f\u3001\u65b0\u3057\u3044 Jupyter \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u958b\u59cb\u3057\u3066\u3001\u904e\u53bb 5 \u5e74\u9593\u306b\u304a\u3051\u308b Apple \u306e\u682a\u4fa1\u306e\u7570\u5e38\u3092\u691c\u77e5\u3057\u3066\u307f\u307e\u3057\u3087\u3046\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\">\u682a\u4fa1\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8<\/a>\u306f\u6700\u65b0\u306e\u30c7\u30fc\u30bf\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002 \u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u306b\u6cbf\u3063\u3066\u4f5c\u696d\u3092\u9032\u3081\u308b\u5834\u5408\u306f\u3001\u3053\u3053\u3067\u4f7f\u7528\u3057\u3066\u3044\u308b<a href=\"https:\/\/github.com\/Cheukting\/lstm_anomaly_detection\/tree\/main\/data\" target=\"_blank\" rel=\"noopener\">\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/a>\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>1. Jupyter \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u958b\u59cb\u3059\u308b<\/strong><\/h4>\n<p>\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u958b\u59cb\u3059\u308b\u969b\u306b\u306f\u3001\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u306b\u6700\u9069\u5316\u3055\u308c\u305f Jupyter \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\u3092\u9078\u629e\u3067\u304d\u307e\u3059\u3002 <em>New Project<\/em>\uff08\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\uff09\u30a6\u30a3\u30f3\u30c9\u30a6\u3067 Git \u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3001\u3069\u306e conda \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u74b0\u5883\u3092\u7ba1\u7406\u3059\u308b\u304b\u3092\u6c7a\u5b9a\u3057\u307e\u3059\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=\"PyCharm \u3067 Jupyter \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u958b\u59cb\u3059\u308b\" width=\"1592\" height=\"1282\" \/><\/figure>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u8d77\u52d5\u3059\u308b\u3068\u3001\u30b5\u30f3\u30d7\u30eb\u306e\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002 \u3053\u306e\u6f14\u7fd2\u306b\u4f7f\u7528\u3059\u308b\u65b0\u3057\u3044 Jupyter \u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\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 \u5185\u306e\u30b5\u30f3\u30d7\u30eb\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\" width=\"716\" height=\"382\" \/><\/figure>\n<p>\u4f5c\u6210\u3057\u305f\u3089\u3001<code>requirements.txt<\/code> \u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3057\u307e\u3057\u3087\u3046\u3002 pandas\u3001matplotlib\u3001\u304a\u3088\u3073 PyPI \u3067\u300ctorch\u300d\u3068\u540d\u4ed8\u3051\u3089\u308c\u3066\u3044\u308b PyTorch \u304c\u5fc5\u8981\u3067\u3059\u3002 PyTorch \u306f conda \u74b0\u5883\u306b\u306f\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u305f\u3081\u3001PyCharm \u304b\u3089\u305d\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u6b20\u843d\u3057\u3066\u3044\u308b\u3068\u901a\u77e5\u3055\u308c\u307e\u3059\u3002 \u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u306b\u306f\u3001\u96fb\u7403\u30a2\u30a4\u30b3\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001<em>Install all missing packages<\/em>\uff08\u3059\u3079\u3066\u306e\u6b20\u843d\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\uff09\u3092\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044\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=\"PyCharm \u306e Install all missing packages\uff08\u3059\u3079\u3066\u306e\u6b20\u843d\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\uff09\" width=\"1358\" height=\"762\" \/><\/figure>\n<h4 class=\"wp-block-heading\"><strong>2. \u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u3068\u691c\u67fb<\/strong><\/h4>\n<p>\u6b21\u306b\u3001<a href=\"https:\/\/github.com\/Cheukting\/lstm_anomaly_detection\/tree\/main\/data\" target=\"_blank\" rel=\"noopener\">apple_stock_5y.csv<\/a> \u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092 data \u30d5\u30a9\u30eb\u30c0\u30fc\u306b\u914d\u7f6e\u3057\u3001pandas DataFrame \u3068\u3057\u3066\u8aad\u307f\u8fbc\u3093\u3067\u691c\u67fb\u3057\u307e\u3059\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>\u5bfe\u8a71\u578b\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u6b20\u640d\u30c7\u30fc\u30bf\u304c\u306a\u3044\u304b\u3092\u7c21\u5358\u306b\u78ba\u8a8d\u3067\u304d\u307e\u3059\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>\u6b20\u640d\u30c7\u30fc\u30bf\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u30011 \u3064\u554f\u984c\u304c\u3042\u308a\u307e\u3059\u3002<em>Close\/Last<\/em> \u4fa1\u683c\u3092\u4f7f\u7528\u3057\u305f\u3044\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u306f\u6570\u5024\u30c7\u30fc\u30bf\u578b\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002 \u5909\u63db\u3092\u884c\u3044\u3001\u3082\u3046\u4e00\u5ea6\u30c7\u30fc\u30bf\u3092\u691c\u7d22\u3057\u307e\u3057\u3087\u3046\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=\"\">df[\"Close\/Last\"] = df[\"Close\/Last\"].apply(lambda x: float(x[1:]))\ndf<\/pre>\n<p>\u5bfe\u8a71\u578b\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3063\u3066\u4fa1\u683c\u3092\u691c\u67fb\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002 \u5de6\u5074\u306e\u30d7\u30ed\u30c3\u30c8\u30a2\u30a4\u30b3\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u30d7\u30ed\u30c3\u30c8\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002 \u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f x \u8ef8\u306b <em>Date<\/em>\u3001y \u8ef8\u306b <em>Volume <\/em> \u304c\u4f7f\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u691c\u67fb\u3059\u308b\u306e\u306f <em>Close\/Last<\/em> \u4fa1\u683c\u3067\u3042\u308b\u305f\u3081\u3001\u53f3\u5074\u306e\u6b6f\u8eca\u30a2\u30a4\u30b3\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u8a2d\u5b9a\u306b\u79fb\u52d5\u3057\u3001<em>Close\/Last<\/em> \u3092 y \u8ef8\u306b\u9078\u629e\u3057\u307e\u3059\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. LSTM \u306e\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u30c7\u30fc\u30bf\u3092\u6e96\u5099\u3059\u308b<\/strong><\/h4>\n<p>LSTM \u30e2\u30c7\u30eb\u3067\u4f7f\u7528\u3055\u308c\u308b\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u30c7\u30fc\u30bf\u3092\u6e96\u5099\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u6b21\u306e\u4fa1\u683c\u3092\u4e88\u6e2c\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u305d\u308c\u305e\u308c\u304c\u6642\u9593\u67a0\u3092\u8868\u3059\u4e00\u9023\u306e\u30d9\u30af\u30c8\u30eb\uff08\u7279\u5fb4\u91cf X\uff09\u3092\u6e96\u5099\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002 \u6b21\u306e\u4fa1\u683c\u306b\u3088\u3063\u3066\u5225\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\uff08\u30bf\u30fc\u30b2\u30c3\u30c8 y\uff09\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002 \u3053\u3053\u3067\u306f\u3001\u3053\u306e\u6642\u9593\u67a0\u306e\u5927\u304d\u3055\u3092 <code>lookback<\/code> \u5909\u6570\u3092\u4f7f\u7528\u3057\u3066\u9078\u629e\u3067\u304d\u307e\u3059\u3002 \u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u3001\u30b7\u30fc\u30b1\u30f3\u30b9 X \u3068 y \u3092\u4f5c\u6210\u3057\u3001\u305d\u308c\u3089\u3092 PyTorch \u30c6\u30f3\u30bd\u30eb\u306b\u5909\u63db\u3057\u3066\u3044\u307e\u3059\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 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\u7684\u306b\u306f\u67a0\u304c\u5927\u304d\u3044\u307b\u3069\u5165\u529b\u30d9\u30af\u30c8\u30eb\u304c\u5927\u304d\u304f\u306a\u308b\u305f\u3081\u3001\u30e2\u30c7\u30eb\u3082\u5927\u304d\u304f\u306a\u308a\u307e\u3059\u3002 \u305f\u3060\u3057\u3001\u67a0\u304c\u5927\u304d\u3044\u307b\u3069\u5165\u529b\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u304c\u77ed\u304f\u306a\u308b\u305f\u3081\u3001\u3053\u306e lockback \u67a0\u306e\u6307\u5b9a\u3067\u306f\u30d0\u30e9\u30f3\u30b9\u3092\u53d6\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u307e\u305a\u306f 5 \u304b\u3089\u59cb\u3081\u307e\u3059\u304c\u3001\u9055\u3044\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u4ed6\u306e\u5024\u3082\u81ea\u7531\u306b\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>4. \u30e2\u30c7\u30eb\u3092\u69cb\u7bc9\u3057\u3066\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u3059\u308b<\/strong><\/h4>\n<p>\u30e2\u30c7\u30eb\u3092\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u3059\u308b\u524d\u306b\u3001PyTorch \u306e <a href=\"https:\/\/pytorch.org\/docs\/stable\/nn.html\" target=\"_blank\" rel=\"noopener\">nn \u30e2\u30b8\u30e5\u30fc\u30eb<\/a>\u3092\u4f7f\u7528\u3059\u308b\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3066\u30e2\u30c7\u30eb\u3092\u69cb\u7bc9\u3067\u304d\u307e\u3059\u3002 nn \u30e2\u30b8\u30e5\u30fc\u30eb\u306b\u306f\u5404\u7a2e\u306e\u30cb\u30e5\u30fc\u30e9\u30eb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30ec\u30a4\u30e4\u30fc\u306a\u3069\u3001\u8907\u6570\u306e\u30d3\u30eb\u30c7\u30a3\u30f3\u30b0\u30d6\u30ed\u30c3\u30af\u304c\u5099\u308f\u3063\u3066\u3044\u307e\u3059\u3002 \u3053\u306e\u6f14\u7fd2\u3067\u306f\u5358\u7d14\u306a <a href=\"https:\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.LSTM.html\" target=\"_blank\" rel=\"noopener\">LSTM \u30ec\u30a4\u30e4\u30fc<\/a>\u3092\u69cb\u7bc9\u3057\u3001<a href=\"https:\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.Linear.html\" target=\"_blank\" rel=\"noopener\">Linear \u30ec\u30a4\u30e4\u30fc<\/a>\u3092\u305d\u306e\u5f8c\u306b\u69cb\u7bc9\u3057\u307e\u3059\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 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>\u6b21\u306b\u3001\u30e2\u30c7\u30eb\u3092\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u3057\u307e\u3059\u3002 \u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u3059\u308b\u524d\u306b\u3001optimizer\u3001\u4e88\u6e2c\u3055\u308c\u308b y \u5024\u3068\u5b9f\u969b\u306e y \u5024\u306e\u9593\u306e\u640d\u5931\u3092\u8a08\u7b97\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3059\u308b<a href=\"https:\/\/pytorch.org\/docs\/stable\/nn.html#loss-functions\" target=\"_blank\" rel=\"noopener\">\u640d\u5931\u95a2\u6570<\/a>\u3001\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u30c7\u30fc\u30bf\u3092\u30d5\u30a3\u30fc\u30c9\u3059\u308b\u305f\u3081\u306e<a href=\"https:\/\/pytorch.org\/docs\/stable\/data.html#data-loading-order-and-sampler\" target=\"_blank\" rel=\"noopener\">\u30c7\u30fc\u30bf\u30ed\u30fc\u30c0\u30fc<\/a>\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\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 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>\u30c7\u30fc\u30bf\u30ed\u30fc\u30c0\u30fc\u306f\u5165\u529b\u3092\u30b7\u30e3\u30c3\u30d5\u30eb\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306f\u3059\u3067\u306b\u6642\u9593\u67a0\u3092\u4f5c\u6210\u6e08\u307f\u3067\u3042\u308a\u3001 \u305d\u308c\u306b\u3088\u3063\u3066\u5404\u67a0\u5185\u306e\u9023\u7d9a\u7684\u306a\u95a2\u4fc2\u6027\u304c\u7dad\u6301\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>\u30a8\u30dd\u30c3\u30af\u3054\u3068\u306b\u30eb\u30fc\u30d7\u51e6\u7406\u3092\u884c\u3046 <code>for<\/code> \u30eb\u30fc\u30d7\u3092\u4f7f\u3063\u3066\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u3092\u884c\u3044\u307e\u3059\u3002 100 \u30a8\u30dd\u30c3\u30af\u3054\u3068\u306b\u640d\u5931\u3092\u51fa\u529b\u3057\u3001\u30e2\u30c7\u30eb\u304c\u53ce\u675f\u3059\u308b\u69d8\u5b50\u3092\u89b3\u5bdf\u3057\u307e\u3059\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=\"\">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>\u3053\u3053\u3067\u306f 1000 \u30a8\u30dd\u30c3\u30af\u304b\u3089\u958b\u59cb\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u30e2\u30c7\u30eb\u306f\u975e\u5e38\u306b\u7d20\u65e9\u304f\u53ce\u675f\u3057\u307e\u3059\u3002 \u6700\u826f\u306e\u7d50\u679c\u3092\u5f97\u308b\u305f\u3081\u3001\u4ed6\u306e\u30a8\u30dd\u30c3\u30af\u6570\u3092\u81ea\u7531\u306b\u8a66\u3057\u3066\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\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=\"\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u306e\u30a8\u30dd\u30c3\u30af\" width=\"1346\" height=\"1046\" \/><\/figure>\n<p>PyCharm \u3067\u306f\u3001\u5b9f\u884c\u306b\u6642\u9593\u3092\u8981\u3059\u308b\u30bb\u30eb\u304b\u3089\u6b8b\u308a\u6642\u9593\u3068\u30bb\u30eb\u3078\u306e\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u304c\u542b\u307e\u308c\u308b\u901a\u77e5\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002 \u3053\u308c\u306f\u6a5f\u68b0\u5b66\u7fd2\u30e2\u30c7\u30eb\u3001\u7279\u306b\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u30e2\u30c7\u30eb\u3092 Jupyter \u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3067\u30c8\u30ec\u30fc\u30cb\u30f3\u30b0\u3059\u308b\u5834\u5408\u306b\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<h4 class=\"wp-block-heading\"><strong>5. \u4e88\u6e2c\u3092\u30d7\u30ed\u30c3\u30c8\u3057\u3066\u8aa4\u5dee\u3092\u898b\u3064\u3051\u308b<\/strong><\/h4>\n<p>\u6b21\u306b\u3001\u4e88\u6e2c\u3092\u4f5c\u6210\u3057\u3001\u5b9f\u969b\u306e\u6642\u7cfb\u5217\u3068\u4e00\u7dd2\u306b\u30d7\u30ed\u30c3\u30c8\u3057\u307e\u3059\u3002 \u5b9f\u969b\u306e\u6642\u7cfb\u5217\u306b\u4e00\u81f4\u3055\u305b\u308b\u306b\u306f\u30012 \u6b21\u5143\u306e np \u7cfb\u5217\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002 \u5b9f\u969b\u306e\u6642\u7cfb\u5217\u306f\u9752\u3001\u4e88\u6e2c\u3055\u308c\u305f\u6642\u7cfb\u5217\u306f\u8d64\u3067\u8868\u793a\u3055\u308c\u307e\u3059\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=\"\u4e88\u6e2c\u3092\u30d7\u30ed\u30c3\u30c8\u3057\u3066\u8aa4\u5dee\u3092\u898b\u3064\u3051\u308b\" width=\"1180\" height=\"856\" \/><\/figure>\n<p>\u3088\u304f\u89b3\u5bdf\u3059\u308b\u3068\u3001\u4e88\u6e2c\u3068\u5b9f\u969b\u306e\u5024\u304c\u5b8c\u5168\u306b\u4e00\u81f4\u3057\u306a\u3044\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u304c\u3001 \u307b\u3068\u3093\u3069\u306e\u4e88\u6e2c\u306f\u826f\u597d\u3060\u3068\u8a00\u3048\u307e\u3059\u3002<\/p>\n<p>\u8aa4\u5dee\u3092\u8a73\u3057\u304f\u691c\u67fb\u3059\u308b\u305f\u3081\u3001\u8aa4\u5dee\u7cfb\u5217\u3092\u4f5c\u6210\u3057\u3001\u5bfe\u8a71\u578b\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u7528\u3057\u3066\u89b3\u5bdf\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u4eca\u56de\u306f\u7d76\u5bfe\u8aa4\u5dee\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\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>\u8a2d\u5b9a\u3092\u4f7f\u7528\u3057\u3066\u7d76\u5bfe\u8aa4\u5dee\u306e\u5024\u3092 x \u8ef8\u3001\u5024\u306e\u30ab\u30a6\u30f3\u30c8\u3092 y \u8ef8\u3068\u3057\u3066\u30d2\u30b9\u30c8\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u307e\u3059\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. \u7570\u5e38\u306e\u3057\u304d\u3044\u5024\u3092\u6c7a\u5b9a\u3057\u3066\u53ef\u8996\u5316\u3059\u308b<\/strong><\/h4>\n<p>\u307b\u3068\u3093\u3069\u306e\u30dd\u30a4\u30f3\u30c8\u306b 6 \u672a\u6e80\u306e\u7d76\u5bfe\u8aa4\u5dee\u304c\u3042\u308b\u305f\u3081\u3001\u305d\u308c\u3092\u7570\u5e38\u306e\u3057\u304d\u3044\u5024\u3068\u3057\u3066\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 <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\">\u990a\u8702\u7bb1\u306e\u7570\u5e38\u3067\u884c\u3063\u305f<\/a>\u3088\u3046\u306b\u3001\u7570\u5e38\u306a\u30c7\u30fc\u30bf\u30dd\u30a4\u30f3\u30c8\u3092\u30b0\u30e9\u30d5\u306b\u30d7\u30ed\u30c3\u30c8\u3067\u304d\u307e\u3059\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=\"\u7570\u5e38\u306a\u30c7\u30fc\u30bf\u30dd\u30a4\u30f3\u30c8\u3092\u30b0\u30e9\u30d5\u306b\u30d7\u30ed\u30c3\u30c8\u3059\u308b\" width=\"1600\" height=\"963\" \/><\/figure>\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n<p>\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306f\u3001\u30d3\u30b8\u30cd\u30b9\u3084\u79d1\u5b66\u7814\u7a76\u306a\u3069\u306e\u591a\u6570\u306e\u7528\u9014\u3067\u4f7f\u7528\u3055\u308c\u308b\u30c7\u30fc\u30bf\u306e\u5171\u901a\u5f62\u5f0f\u3067\u3059\u3002 \u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u306e\u9023\u7d9a\u7684\u306a\u6027\u8cea\u306b\u3088\u308a\u3001\u30c7\u30fc\u30bf\u5185\u306e\u7570\u5e38\u3092\u5224\u5b9a\u3059\u308b\u305f\u3081\u306e\u7279\u6b8a\u306a\u624b\u6cd5\u3068\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u304c\u4f7f\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u3067\u306f\u3001STL \u5206\u89e3\u3092\u4f7f\u3063\u3066\u5b63\u7bc0\u6027\u3068\u30c8\u30ec\u30f3\u30c9\u3092\u9664\u53bb\u3059\u308b\u3053\u3068\u3067\u7570\u5e38\u3092\u767a\u898b\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002 \u307e\u305f\u3001\u30c7\u30a3\u30fc\u30d7\u30e9\u30fc\u30cb\u30f3\u30b0\u3068 LSTM \u30e2\u30c7\u30eb\u3092\u4f7f\u7528\u3057\u3066\u4e88\u6e2c\u3055\u308c\u305f\u63a8\u5b9a\u5024\u3068\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u3092\u6bd4\u8f03\u3059\u308b\u3053\u3068\u3067\u7570\u5e38\u3092\u5224\u65ad\u3059\u308b\u65b9\u6cd5\u3082\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2 class=\"wp-block-heading\">PyCharm \u306b\u3088\u308b\u7570\u5e38\u306e\u691c\u77e5<\/h2>\n<p>PyCharm Professional \u3067 Jupyter \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u591a\u6570\u306e\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u3068\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u3092\u4f7f\u3063\u3066\u7570\u5e38\u691c\u77e5\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u7c21\u5358\u306b\u6e96\u5099\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 PyCharm \u3067\u306f\u30b0\u30e9\u30d5\u51fa\u529b\u3092\u751f\u6210\u3057\u3066\u7570\u5e38\u3092\u691c\u67fb\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3001\u30d7\u30ed\u30c3\u30c8\u306b\u3082\u975e\u5e38\u306b\u7c21\u5358\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u3059\u3002 \u81ea\u52d5\u88dc\u5b8c\u306b\u3088\u308b\u63d0\u6848\u306a\u3069\u306e\u305d\u306e\u4ed6\u306e\u6a5f\u80fd\u3092\u4f7f\u7528\u3059\u308c\u3070\u3001Scikit-learn \u30e2\u30c7\u30eb\u3068 Matplotlib \u30d7\u30ed\u30c3\u30c8\u306e\u3059\u3079\u3066\u306e\u8a2d\u5b9a\u3082\u7c21\u5358\u306b\u64cd\u4f5c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>PyCharm \u3092\u4f7f\u7528\u3057\u3066\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30ec\u30d9\u30eb\u30a2\u30c3\u30d7\u3057\u307e\u3057\u3087\u3046\u3002\u307e\u305f\u3001\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u306e\u5408\u7406\u5316\u306b\u5f79\u7acb\u3064<a href=\"https:\/\/www.jetbrains.com\/ja-jp\/pycharm\/data-science\/\" target=\"_blank\" rel=\"noopener\">\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u6a5f\u80fd\u3092\u3054\u89a7\u304f\u3060\u3055\u3044<\/a>\u3002<\/p>\n<div class=\"buttons\">\n<div class=\"buttons__row\"><a class=\"btn\" href=\"https:\/\/www.jetbrains.com\/ja-jp\/pycharm\/data-science\/\" target=\"\" rel=\"noopener\">PyCharm Pro \u3092\u7121\u6599\u3067\u4f7f\u3044\u59cb\u3081\u308b<\/a><\/div>\n<\/div>\n\n\n<p><strong>\u30aa\u30ea\u30b8\u30ca\u30eb\uff08\u82f1\u8a9e\uff09\u30d6\u30ed\u30b0\u6295\u7a3f\u8a18\u4e8b\u306e\u4f5c\u8005\uff1a<\/strong><\/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":1394,"featured_media":568796,"comment_status":"closed","ping_status":"closed","template":"","categories":[952,1401],"tags":[8670],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/pycharm\/564415"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/pycharm"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/types\/pycharm"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/users\/1394"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/comments?post=564415"}],"version-history":[{"count":9,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/pycharm\/564415\/revisions"}],"predecessor-version":[{"id":568820,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/pycharm\/564415\/revisions\/568820"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/media\/568796"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/media?parent=564415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/categories?post=564415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/tags?post=564415"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/ja\/wp-json\/wp\/v2\/cross-post-tag?post=564415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}