{"id":1042522,"date":"2024-12-31T12:58:11","date_gmt":"2024-12-31T04:58:11","guid":{"rendered":""},"modified":"2024-12-31T12:58:14","modified_gmt":"2024-12-31T04:58:14","slug":"python%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90%e6%97%b6%e9%97%b4%e5%ba%8f%e5%88%97%e6%9c%aa%e6%9d%a5%e9%a2%84%e6%b5%8b%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1042522.html","title":{"rendered":"python\u5982\u4f55\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u672a\u6765\u9884\u6d4b\u8868"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/6d4429b9-1ca5-40f5-b7aa-da88e16e2649.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python\u5982\u4f55\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u672a\u6765\u9884\u6d4b\u8868\" \/><\/p>\n<p><p> <strong>\u5f00\u5934\u6bb5\u843d:<\/strong><\/p>\n<\/p>\n<p><p><strong>Python\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u672a\u6765\u9884\u6d4b\u8868\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528ARIMA\u6a21\u578b\u3001Prophet\u6a21\u578b\u3001LSTM\u6a21\u578b\u3001SARIMA\u6a21\u578b<\/strong>\u3002\u5176\u4e2d\uff0cARIMA\u6a21\u578b\u662f\u7ecf\u5178\u7684\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u65b9\u6cd5\u4e4b\u4e00\uff0c\u9002\u7528\u4e8e\u5355\u53d8\u91cf\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002Prophet\u6a21\u578b\u662f\u7531Facebook\u5f00\u53d1\u7684\u4e00\u79cd\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u5de5\u5177\uff0c\u80fd\u591f\u5904\u7406\u7f3a\u5931\u6570\u636e\u548c\u5f02\u5e38\u503c\u3002LSTM\u6a21\u578b\u662f\u4e00\u79cd\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\uff0c\u64c5\u957f\u5904\u7406\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u80fd\u591f\u6355\u6349\u5230\u957f\u65f6\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u3002SARIMA\u6a21\u578b\u662f\u5728ARIMA\u6a21\u578b\u57fa\u7840\u4e0a\u589e\u52a0\u4e86\u5b63\u8282\u6027\u56e0\u7d20\u7684\u8003\u8651\uff0c\u9002\u7528\u4e8e\u5177\u6709\u5b63\u8282\u6027\u6ce2\u52a8\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u6a21\u578b\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u672a\u6765\u9884\u6d4b\u8868\u3002<\/p>\n<\/p>\n<p><p><strong>\u4e00\u3001ARIMA\u6a21\u578b<\/strong><\/p>\n<\/p>\n<p><p>ARIMA\uff08AutoRegressive Integrated Moving Average\uff09\u6a21\u578b\u662f\u4e00\u79cd\u7ecf\u5178\u7684\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u65b9\u6cd5\u3002\u5b83\u901a\u8fc7\u7ed3\u5408\u81ea\u56de\u5f52\uff08AR\uff09\u548c\u79fb\u52a8\u5e73\u5747\uff08MA\uff09\u4e24\u4e2a\u8fc7\u7a0b\u6765\u5bf9\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u8fdb\u884c\u5efa\u6a21\uff0c\u5e76\u901a\u8fc7\u5dee\u5206\uff08I\uff09\u6765\u4f7f\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u5e73\u7a33\u3002ARIMA\u6a21\u578b\u5728\u5f88\u591a\u573a\u666f\u4e0b\u90fd\u8868\u73b0\u51fa\u8272\uff0c\u5c24\u5176\u662f\u5355\u53d8\u91cf\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>1.1 \u6570\u636e\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528ARIMA\u6a21\u578b\u4e4b\u524d\uff0c\u9700\u8981\u5bf9\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\u3002\u9996\u5148\u9700\u8981\u786e\u4fdd\u6570\u636e\u662f\u5e73\u7a33\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528ADF\uff08Augmented Dickey-Fuller\uff09\u68c0\u9a8c\u6765\u5224\u65ad\u3002\u5982\u679c\u6570\u636e\u4e0d\u5e73\u7a33\uff0c\u53ef\u4ee5\u901a\u8fc7\u5dee\u5206\u7684\u65b9\u6cd5\u4f7f\u5176\u5e73\u7a33\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from statsmodels.tsa.stattools import adfuller<\/p>\n<h2><strong>\u8bfb\u53d6\u65f6\u95f4\u5e8f\u5217\u6570\u636e<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;timeseries_data.csv&#39;, index_col=&#39;date&#39;, parse_dates=True)<\/p>\n<h2><strong>ADF\u68c0\u9a8c<\/strong><\/h2>\n<p>result = adfuller(data[&#39;value&#39;])<\/p>\n<p>print(&#39;ADF Statistic:&#39;, result[0])<\/p>\n<p>print(&#39;p-value:&#39;, result[1])<\/p>\n<h2><strong>\u5982\u679c\u6570\u636e\u4e0d\u5e73\u7a33\uff0c\u5219\u8fdb\u884c\u5dee\u5206<\/strong><\/h2>\n<p>if result[1] &gt; 0.05:<\/p>\n<p>    data[&#39;value_diff&#39;] = data[&#39;value&#39;].diff().dropna()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>1.2 \u6a21\u578b\u62df\u5408<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u9884\u5904\u7406\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528ARIMA\u6a21\u578b\u8fdb\u884c\u62df\u5408\u3002\u9700\u8981\u786e\u5b9aARIMA\u6a21\u578b\u7684\u4e09\u4e2a\u53c2\u6570\uff1ap\uff08\u81ea\u56de\u5f52\u9636\u6570\uff09\u3001d\uff08\u5dee\u5206\u9636\u6570\uff09\u548cq\uff08\u79fb\u52a8\u5e73\u5747\u9636\u6570\uff09\u3002\u53ef\u4ee5\u4f7f\u7528<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>C\uff08Akaike Information Criterion\uff09\u6216\u8005BIC\uff08Bayesian Information Criterion\uff09\u6765\u9009\u62e9\u6700\u4f18\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from statsmodels.tsa.arima.model import ARIMA<\/p>\n<h2><strong>\u786e\u5b9aARIMA\u6a21\u578b\u53c2\u6570<\/strong><\/h2>\n<p>p, d, q = 1, 1, 1  # \u793a\u4f8b\u53c2\u6570<\/p>\n<h2><strong>\u62df\u5408ARIMA\u6a21\u578b<\/strong><\/h2>\n<p>model = ARIMA(data[&#39;value_diff&#39;].dropna(), order=(p, d, q))<\/p>\n<p>model_fit = model.fit()<\/p>\n<h2><strong>\u6253\u5370\u6a21\u578b\u6458\u8981<\/strong><\/h2>\n<p>print(model_fit.summary())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>1.3 \u751f\u6210\u9884\u6d4b\u8868<\/h3>\n<\/p>\n<p><p>\u62df\u5408\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\uff0c\u5e76\u751f\u6210\u672a\u6765\u7684\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9884\u6d4b\u672a\u6765\u65f6\u95f4\u5e8f\u5217<\/p>\n<p>forecast = model_fit.forecast(steps=12)  # \u9884\u6d4b\u672a\u676512\u4e2a\u65f6\u95f4\u70b9<\/p>\n<h2><strong>\u751f\u6210\u9884\u6d4b\u8868<\/strong><\/h2>\n<p>forecast_df = pd.DataFrame(forecast, columns=[&#39;forecast&#39;])<\/p>\n<p>forecast_df.index = pd.date_range(start=data.index[-1], periods=12, freq=&#39;M&#39;)<\/p>\n<p>print(forecast_df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e8c\u3001Prophet\u6a21\u578b<\/strong><\/p>\n<\/p>\n<p><p>Prophet\u6a21\u578b\u662f\u7531Facebook\u5f00\u53d1\u7684\u4e00\u79cd\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u5de5\u5177\uff0c\u80fd\u591f\u5904\u7406\u7f3a\u5931\u6570\u636e\u548c\u5f02\u5e38\u503c\uff0c\u4e14\u5bf9\u5b63\u8282\u6027\u6ce2\u52a8\u6709\u5f88\u597d\u7684\u5904\u7406\u80fd\u529b\u3002Prophet\u6a21\u578b\u4f7f\u7528\u7b80\u5355\u4e14\u6548\u679c\u663e\u8457\uff0c\u975e\u5e38\u9002\u5408\u4e1a\u52a1\u51b3\u7b56\u4e2d\u7684\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u3002<\/p>\n<\/p>\n<p><h3>2.1 \u6570\u636e\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>Prophet\u6a21\u578b\u8981\u6c42\u8f93\u5165\u7684\u6570\u636e\u6846\u4e2d\u5305\u542b\u4e24\u5217\uff1a\u65e5\u671f\u5217\uff08ds\uff09\u548c\u6570\u503c\u5217\uff08y\uff09\u3002\u56e0\u6b64\uff0c\u9700\u8981\u5c06\u539f\u59cb\u6570\u636e\u8f6c\u6362\u4e3aProphet\u6a21\u578b\u6240\u9700\u7684\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from fbprophet import Prophet<\/p>\n<h2><strong>\u8f6c\u6362\u6570\u636e\u683c\u5f0f<\/strong><\/h2>\n<p>prophet_data = data.reset_index()<\/p>\n<p>prophet_data.columns = [&#39;ds&#39;, &#39;y&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.2 \u6a21\u578b\u62df\u5408<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u9884\u5904\u7406\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528Prophet\u6a21\u578b\u8fdb\u884c\u62df\u5408\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efaProphet\u6a21\u578b<\/p>\n<p>model = Prophet()<\/p>\n<h2><strong>\u62df\u5408\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(prophet_data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.3 \u751f\u6210\u9884\u6d4b\u8868<\/h3>\n<\/p>\n<p><p>\u62df\u5408\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\uff0c\u5e76\u751f\u6210\u672a\u6765\u7684\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u672a\u6765\u6570\u636e\u6846<\/p>\n<p>future = model.make_future_dataframe(periods=12, freq=&#39;M&#39;)<\/p>\n<h2><strong>\u9884\u6d4b\u672a\u6765\u65f6\u95f4\u5e8f\u5217<\/strong><\/h2>\n<p>forecast = model.predict(future)<\/p>\n<h2><strong>\u751f\u6210\u9884\u6d4b\u8868<\/strong><\/h2>\n<p>forecast[[&#39;ds&#39;, &#39;yhat&#39;, &#39;yhat_lower&#39;, &#39;yhat_upper&#39;]].tail(12)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u4e09\u3001LSTM\u6a21\u578b<\/strong><\/p>\n<\/p>\n<p><p>LSTM\uff08Long Short-Term Memory\uff09\u6a21\u578b\u662f\u4e00\u79cd\u7279\u6b8a\u7684RNN\uff08Recurrent Neural Network\uff09\uff0c\u64c5\u957f\u5904\u7406\u65f6\u95f4\u5e8f\u5217\u6570\u636e\uff0c\u80fd\u591f\u6355\u6349\u5230\u957f\u65f6\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u3002LSTM\u6a21\u578b\u5728\u5904\u7406\u590d\u6742\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u65f6\u8868\u73b0\u4f18\u5f02\u3002<\/p>\n<\/p>\n<p><h3>3.1 \u6570\u636e\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528LSTM\u6a21\u578b\u4e4b\u524d\uff0c\u9700\u8981\u5bf9\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\u3002\u5305\u62ec\u6570\u636e\u5f52\u4e00\u5316\u548c\u521b\u5efa\u8bad\u7ec3\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>from sklearn.preprocessing import MinMaxScaler<\/p>\n<h2><strong>\u5f52\u4e00\u5316\u6570\u636e<\/strong><\/h2>\n<p>scaler = MinMaxScaler(feature_range=(0, 1))<\/p>\n<p>scaled_data = scaler.fit_transform(data[&#39;value&#39;].values.reshape(-1, 1))<\/p>\n<h2><strong>\u521b\u5efa\u8bad\u7ec3\u6570\u636e\u96c6<\/strong><\/h2>\n<p>def create_dataset(dataset, look_back=1):<\/p>\n<p>    X, Y = [], []<\/p>\n<p>    for i in range(len(dataset)-look_back-1):<\/p>\n<p>        a = dataset[i:(i+look_back), 0]<\/p>\n<p>        X.append(a)<\/p>\n<p>        Y.append(dataset[i + look_back, 0])<\/p>\n<p>    return np.array(X), np.array(Y)<\/p>\n<p>look_back = 3  # \u89c2\u5bdf\u7a97\u53e3\u5927\u5c0f<\/p>\n<p>X, Y = create_dataset(scaled_data, look_back)<\/p>\n<p>X = np.reshape(X, (X.shape[0], X.shape[1], 1))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.2 \u6a21\u578b\u6784\u5efa\u4e0e\u8bad\u7ec3<\/h3>\n<\/p>\n<p><p>\u6784\u5efaLSTM\u6a21\u578b\u5e76\u8fdb\u884c\u8bad\u7ec3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from keras.models import Sequential<\/p>\n<p>from keras.layers import Dense, LSTM<\/p>\n<h2><strong>\u6784\u5efaLSTM\u6a21\u578b<\/strong><\/h2>\n<p>model = Sequential()<\/p>\n<p>model.add(LSTM(50, return_sequences=True, input_shape=(look_back, 1)))<\/p>\n<p>model.add(LSTM(50))<\/p>\n<p>model.add(Dense(1))<\/p>\n<p>model.compile(loss=&#39;mean_squared_error&#39;, optimizer=&#39;adam&#39;)<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(X, Y, epochs=100, batch_size=1, verbose=2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.3 \u751f\u6210\u9884\u6d4b\u8868<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u8bad\u7ec3\u597d\u7684LSTM\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\uff0c\u5e76\u751f\u6210\u672a\u6765\u7684\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9884\u6d4b\u672a\u6765\u65f6\u95f4\u5e8f\u5217<\/p>\n<p>future_data = scaled_data[-look_back:]<\/p>\n<p>future_data = np.reshape(future_data, (1, look_back, 1))<\/p>\n<p>predictions = []<\/p>\n<p>for i in range(12):  # \u9884\u6d4b\u672a\u676512\u4e2a\u65f6\u95f4\u70b9<\/p>\n<p>    prediction = model.predict(future_data)<\/p>\n<p>    predictions.append(prediction[0][0])<\/p>\n<p>    future_data = np.append(future_data[:, 1:, :], [[prediction]], axis=1)<\/p>\n<h2><strong>\u53cd\u5f52\u4e00\u5316\u9884\u6d4b\u503c<\/strong><\/h2>\n<p>predictions = scaler.inverse_transform(np.array(predictions).reshape(-1, 1))<\/p>\n<h2><strong>\u751f\u6210\u9884\u6d4b\u8868<\/strong><\/h2>\n<p>forecast_df = pd.DataFrame(predictions, columns=[&#39;forecast&#39;])<\/p>\n<p>forecast_df.index = pd.date_range(start=data.index[-1], periods=12, freq=&#39;M&#39;)<\/p>\n<p>print(forecast_df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u56db\u3001SARIMA\u6a21\u578b<\/strong><\/p>\n<\/p>\n<p><p>SARIMA\uff08Seasonal ARIMA\uff09\u6a21\u578b\u662f\u5728ARIMA\u6a21\u578b\u57fa\u7840\u4e0a\u589e\u52a0\u4e86\u5b63\u8282\u6027\u56e0\u7d20\u7684\u8003\u8651\uff0c\u9002\u7528\u4e8e\u5177\u6709\u5b63\u8282\u6027\u6ce2\u52a8\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>4.1 \u6570\u636e\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528SARIMA\u6a21\u578b\u4e4b\u524d\uff0c\u9700\u8981\u5bf9\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u8fdb\u884c\u9884\u5904\u7406\u3002\u9996\u5148\u9700\u8981\u786e\u4fdd\u6570\u636e\u662f\u5e73\u7a33\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528ADF\u68c0\u9a8c\u6765\u5224\u65ad\u3002\u5982\u679c\u6570\u636e\u4e0d\u5e73\u7a33\uff0c\u53ef\u4ee5\u901a\u8fc7\u5dee\u5206\u7684\u65b9\u6cd5\u4f7f\u5176\u5e73\u7a33\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># ADF\u68c0\u9a8c<\/p>\n<p>result = adfuller(data[&#39;value&#39;])<\/p>\n<p>print(&#39;ADF Statistic:&#39;, result[0])<\/p>\n<p>print(&#39;p-value:&#39;, result[1])<\/p>\n<h2><strong>\u5982\u679c\u6570\u636e\u4e0d\u5e73\u7a33\uff0c\u5219\u8fdb\u884c\u5dee\u5206<\/strong><\/h2>\n<p>if result[1] &gt; 0.05:<\/p>\n<p>    data[&#39;value_diff&#39;] = data[&#39;value&#39;].diff().dropna()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.2 \u6a21\u578b\u62df\u5408<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u9884\u5904\u7406\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528SARIMA\u6a21\u578b\u8fdb\u884c\u62df\u5408\u3002\u9700\u8981\u786e\u5b9aSARIMA\u6a21\u578b\u7684\u4e03\u4e2a\u53c2\u6570\uff1ap\uff08\u81ea\u56de\u5f52\u9636\u6570\uff09\u3001d\uff08\u5dee\u5206\u9636\u6570\uff09\u3001q\uff08\u79fb\u52a8\u5e73\u5747\u9636\u6570\uff09\u3001P\uff08\u5b63\u8282\u6027\u81ea\u56de\u5f52\u9636\u6570\uff09\u3001D\uff08\u5b63\u8282\u6027\u5dee\u5206\u9636\u6570\uff09\u3001Q\uff08\u5b63\u8282\u6027\u79fb\u52a8\u5e73\u5747\u9636\u6570\uff09\u548cs\uff08\u5b63\u8282\u5468\u671f\uff09\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from statsmodels.tsa.statespace.sarimax import SARIMAX<\/p>\n<h2><strong>\u786e\u5b9aSARIMA\u6a21\u578b\u53c2\u6570<\/strong><\/h2>\n<p>p, d, q = 1, 1, 1  # \u975e\u5b63\u8282\u6027\u53c2\u6570<\/p>\n<p>P, D, Q, s = 1, 1, 1, 12  # \u5b63\u8282\u6027\u53c2\u6570<\/p>\n<h2><strong>\u62df\u5408SARIMA\u6a21\u578b<\/strong><\/h2>\n<p>model = SARIMAX(data[&#39;value_diff&#39;].dropna(), order=(p, d, q), seasonal_order=(P, D, Q, s))<\/p>\n<p>model_fit = model.fit()<\/p>\n<h2><strong>\u6253\u5370\u6a21\u578b\u6458\u8981<\/strong><\/h2>\n<p>print(model_fit.summary())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.3 \u751f\u6210\u9884\u6d4b\u8868<\/h3>\n<\/p>\n<p><p>\u62df\u5408\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\uff0c\u5e76\u751f\u6210\u672a\u6765\u7684\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9884\u6d4b\u672a\u6765\u65f6\u95f4\u5e8f\u5217<\/p>\n<p>forecast = model_fit.get_forecast(steps=12)<\/p>\n<h2><strong>\u751f\u6210\u9884\u6d4b\u8868<\/strong><\/h2>\n<p>forecast_df = forecast.conf_int()<\/p>\n<p>forecast_df[&#39;forecast&#39;] = model_fit.predict(start=forecast_df.index[0], end=forecast_df.index[-1])<\/p>\n<p>print(forecast_df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Python\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u672a\u6765\u9884\u6d4b\u8868\u3002\u6bcf\u79cd\u6a21\u578b\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u7684\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u7279\u70b9\u9009\u62e9\u5408\u9002\u7684\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u7684\u672a\u6765\u9884\u6d4b\u6570\u636e\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u50cfPandas\u548cStatsmodels\u8fd9\u6837\u7684\u5e93\u6765\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u7684\u672a\u6765\u9884\u6d4b\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u51c6\u5907\u597d\u5386\u53f2\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528ARIMA\u6a21\u578b\u6216Prophet\u6a21\u578b\u7b49\u8fdb\u884c\u5efa\u6a21\uff0c\u6700\u540e\u901a\u8fc7\u9884\u6d4b\u529f\u80fd\u751f\u6210\u672a\u6765\u7684\u6570\u636e\u3002\u8fd9\u4e9b\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u51fd\u6570\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u8f7b\u677e\u5b9e\u73b0\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u3002<\/p>\n<p><strong>\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u65f6\uff0c\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u6a21\u578b\uff1f<\/strong><br \/>\u9009\u62e9\u5408\u9002\u7684\u6a21\u578b\u901a\u5e38\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u7279\u6027\uff0c\u4f8b\u5982\u5b63\u8282\u6027\u3001\u8d8b\u52bf\u548c\u5468\u671f\u6027\u3002ARIMA\u6a21\u578b\u9002\u7528\u4e8e\u5e73\u7a33\u6570\u636e\uff0c\u800cProphet\u6a21\u578b\u5219\u66f4\u9002\u5408\u5904\u7406\u5b63\u8282\u6027\u548c\u5047\u671f\u6548\u5e94\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u7ed8\u5236\u81ea\u76f8\u5173\u56fe\u548c\u504f\u81ea\u76f8\u5173\u56fe\u6765\u5206\u6790\u6570\u636e\u7279\u5f81\uff0c\u5e2e\u52a9\u60a8\u51b3\u5b9a\u4f7f\u7528\u54ea\u79cd\u6a21\u578b\u3002<\/p>\n<p><strong>\u5728\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u8868\u65f6\uff0c\u5982\u4f55\u8bc4\u4f30\u9884\u6d4b\u7684\u51c6\u786e\u6027\uff1f<\/strong><br \/>\u9884\u6d4b\u7684\u51c6\u786e\u6027\u53ef\u4ee5\u901a\u8fc7\u8ba1\u7b97\u4e00\u4e9b\u7edf\u8ba1\u6307\u6807\u6765\u8bc4\u4f30\uff0c\u4f8b\u5982\u5747\u65b9\u6839\u8bef\u5dee\uff08RMSE\uff09\u3001\u5e73\u5747\u7edd\u5bf9\u8bef\u5dee\uff08MAE\uff09\u548cR\u00b2\u5206\u6570\u3002\u8fd9\u4e9b\u6307\u6807\u53ef\u4ee5\u5e2e\u52a9\u60a8\u4e86\u89e3\u6a21\u578b\u7684\u6027\u80fd\u4ee5\u53ca\u9884\u6d4b\u503c\u4e0e\u5b9e\u9645\u503c\u4e4b\u95f4\u7684\u5dee\u5f02\u3002\u5e38\u7528\u7684\u5de5\u5177\u6709Scikit-learn\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u8ba1\u7b97\u8fd9\u4e9b\u8bc4\u4f30\u6307\u6807\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d: Python\u751f\u6210\u65f6\u95f4\u5e8f\u5217\u672a\u6765\u9884\u6d4b\u8868\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528ARIMA\u6a21\u578b\u3001Prophet\u6a21\u578b\u3001LSTM\u6a21\u578b\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1042529,"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\/1042522"}],"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=1042522"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1042522\/revisions"}],"predecessor-version":[{"id":1042531,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1042522\/revisions\/1042531"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1042529"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1042522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1042522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1042522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}