{"id":973560,"date":"2024-12-27T05:57:57","date_gmt":"2024-12-26T21:57:57","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/973560.html"},"modified":"2024-12-27T05:57:59","modified_gmt":"2024-12-26T21:57:59","slug":"python%e6%97%b6%e9%97%b4%e5%ba%8f%e5%88%97%e5%a6%82%e4%bd%95%e6%8b%9f%e5%90%88","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/973560.html","title":{"rendered":"python\u65f6\u95f4\u5e8f\u5217\u5982\u4f55\u62df\u5408"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24195653\/f53bca10-28b5-42ed-a66d-966b52edd6e1.webp\" alt=\"python\u65f6\u95f4\u5e8f\u5217\u5982\u4f55\u62df\u5408\" \/><\/p>\n<p><p> <strong>Python\u65f6\u95f4\u5e8f\u5217\u62df\u5408\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528ARIMA\u6a21\u578b\u3001\u4f7f\u7528Prophet\u5e93\u3001\u4f7f\u7528LSTM\u795e\u7ecf\u7f51\u7edc\u3002<\/strong>\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0cARIMA\u6a21\u578b\u9002\u7528\u4e8e\u7ebf\u6027\u6570\u636e\u7684\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\uff0cProphet\u5e93\u7531Facebook\u5f00\u53d1\uff0c\u9002\u7528\u4e8e\u5177\u6709\u5b63\u8282\u6027\u8d8b\u52bf\u7684\u6570\u636e\uff0c\u800cLSTM\u795e\u7ecf\u7f51\u7edc\u5219\u9002\u7528\u4e8e\u5904\u7406\u66f4\u590d\u6742\u548c\u975e\u7ebf\u6027\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>ARIMA\u6a21\u578b\uff0c\u5373\u81ea\u56de\u5f52\u79ef\u5206\u6ed1\u52a8\u5e73\u5747\u6a21\u578b\uff0c\u662f\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u4e2d\u6700\u5e38\u7528\u7684\u6a21\u578b\u4e4b\u4e00\u3002\u5b83\u901a\u8fc7\u6355\u6349\u65f6\u95f4\u5e8f\u5217\u4e2d\u7684\u81ea\u76f8\u5173\u6027\u6765\u8fdb\u884c\u9884\u6d4b\u3002ARIMA\u6a21\u578b\u7684\u4f18\u70b9\u5728\u4e8e\u5176\u7b80\u5355\u6613\u7528\uff0c\u5e76\u4e14\u9002\u5408\u4e8e\u7ebf\u6027\u6570\u636e\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u975e\u7ebf\u6027\u6216\u590d\u6742\u6a21\u5f0f\u7684\u6570\u636e\uff0cARIMA\u6a21\u578b\u53ef\u80fd\u4e0d\u8db3\u4ee5\u63d0\u4f9b\u51c6\u786e\u7684\u9884\u6d4b\u3002<\/p>\n<\/p>\n<p><p>LSTM\uff08\u957f\u77ed\u671f\u8bb0\u5fc6\uff09\u795e\u7ecf\u7f51\u7edc\u662f\u4e00\u79cd\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u5e8f\u5217\u6570\u636e\u3002\u4e0e\u4f20\u7edf\u7684RNN\uff08\u9012\u5f52\u795e\u7ecf\u7f51\u7edc\uff09\u76f8\u6bd4\uff0cLSTM\u901a\u8fc7\u5f15\u5165\u8bb0\u5fc6\u5355\u5143\u548c\u95e8\u63a7\u673a\u5236\uff0c\u80fd\u591f\u66f4\u597d\u5730\u6355\u83b7\u957f\u671f\u4f9d\u8d56\u5173\u7cfb\uff0c\u4ece\u800c\u5728\u975e\u7ebf\u6027\u548c\u590d\u6742\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u4e0a\u63d0\u4f9b\u66f4\u597d\u7684\u9884\u6d4b\u6548\u679c\u3002<\/p>\n<\/p>\n<p><p>Prophet\u5e93\u662f\u7531Facebook\u5f00\u53d1\u7684\u4e00\u4e2a\u5f00\u6e90\u5de5\u5177\uff0c\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u5177\u6709\u5b63\u8282\u6027\u8d8b\u52bf\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002\u5b83\u53ef\u4ee5\u81ea\u52a8\u5904\u7406\u7f3a\u5931\u6570\u636e\u3001\u5f02\u5e38\u503c\uff0c\u5e76\u4e14\u652f\u6301\u591a\u4e2a\u5b63\u8282\u6027\u6210\u5206\u7684\u5efa\u6a21\uff0c\u975e\u5e38\u9002\u5408\u5546\u4e1a\u6570\u636e\u7684\u5206\u6790\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001ARIMA\u6a21\u578b<\/h3>\n<\/p>\n<p><p>ARIMA\u6a21\u578b\u662f\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u7684\u7ecf\u5178\u6a21\u578b\u4e4b\u4e00\uff0c\u5176\u5168\u79f0\u4e3a\u81ea\u56de\u5f52\u79ef\u5206\u6ed1\u52a8\u5e73\u5747\u6a21\u578b\u3002\u5b83\u7ed3\u5408\u4e86\u81ea\u56de\u5f52\uff08AR\uff09\u548c\u6ed1\u52a8\u5e73\u5747\uff08MA\uff09\u4e24\u79cd\u65b9\u6cd5\uff0c\u5e76\u901a\u8fc7\u5dee\u5206\uff08I\uff09\u6765\u5904\u7406\u975e\u5e73\u7a33\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002\u4e0b\u9762\u6211\u4eec\u6765\u8be6\u7ec6\u4e86\u89e3ARIMA\u6a21\u578b\u7684\u57fa\u672c\u539f\u7406\u548c\u5e94\u7528\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1. ARIMA\u6a21\u578b\u7684\u57fa\u672c\u539f\u7406<\/h4>\n<\/p>\n<p><p>ARIMA\u6a21\u578b\u7684\u57fa\u672c\u601d\u60f3\u662f\u901a\u8fc7\u5bf9\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u5dee\u5206\u64cd\u4f5c\uff0c\u4f7f\u5176\u6210\u4e3a\u5e73\u7a33\u5e8f\u5217\uff0c\u7136\u540e\u7528\u81ea\u56de\u5f52\u548c\u6ed1\u52a8\u5e73\u5747\u7684\u65b9\u6cd5\u8fdb\u884c\u5efa\u6a21\u3002ARIMA\u6a21\u578b\u53ef\u4ee5\u8868\u793a\u4e3aARIMA(p, d, q)\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>p<\/strong>\uff1a\u81ea\u56de\u5f52\u90e8\u5206\u7684\u9636\u6570\uff0c\u8868\u793a\u5f53\u524d\u503c\u4e0e\u524dp\u4e2a\u503c\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/li>\n<li><strong>d<\/strong>\uff1a\u5dee\u5206\u6b21\u6570\uff0c\u8868\u793a\u4e3a\u4e86\u4f7f\u5e8f\u5217\u5e73\u7a33\u6240\u9700\u7684\u5dee\u5206\u64cd\u4f5c\u6b21\u6570\u3002<\/li>\n<li><strong>q<\/strong>\uff1a\u6ed1\u52a8\u5e73\u5747\u90e8\u5206\u7684\u9636\u6570\uff0c\u8868\u793a\u5f53\u524d\u503c\u4e0e\u524dq\u4e2a\u8bef\u5dee\u9879\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/li>\n<\/ul>\n<p><p>ARIMA\u6a21\u578b\u7684\u6838\u5fc3\u5728\u4e8e\u9009\u62e9\u5408\u9002\u7684p\u3001d\u3001q\u53c2\u6570\uff0c\u8fd9\u901a\u5e38\u9700\u8981\u901a\u8fc7\u89c2\u5bdf\u81ea\u76f8\u5173\u51fd\u6570\uff08ACF\uff09\u548c\u504f\u81ea\u76f8\u5173\u51fd\u6570\uff08PACF\uff09\u56fe\u6765\u8fdb\u884c\u3002<\/p>\n<\/p>\n<p><h4>2. ARIMA\u6a21\u578b\u7684\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0cARIMA\u6a21\u578b\u7684\u5b9e\u73b0\u53ef\u4ee5\u901a\u8fc7statsmodels\u5e93\u6765\u5b8c\u6210\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684ARIMA\u6a21\u578b\u5e94\u7528\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from statsmodels.tsa.arima.model import ARIMA<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u52a0\u8f7d\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;your_time_series_data.csv&#39;, parse_dates=[&#39;date&#39;], index_col=&#39;date&#39;)<\/p>\n<p>time_series = data[&#39;value&#39;]<\/p>\n<h2><strong>\u62c6\u5206\u6570\u636e\u96c6\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/strong><\/h2>\n<p>tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n = time_series[:int(len(time_series)*0.8)]<\/p>\n<p>test = time_series[int(len(time_series)*0.8):]<\/p>\n<h2><strong>\u62df\u5408ARIMA\u6a21\u578b<\/strong><\/h2>\n<p>model = ARIMA(train, order=(p, d, q))<\/p>\n<p>model_fit = model.fit()<\/p>\n<h2><strong>\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>predictions = model_fit.forecast(steps=len(test))<\/p>\n<h2><strong>\u7ed8\u5236\u5b9e\u9645\u503c\u548c\u9884\u6d4b\u503c\u7684\u5bf9\u6bd4\u56fe<\/strong><\/h2>\n<p>plt.plot(test.index, test.values, label=&#39;Actual&#39;)<\/p>\n<p>plt.plot(test.index, predictions, label=&#39;Predicted&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4ee5\u4e0a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u52a0\u8f7d\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5e76\u62c6\u5206\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528ARIMA\u6a21\u578b\u8fdb\u884c\u62df\u5408\uff0c\u5e76\u8fdb\u884c\u9884\u6d4b\u3002\u6700\u540e\uff0c\u901a\u8fc7\u7ed8\u56fe\u5bf9\u6bd4\u5b9e\u9645\u503c\u548c\u9884\u6d4b\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001Prophet\u5e93<\/h3>\n<\/p>\n<p><p>Prophet\u662f\u7531Facebook\u5f00\u53d1\u7684\u4e00\u6b3e\u7528\u4e8e\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u7684\u5f00\u6e90\u5de5\u5177\uff0c\u975e\u5e38\u9002\u5408\u5904\u7406\u5177\u6709\u5b63\u8282\u6027\u8d8b\u52bf\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002Prophet\u7684\u4f18\u70b9\u5728\u4e8e\u5176\u6613\u7528\u6027\u548c\u9ad8\u6548\u6027\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u6709\u8282\u5047\u65e5\u6548\u5e94\u6216\u975e\u7ebf\u6027\u8d8b\u52bf\u7684\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h4>1. Prophet\u7684\u57fa\u672c\u539f\u7406<\/h4>\n<\/p>\n<p><p>Prophet\u6a21\u578b\u5c06\u65f6\u95f4\u5e8f\u5217\u5206\u89e3\u4e3a\u4e09\u4e2a\u4e3b\u8981\u6210\u5206\uff1a\u8d8b\u52bf\u3001\u5b63\u8282\u6027\u548c\u5047\u65e5\u6548\u5e94\u3002\u8d8b\u52bf\u90e8\u5206\u63cf\u8ff0\u6570\u636e\u7684\u957f\u671f\u53d8\u5316\uff0c\u5b63\u8282\u6027\u90e8\u5206\u63cf\u8ff0\u6570\u636e\u7684\u5468\u671f\u6027\u53d8\u5316\uff0c\u800c\u5047\u65e5\u6548\u5e94\u90e8\u5206\u5219\u7528\u6765\u6355\u6349\u7279\u6b8a\u65e5\u671f\u7684\u5f71\u54cd\u3002Prophet\u901a\u8fc7\u52a0\u6cd5\u6a21\u578b\u5c06\u8fd9\u4e09\u4e2a\u6210\u5206\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u4ece\u800c\u5b9e\u73b0\u5bf9\u65f6\u95f4\u5e8f\u5217\u7684\u9884\u6d4b\u3002<\/p>\n<\/p>\n<p><h4>2. Prophet\u7684\u5e94\u7528<\/h4>\n<\/p>\n<p><p>Prophet\u5e93\u7684\u4f7f\u7528\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u51e0\u884c\u4ee3\u7801\u5373\u53ef\u5b8c\u6210\u5efa\u6a21\u548c\u9884\u6d4b\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684Prophet\u5e94\u7528\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from fbprophet import Prophet<\/p>\n<p>import pandas as pd<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u52a0\u8f7d\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;your_time_series_data.csv&#39;)<\/p>\n<p>data.columns = [&#39;ds&#39;, &#39;y&#39;]  # Prophet\u9700\u8981\u7684\u5217\u540d\u683c\u5f0f<\/p>\n<h2><strong>\u521b\u5efaProphet\u6a21\u578b\u5e76\u62df\u5408\u6570\u636e<\/strong><\/h2>\n<p>model = Prophet()<\/p>\n<p>model.fit(data)<\/p>\n<h2><strong>\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>future = model.make_future_dataframe(periods=365)<\/p>\n<p>forecast = model.predict(future)<\/p>\n<h2><strong>\u7ed8\u5236\u9884\u6d4b\u7ed3\u679c<\/strong><\/h2>\n<p>model.plot(forecast)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4ee5\u4e0a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u52a0\u8f7d\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u5e76\u5c06\u6570\u636e\u683c\u5f0f\u8c03\u6574\u4e3aProphet\u6240\u9700\u7684\u683c\u5f0f\u3002\u7136\u540e\uff0c\u6211\u4eec\u521b\u5efaProphet\u6a21\u578b\u5e76\u8fdb\u884c\u62df\u5408\u3002\u6700\u540e\uff0c\u901a\u8fc7\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\uff0c\u5e76\u7ed8\u5236\u9884\u6d4b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001LSTM\u795e\u7ecf\u7f51\u7edc<\/h3>\n<\/p>\n<p><p>LSTM\uff08\u957f\u77ed\u671f\u8bb0\u5fc6\uff09\u795e\u7ecf\u7f51\u7edc\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u9012\u5f52\u795e\u7ecf\u7f51\u7edc\uff0c\u80fd\u591f\u6709\u6548\u6355\u83b7\u65f6\u95f4\u5e8f\u5217\u4e2d\u7684\u957f\u671f\u4f9d\u8d56\u5173\u7cfb\u3002LSTM\u7f51\u7edc\u901a\u8fc7\u5f15\u5165\u8bb0\u5fc6\u5355\u5143\u548c\u95e8\u63a7\u673a\u5236\uff0c\u53ef\u4ee5\u5728\u5904\u7406\u590d\u6742\u548c\u975e\u7ebf\u6027\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u65f6\u53d6\u5f97\u826f\u597d\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<p><h4>1. LSTM\u7684\u57fa\u672c\u539f\u7406<\/h4>\n<\/p>\n<p><p>LSTM\u7f51\u7edc\u7684\u6838\u5fc3\u5728\u4e8e\u5176\u72ec\u7279\u7684\u7ed3\u6784\uff0c\u5305\u62ec\u8f93\u5165\u95e8\u3001\u9057\u5fd8\u95e8\u548c\u8f93\u51fa\u95e8\u3002\u8fd9\u4e9b\u95e8\u63a7\u673a\u5236\u5141\u8bb8LSTM\u7f51\u7edc\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u9009\u62e9\u6027\u5730\u8bb0\u4f4f\u6216\u9057\u5fd8\u4fe1\u606f\uff0c\u4ece\u800c\u6709\u6548\u5730\u6355\u83b7\u957f\u671f\u4f9d\u8d56\u5173\u7cfb\u3002\u4e0e\u4f20\u7edf\u7684RNN\u4e0d\u540c\uff0cLSTM\u80fd\u591f\u907f\u514d\u68af\u5ea6\u6d88\u5931\u95ee\u9898\uff0c\u56e0\u6b64\u5728\u5904\u7406\u957f\u5e8f\u5217\u6570\u636e\u65f6\u8868\u73b0\u66f4\u4f73\u3002<\/p>\n<\/p>\n<p><h4>2. LSTM\u7684\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0cLSTM\u7f51\u7edc\u7684\u5b9e\u73b0\u901a\u5e38\u4f9d\u8d56\u4e8e\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u5982TensorFlow\u6216Keras\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684LSTM\u6a21\u578b\u5e94\u7528\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import pandas as pd<\/p>\n<p>from sklearn.preprocessing import MinMaxScaler<\/p>\n<p>from keras.models import Sequential<\/p>\n<p>from keras.layers import LSTM, Dense<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u52a0\u8f7d\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;your_time_series_data.csv&#39;)<\/p>\n<p>values = data[&#39;value&#39;].values.reshape(-1, 1)<\/p>\n<h2><strong>\u5f52\u4e00\u5316\u6570\u636e<\/strong><\/h2>\n<p>scaler = MinMaxScaler(feature_range=(0, 1))<\/p>\n<p>scaled_values = scaler.fit_transform(values)<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u96c6<\/strong><\/h2>\n<p>def create_dataset(dataset, time_step=1):<\/p>\n<p>    dataX, dataY = [], []<\/p>\n<p>    for i in range(len(dataset)-time_step-1):<\/p>\n<p>        a = dataset[i:(i+time_step), 0]<\/p>\n<p>        dataX.append(a)<\/p>\n<p>        dataY.append(dataset[i + time_step, 0])<\/p>\n<p>    return np.array(dataX), np.array(dataY)<\/p>\n<p>time_step = 10<\/p>\n<p>X, y = create_dataset(scaled_values, time_step)<\/p>\n<h2><strong>\u62c6\u5206\u6570\u636e\u96c6\u4e3a\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6<\/strong><\/h2>\n<p>train_size = int(len(X) * 0.8)<\/p>\n<p>trainX, testX = X[:train_size], X[train_size:]<\/p>\n<p>trainY, testY = y[:train_size], y[train_size:]<\/p>\n<h2><strong>\u91cd\u5851\u8f93\u5165\u6570\u636e\u683c\u5f0f\u4e3a [\u6837\u672c, \u65f6\u95f4\u6b65, \u7279\u5f81]<\/strong><\/h2>\n<p>trainX = trainX.reshape(trainX.shape[0], trainX.shape[1], 1)<\/p>\n<p>testX = testX.reshape(testX.shape[0], testX.shape[1], 1)<\/p>\n<h2><strong>\u521b\u5efaLSTM\u6a21\u578b<\/strong><\/h2>\n<p>model = Sequential()<\/p>\n<p>model.add(LSTM(50, return_sequences=True, input_shape=(time_step, 1)))<\/p>\n<p>model.add(LSTM(50, return_sequences=False))<\/p>\n<p>model.add(Dense(1))<\/p>\n<p>model.compile(optimizer=&#39;adam&#39;, loss=&#39;mean_squared_error&#39;)<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(trainX, trainY, epochs=100, batch_size=64, verbose=1)<\/p>\n<h2><strong>\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>trainPredict = model.predict(trainX)<\/p>\n<p>testPredict = model.predict(testX)<\/p>\n<h2><strong>\u53cd\u5f52\u4e00\u5316\u6570\u636e<\/strong><\/h2>\n<p>trainPredict = scaler.inverse_transform(trainPredict)<\/p>\n<p>testPredict = scaler.inverse_transform(testPredict)<\/p>\n<p>trainY = scaler.inverse_transform([trainY])<\/p>\n<p>testY = scaler.inverse_transform([testY])<\/p>\n<h2><strong>\u7ed8\u5236\u9884\u6d4b\u7ed3\u679c<\/strong><\/h2>\n<p>plt.plot(data.index, values, label=&#39;Actual&#39;)<\/p>\n<p>plt.plot(data.index[time_step:len(trainPredict)+time_step], trainPredict, label=&#39;Train Prediction&#39;)<\/p>\n<p>plt.plot(data.index[len(trainPredict)+(time_step*2):len(data)-1], testPredict, label=&#39;Test Prediction&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4ee5\u4e0a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u52a0\u8f7d\u548c\u5f52\u4e00\u5316\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u7136\u540e\u521b\u5efaLSTM\u6a21\u578b\u5e76\u8fdb\u884c\u8bad\u7ec3\u3002\u6700\u540e\uff0c\u901a\u8fc7\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\uff0c\u5e76\u7ed8\u5236\u9884\u6d4b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u6bd4\u8f83\u4e0e\u9009\u62e9<\/h3>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u5408\u9002\u7684\u65f6\u95f4\u5e8f\u5217\u62df\u5408\u65b9\u6cd5\u65f6\uff0c\u9700\u8981\u8003\u8651\u6570\u636e\u7684\u7279\u6027\u548c\u5177\u4f53\u9700\u6c42\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>ARIMA\u6a21\u578b<\/strong>\uff1a\u9002\u7528\u4e8e\u7ebf\u6027\u548c\u975e\u5b63\u8282\u6027\u65f6\u95f4\u5e8f\u5217\u3002\u5982\u679c\u6570\u636e\u8868\u73b0\u51fa\u5f3a\u70c8\u7684\u7ebf\u6027\u8d8b\u52bf\u4e14\u6ca1\u6709\u660e\u663e\u7684\u5b63\u8282\u6027\uff0cARIMA\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/li>\n<li><strong>Prophet\u5e93<\/strong>\uff1a\u9002\u7528\u4e8e\u5177\u6709\u5b63\u8282\u6027\u8d8b\u52bf\u7684\u6570\u636e\u3002Prophet\u80fd\u591f\u81ea\u52a8\u5904\u7406\u7f3a\u5931\u503c\u548c\u5f02\u5e38\u503c\uff0c\u5e76\u652f\u6301\u591a\u79cd\u5b63\u8282\u6027\u6210\u5206\uff0c\u662f\u5904\u7406\u5546\u4e1a\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7684\u7406\u60f3\u5de5\u5177\u3002<\/li>\n<li><strong>LSTM\u795e\u7ecf\u7f51\u7edc<\/strong>\uff1a\u9002\u7528\u4e8e\u590d\u6742\u548c\u975e\u7ebf\u6027\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002LSTM\u5728\u6355\u83b7\u957f\u671f\u4f9d\u8d56\u5173\u7cfb\u548c\u5904\u7406\u975e\u7ebf\u6027\u6a21\u5f0f\u65b9\u9762\u5177\u6709\u4f18\u52bf\uff0c\u7279\u522b\u662f\u5f53\u6570\u636e\u5177\u6709\u590d\u6742\u52a8\u6001\u65f6\u3002<\/li>\n<\/ul>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u6570\u636e\u7279\u6027\u548c\u8ba1\u7b97\u8d44\u6e90\uff0c\u9009\u62e9\u4e00\u79cd\u6216\u591a\u79cd\u65b9\u6cd5\u8fdb\u884c\u6bd4\u8f83\uff0c\u6700\u7ec8\u9009\u51fa\u6700\u80fd\u6ee1\u8db3\u9700\u6c42\u7684\u6a21\u578b\u3002\u901a\u8fc7\u5bf9\u6bd4\u6a21\u578b\u7684\u9884\u6d4b\u7cbe\u5ea6\u548c\u8ba1\u7b97\u6548\u7387\uff0c\u627e\u5230\u6700\u4f18\u7684\u65f6\u95f4\u5e8f\u5217\u62df\u5408\u65b9\u6848\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u6a21\u578b\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u62df\u5408\uff1f<\/strong><br \/>\u5728\u8fdb\u884c\u65f6\u95f4\u5e8f\u5217\u62df\u5408\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u6a21\u578b\u81f3\u5173\u91cd\u8981\u3002\u5e38\u7528\u7684\u6a21\u578b\u5305\u62ec\u81ea\u56de\u5f52\u6a21\u578b\uff08AR\uff09\u3001\u79fb\u52a8\u5e73\u5747\u6a21\u578b\uff08MA\uff09\u3001\u81ea\u56de\u5f52\u6ed1\u52a8\u5e73\u5747\u6a21\u578b\uff08ARMA\uff09\u3001\u81ea\u56de\u5f52\u79ef\u5206\u6ed1\u52a8\u5e73\u5747\u6a21\u578b\uff08ARIMA\uff09\u4ee5\u53ca\u5b63\u8282\u6027ARIMA\uff08SARIMA\uff09\u3002\u5728\u9009\u62e9\u6a21\u578b\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ed8\u5236\u81ea\u76f8\u5173\u51fd\u6570\uff08ACF\uff09\u548c\u504f\u81ea\u76f8\u5173\u51fd\u6570\uff08PACF\uff09\u56fe\u6765\u5206\u6790\u6570\u636e\u7684\u7279\u6027\uff0c\u4ee5\u6b64\u51b3\u5b9a\u4f7f\u7528\u54ea\u79cd\u6a21\u578b\u3002\u6b64\u5916\uff0c\u6a21\u578b\u7684\u4f18\u52a3\u53ef\u4ee5\u901a\u8fc7AIC\uff08\u8d64\u6c60\u4fe1\u606f\u91cf\u51c6\u5219\uff09\u548cBIC\uff08\u8d1d\u53f6\u65af\u4fe1\u606f\u91cf\u51c6\u5219\uff09\u7b49\u6307\u6807\u8fdb\u884c\u8bc4\u4f30\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u4e2d\u7684\u7f3a\u5931\u503c\uff1f<\/strong><br \/>\u7f3a\u5931\u503c\u5728\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u4e2d\u975e\u5e38\u5e38\u89c1\uff0c\u5904\u7406\u7f3a\u5931\u503c\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u3002\u53ef\u4ee5\u4f7f\u7528\u63d2\u503c\u6cd5\uff0c\u5982\u7ebf\u6027\u63d2\u503c\u3001\u6837\u6761\u63d2\u503c\u7b49\uff0c\u6765\u586b\u8865\u7f3a\u5931\u503c\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u524d\u540e\u503c\u7684\u5e73\u5747\u6570\u8fdb\u884c\u586b\u8865\u4e5f\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u5f0f\u3002\u5bf9\u4e8e\u7f3a\u5931\u503c\u8f83\u591a\u7684\u65f6\u95f4\u5e8f\u5217\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\u586b\u8865\uff0c\u5982\u4f7f\u7528ARIMA\u6a21\u578b\u9884\u6d4b\u7f3a\u5931\u65f6\u95f4\u70b9\u7684\u503c\u3002\u786e\u4fdd\u5728\u5904\u7406\u7f3a\u5931\u503c\u65f6\uff0c\u5c3d\u91cf\u4fdd\u7559\u6570\u636e\u7684\u7279\u6027\uff0c\u907f\u514d\u5f15\u5165\u504f\u5dee\u3002<\/p>\n<p><strong>\u5982\u4f55\u8bc4\u4f30\u65f6\u95f4\u5e8f\u5217\u62df\u5408\u7684\u6548\u679c\uff1f<\/strong><br \/>\u8bc4\u4f30\u65f6\u95f4\u5e8f\u5217\u62df\u5408\u6548\u679c\u7684\u65b9\u6cd5\u6709\u591a\u79cd\u3002\u5e38\u7528\u7684\u8bc4\u4f30\u6307\u6807\u5305\u62ec\u5747\u65b9\u8bef\u5dee\uff08MSE\uff09\u3001\u5747\u65b9\u6839\u8bef\u5dee\uff08RMSE\uff09\u3001\u5e73\u5747\u7edd\u5bf9\u8bef\u5dee\uff08MAE\uff09\u7b49\u3002\u8fd9\u4e9b\u6307\u6807\u53ef\u4ee5\u5e2e\u52a9\u5224\u65ad\u6a21\u578b\u7684\u9884\u6d4b\u7cbe\u5ea6\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u901a\u8fc7\u53ef\u89c6\u5316\u62df\u5408\u7ed3\u679c\u4e0e\u5b9e\u9645\u6570\u636e\u7684\u5bf9\u6bd4\u56fe\uff0c\u76f4\u89c2\u5c55\u793a\u6a21\u578b\u7684\u62df\u5408\u6548\u679c\u3002\u82e5\u6a21\u578b\u5b58\u5728\u8fc7\u62df\u5408\u73b0\u8c61\uff0c\u53ef\u80fd\u5728\u8bad\u7ec3\u96c6\u4e0a\u8868\u73b0\u826f\u597d\uff0c\u4f46\u5728\u9a8c\u8bc1\u96c6\u6216\u6d4b\u8bd5\u96c6\u4e0a\u7684\u8868\u73b0\u5374\u4e0d\u7406\u60f3\uff0c\u56e0\u6b64\uff0c\u4ea4\u53c9\u9a8c\u8bc1\u4e5f\u662f\u4e00\u79cd\u6709\u6548\u7684\u8bc4\u4f30\u65b9\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u65f6\u95f4\u5e8f\u5217\u62df\u5408\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528ARIMA\u6a21\u578b\u3001\u4f7f\u7528Prophet\u5e93\u3001\u4f7f\u7528LSTM\u795e\u7ecf\u7f51\u7edc\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5 [&hellip;]","protected":false},"author":3,"featured_media":973564,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/973560"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=973560"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/973560\/revisions"}],"predecessor-version":[{"id":973565,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/973560\/revisions\/973565"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/973564"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=973560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=973560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=973560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}