中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

武漢模板建站平臺(tái)哪家好鏈接提交工具

武漢模板建站平臺(tái)哪家好,鏈接提交工具,重慶網(wǎng)站公司建設(shè),網(wǎng)站公司建設(shè)公司一、本文介紹 本文帶來(lái)的是利用傳統(tǒng)時(shí)間序列預(yù)測(cè)模型ARIMA(注意:ARIMA模型不屬于機(jī)器學(xué)習(xí))和利用PyTorch實(shí)現(xiàn)深度學(xué)習(xí)模型LSTM進(jìn)行融合進(jìn)行預(yù)測(cè),主要思想是->先利用ARIMA先和移動(dòng)平均結(jié)合處理數(shù)據(jù)的線性部分(例如趨勢(shì)和季節(jié)性&#xff09…

一、本文介紹

本文帶來(lái)的是利用傳統(tǒng)時(shí)間序列預(yù)測(cè)模型ARIMA(注意:ARIMA模型不屬于機(jī)器學(xué)習(xí))和利用PyTorch實(shí)現(xiàn)深度學(xué)習(xí)模型LSTM進(jìn)行融合進(jìn)行預(yù)測(cè),主要思想是->先利用ARIMA先和移動(dòng)平均結(jié)合處理數(shù)據(jù)的線性部分(例如趨勢(shì)和季節(jié)性),同時(shí)利用LSTM捕捉更復(fù)雜的非線性模式和長(zhǎng)期依賴關(guān)系。本文內(nèi)容包括->講解LSTM和ARIMA的基本原理、融合的主要思想和依據(jù)、模型實(shí)戰(zhàn)所用數(shù)據(jù)集介紹 、模型的參數(shù)講解、模型的訓(xùn)練、結(jié)果展示、結(jié)果分析、以及如何訓(xùn)練你個(gè)人數(shù)據(jù)集。

代碼地址->文末有項(xiàng)目的完整代碼塊分析

適用對(duì)象->想要進(jìn)行長(zhǎng)期預(yù)測(cè)(模型的長(zhǎng)期預(yù)測(cè)功能效果不錯(cuò))

目錄

一、本文介紹?

二、基本原理

三、融合思想

四、數(shù)據(jù)集

五、訓(xùn)練和預(yù)測(cè)

1.參數(shù)講解

2.訓(xùn)練

3.預(yù)測(cè)

3.1結(jié)果展示

3.2結(jié)果分析

六、如何訓(xùn)練你個(gè)人數(shù)據(jù)集

總結(jié)


二、基本原理?

其中ARIMA和LSTM的基本原理在我其它的博客中其實(shí)以及都分別經(jīng)過(guò)了,大家如果有興趣可以看我其它博客的講解其中都有非常仔細(xì)的說(shuō)明,下面簡(jiǎn)單的給大家介紹一下。?

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(六)深入理解ARIMA包括差分和相關(guān)性分析

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(三)(LSTM)(Python)(深度學(xué)習(xí))時(shí)間序列預(yù)測(cè)(包括運(yùn)行代碼以及代碼講解)

1.ARIMA的基本原理

ARIMA(自回歸積分滑動(dòng)平均)模型是一種廣泛使用的時(shí)間序列分析方法,它的基本原理可以從其名稱中的三個(gè)部分理解自回歸(AR)、差分(I,即積分的逆過(guò)程)、滑動(dòng)平均(MA)。

  • 自回歸(AR)部分:

? ?????????- 自回歸是指一個(gè)變量與其過(guò)去值的回歸關(guān)系。
? ?????????- 在ARIMA模型中,這表示當(dāng)前值是過(guò)去若干時(shí)間點(diǎn)值的線性組合。
? ?????????- 這部分模型的目的是捕捉時(shí)間序列中的自相關(guān)性。

  • 差分(I)部分:

? ?????????- 差分是為了使非平穩(wěn)時(shí)間序列變得平穩(wěn)的一種處理方式。
? ?????????- 通過(guò)對(duì)原始數(shù)據(jù)進(jìn)行一定次數(shù)的差分,可以去除數(shù)據(jù)中的季節(jié)性和趨勢(shì)性。
? ?????????- 差分次數(shù)通常根據(jù)數(shù)據(jù)的特性決定。

  • ?滑動(dòng)平均(MA)部分:

????????? ?- 滑動(dòng)平均部分是指當(dāng)前值與過(guò)去誤差項(xiàng)的線性組合。
????????? ?- 這里的誤差項(xiàng)是指預(yù)測(cè)值與實(shí)際值之間的差距。
????????? ?- MA模型的目的是捕捉時(shí)間序列中的隨機(jī)波動(dòng)。

在構(gòu)建ARIMA模型時(shí),需要確定三個(gè)主要參數(shù):p(AR項(xiàng)的階數(shù))、d(差分次數(shù))、q(MA項(xiàng)的階數(shù))。這些參數(shù)共同決定了模型的結(jié)構(gòu)。ARIMA模型通過(guò)結(jié)合這三個(gè)部分,既能處理時(shí)間序列的長(zhǎng)期趨勢(shì)和季節(jié)性變化,又能捕捉到序列的隨機(jī)波動(dòng),從而在各種場(chǎng)景下進(jìn)行有效的時(shí)間序列預(yù)測(cè)。

2.LSTM的基本原理

長(zhǎng)短期記憶網(wǎng)絡(luò)(LSTM)是一種特殊類型的遞歸神經(jīng)網(wǎng)絡(luò)(RNN),它專門(mén)設(shè)計(jì)用來(lái)處理序列數(shù)據(jù)的長(zhǎng)期依賴問(wèn)題。LSTM的基本原理主要圍繞其獨(dú)特的內(nèi)部結(jié)構(gòu),這種結(jié)構(gòu)使其能夠有效地學(xué)習(xí)和記憶長(zhǎng)期信息。面是LSTM的結(jié)構(gòu)圖和幾個(gè)關(guān)鍵組成部分和它們的作用

  1. 門(mén)控制制(Gates):

    • LSTM通過(guò)門(mén)(Gates)來(lái)控制細(xì)胞狀態(tài)中的信息流。
    • 這些門(mén)是一種允許信息通過(guò)的方式,它們由一個(gè)sigmoid神經(jīng)網(wǎng)絡(luò)層和一個(gè)逐點(diǎn)乘法操作組成。
    • 門(mén)可以學(xué)習(xí)何時(shí)添加或刪除信息到細(xì)胞狀態(tài)中,這是通過(guò)調(diào)節(jié)信息流的重要性(權(quán)重)來(lái)實(shí)現(xiàn)的。
  • 遺忘門(mén)(Forget Gate):

    • 遺忘門(mén)決定了從細(xì)胞狀態(tài)中丟棄什么信息。
    • 它通過(guò)查看當(dāng)前輸入和前一隱藏層的輸出來(lái)決定保留或丟棄每個(gè)細(xì)胞狀態(tài)中的信息。
  • 輸入門(mén)(Input Gate):

    • 輸入門(mén)用來(lái)更新細(xì)胞狀態(tài)。
    • 它首先通過(guò)一個(gè)sigmoid層決定哪些值將要更新,然后通過(guò)一個(gè)tanh層創(chuàng)建一個(gè)新的候選值向量,這個(gè)向量將被添加到狀態(tài)中。
  • 輸出門(mén)(Output Gate):

    • 輸出門(mén)控制著下一個(gè)隱藏狀態(tài)的值。
    • 隱藏狀態(tài)包含關(guān)于先前輸入的信息,用于預(yù)測(cè)或決策。
    • 這個(gè)門(mén)查看當(dāng)前的細(xì)胞狀態(tài),并決定輸出的部分。

總結(jié):LSTM通過(guò)這種復(fù)雜的內(nèi)部結(jié)構(gòu),能夠有效地解決傳統(tǒng)RNN面臨的長(zhǎng)期依賴問(wèn)題,。這種網(wǎng)絡(luò)能夠記住長(zhǎng)期的信息,同時(shí)還可以決定忘記無(wú)關(guān)緊要或過(guò)時(shí)的信息。?

3.融合思想

將ARIMA和LSTM結(jié)合起來(lái)的主要思想是->

結(jié)合ARIMA和LSTM的目的是利用ARIMA處理數(shù)據(jù)的線性部分(例如趨勢(shì)和季節(jié)性),同時(shí)利用LSTM捕捉更復(fù)雜的非線性模式和長(zhǎng)期依賴關(guān)系。

這種組合方法可以彌補(bǔ)單一模型的不足。例如,當(dāng)時(shí)間序列數(shù)據(jù)既包含線性又包含非線性特征時(shí),單獨(dú)的ARIMA或LSTM可能無(wú)法充分捕捉全部信息,而結(jié)合使用兩者可以提高預(yù)測(cè)性能。

結(jié)合的方式->分階段預(yù)測(cè)(先用移動(dòng)平滑和ARIMA處理,再用LSTM進(jìn)一步分析)、模型融合(將兩個(gè)模型的預(yù)測(cè)結(jié)果綜合考慮)

下面的圖片是整個(gè)結(jié)構(gòu)的網(wǎng)絡(luò)圖,從數(shù)據(jù)的輸出到數(shù)據(jù)的輸出整個(gè)過(guò)程的描述->

總之,將LSTM和ARIMA結(jié)合的核心思想是通過(guò)利用兩種模型的互補(bǔ)優(yōu)勢(shì),提高對(duì)復(fù)雜時(shí)間序列數(shù)據(jù)的預(yù)測(cè)能力。

三、數(shù)據(jù)集

因?yàn)楸疚纳婕暗?span style="color:#1c7892;">ARIMA模型其為單變量的預(yù)測(cè)模型所以我們的模型有限制必須是單元預(yù)測(cè),所以我們的數(shù)據(jù)集為某公司的業(yè)務(wù)水平評(píng)估數(shù)據(jù)為從0-1分布,部分截圖如下->

四、訓(xùn)練和預(yù)測(cè)

下面開(kāi)始分別進(jìn)行參數(shù)的講解、模型訓(xùn)練、預(yù)測(cè)、和結(jié)果展示和分析。

1.參數(shù)講解

if __name__ == '__main__':# Load historical data# CSV should have columns: ['date', 'OT']strpath= '你數(shù)據(jù)集的地址CSV格式的文件'target = 'OT'  # 預(yù)測(cè)的列明data = pd.read_csv('ETTh1.csv', index_col=0, header=0).tail(1500).reset_index(drop=True)[['target']]

其中的參數(shù)講解我以及在代碼中標(biāo)注出來(lái)了應(yīng)該很好理解,主要修改這兩處就可以了。?

2.訓(xùn)練

ARIMA擬合部分->

def get_arima(data, train_len, test_len):# prepare train and test datadata = data.tail(test_len + train_len).reset_index(drop=True)train = data.head(train_len).values.tolist()test = data.tail(test_len).values.tolist()# Initialize modelmodel = auto_arima(train, max_p=3, max_q=3, seasonal=False, trace=True,error_action='ignore', suppress_warnings=True, maxiter=10)# Determine model parametersmodel.fit(train)order = model.get_params()['order']print('ARIMA order:', order, '\n')# Genereate predictionsprediction = []for i in range(len(test)):model = pm.ARIMA(order=order)model.fit(train)print('working on', i+1, 'of', test_len, '-- ' + str(int(100 * (i + 1) / test_len)) + '% complete')prediction.append(model.predict()[0])train.append(test[i])# Generate error datamse = mean_squared_error(test, prediction)rmse = mse ** 0.5mape = mean_absolute_percentage_error(pd.Series(test), pd.Series(prediction))return prediction, mse, rmse, mape

代碼講解->其實(shí)這部分沒(méi)什么好講的就是首先對(duì)數(shù)據(jù)進(jìn)行了處理分出了訓(xùn)練集、測(cè)試集,然后初始化了一個(gè)ARIMA模型(調(diào)用了官方的pmdarima庫(kù)),然后用fit方法進(jìn)行自動(dòng)擬合然后進(jìn)行結(jié)果預(yù)測(cè)。是一個(gè)很標(biāo)準(zhǔn)的ARIMA訓(xùn)練過(guò)程如果大家想仔細(xì)了解可以看我單獨(dú)的ARIMA模型講解里面有具體的分析。?訓(xùn)練過(guò)程控制臺(tái)輸出如下->

LSTM訓(xùn)練部分->?

def get_lstm(data, train_len, test_len, lstm_len=4):# prepare train and test datadata = data.tail(test_len + train_len).reset_index(drop=True)dataset = np.reshape(data.values, (len(data), 1))scaler = MinMaxScaler(feature_range=(0, 1))dataset_scaled = scaler.fit_transform(dataset)x_train = []y_train = []x_test = []for i in range(lstm_len, train_len):x_train.append(dataset_scaled[i - lstm_len:i, 0])y_train.append(dataset_scaled[i, 0])for i in range(train_len, len(dataset_scaled)):x_test.append(dataset_scaled[i - lstm_len:i, 0])x_train = np.array(x_train)y_train = np.array(y_train)x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))x_test = np.array(x_test)x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))# Convert to PyTorch tensorsx_train = torch.tensor(x_train).float()y_train = torch.tensor(y_train).float()x_test = torch.tensor(x_test).float()# Create the PyTorch modelmodel = LSTMModel(input_dim=1, hidden_dim=lstm_len)criterion = torch.nn.MSELoss()optimizer = torch.optim.Adam(model.parameters(), lr=0.01)total_loss = 0# trainfor epoch in range(500):model.train()optimizer.zero_grad()# Forward passy_pred = model(x_train)# Compute Lossloss = criterion(y_pred.squeeze(), y_train)total_loss += loss.item()# Backward pass and optimizeloss.backward()optimizer.step()# Print training progressif (epoch + 1) % 50 == 0:  # 每50輪打印一次print(f'Epoch [{epoch + 1}/500], Loss: {loss.item():.4f}')# Calculate and print average lossaverage_loss = total_loss / 500print(f'Average Loss: {average_loss:.4f}')# Predictionmodel.eval()predict = model(x_test)predict = predict.data.numpy()prediction = scaler.inverse_transform(predict).tolist()output = []for i in range(len(prediction)):output.extend(prediction[i])prediction = output# Error calculationmse = mean_squared_error(data.tail(len(prediction)).values, prediction)rmse = mse ** 0.5mape = mean_absolute_percentage_error(data.tail(len(prediction)).reset_index(drop=True), pd.Series(prediction))return prediction, mse, rmse, mape

代碼講解->同樣這里最上面是數(shù)據(jù)處理部分,分解出來(lái)訓(xùn)練集和測(cè)試集,然后調(diào)用了我定義的LSTM模型最后的總代碼分析里面有,然后進(jìn)行訓(xùn)練,最后調(diào)用模型進(jìn)行預(yù)測(cè),然后將預(yù)測(cè)結(jié)果和測(cè)試集算mse、rmse、和mape?。如果想看LSTM的下詳細(xì)過(guò)程同樣可以看我的單模型講解,訓(xùn)練模型控制臺(tái)輸出如下->

3.預(yù)測(cè)

進(jìn)行預(yù)測(cè)之后控制臺(tái)會(huì)打印預(yù)測(cè)結(jié)果如下->

同時(shí)會(huì)保存csv文件用于真實(shí)值和預(yù)測(cè)值的對(duì)比,如下->?

3.1結(jié)果展示

3.2結(jié)果分析

這篇文章的預(yù)測(cè)結(jié)果和我上一篇的SCINet大家有興趣可以對(duì)比一下經(jīng)過(guò)結(jié)合ARIMA模型的預(yù)測(cè)結(jié)果明顯要好很多,消除了其中一定的數(shù)據(jù)滯后性,但是還是并沒(méi)有完全消失,當(dāng)然可以將ARIMA和更復(fù)雜的移動(dòng)平均方法結(jié)合起來(lái)沒(méi)準(zhǔn)效果會(huì)更好,這里大家可以進(jìn)行嘗試嘗試。

五、如何訓(xùn)練你個(gè)人數(shù)據(jù)集

訓(xùn)練你個(gè)人數(shù)據(jù)集需要注意的就是,因?yàn)槔肁RIMA模型,所以只支持單變量預(yù)測(cè),當(dāng)然也可以替換SARIMA模型進(jìn)行多元預(yù)測(cè)這個(gè)大家也可以嘗試嘗試如果有興趣,把下面的內(nèi)容填寫(xiě)了就可以用你自己的數(shù)據(jù)集進(jìn)行訓(xùn)練了還是比較簡(jiǎn)單的,沒(méi)有涉及到復(fù)雜的參數(shù)類似于Transformer模型那樣。

六、完整的代碼塊分享

import pandas as pd
import numpy as np
from scipy.stats import kurtosis
from pmdarima import auto_arima
import pmdarima as pm
import torch
import torch.nn as nn
from sklearn.metrics import mean_squared_error, mean_absolute_percentage_error
import json
from sklearn.preprocessing import MinMaxScalerdef mean_absolute_percentage_error(actual, prediction):actual = pd.Series(actual)prediction = pd.Series(prediction)return 100 * np.mean(np.abs((actual - prediction))/actual)def get_arima(data, train_len, test_len):# prepare train and test datadata = data.tail(test_len + train_len).reset_index(drop=True)train = data.head(train_len).values.tolist()test = data.tail(test_len).values.tolist()# Initialize modelmodel = auto_arima(train, max_p=3, max_q=3, seasonal=False, trace=True,error_action='ignore', suppress_warnings=True, maxiter=10)# Determine model parametersmodel.fit(train)order = model.get_params()['order']print('ARIMA order:', order, '\n')# Genereate predictionsprediction = []for i in range(len(test)):model = pm.ARIMA(order=order)model.fit(train)print('working on', i+1, 'of', test_len, '-- ' + str(int(100 * (i + 1) / test_len)) + '% complete')prediction.append(model.predict()[0])train.append(test[i])# Generate error datamse = mean_squared_error(test, prediction)rmse = mse ** 0.5mape = mean_absolute_percentage_error(pd.Series(test), pd.Series(prediction))return prediction, mse, rmse, mapeclass LSTMModel(nn.Module):def __init__(self, input_dim, hidden_dim, output_dim=1, num_layers=2):super(LSTMModel, self).__init__()self.hidden_dim = hidden_dimself.num_layers = num_layers# Define the LSTM layerself.lstm = nn.LSTM(input_dim, hidden_dim, num_layers, batch_first=True)# Define the output layerself.linear = nn.Linear(hidden_dim, output_dim)def forward(self, x):# Initialize hidden state with zerosh0 = torch.zeros(self.num_layers, x.size(0), self.hidden_dim).requires_grad_()# Initialize cell statec0 = torch.zeros(self.num_layers, x.size(0), self.hidden_dim).requires_grad_()# We need to detach as we are doing truncated backpropagation through time (BPTT)# If we don't, we'll backprop all the way to the start even after going through another batchout, (hn, cn) = self.lstm(x, (h0.detach(), c0.detach()))# Index hidden state of last time stepout = self.linear(out[:, -1, :])return outdef get_lstm(data, train_len, test_len, lstm_len=4):# prepare train and test datadata = data.tail(test_len + train_len).reset_index(drop=True)dataset = np.reshape(data.values, (len(data), 1))scaler = MinMaxScaler(feature_range=(0, 1))dataset_scaled = scaler.fit_transform(dataset)x_train = []y_train = []x_test = []for i in range(lstm_len, train_len):x_train.append(dataset_scaled[i - lstm_len:i, 0])y_train.append(dataset_scaled[i, 0])for i in range(train_len, len(dataset_scaled)):x_test.append(dataset_scaled[i - lstm_len:i, 0])x_train = np.array(x_train)y_train = np.array(y_train)x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))x_test = np.array(x_test)x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))# Convert to PyTorch tensorsx_train = torch.tensor(x_train).float()y_train = torch.tensor(y_train).float()x_test = torch.tensor(x_test).float()# Create the PyTorch modelmodel = LSTMModel(input_dim=1, hidden_dim=lstm_len)criterion = torch.nn.MSELoss()optimizer = torch.optim.Adam(model.parameters(), lr=0.01)total_loss = 0# trainfor epoch in range(500):model.train()optimizer.zero_grad()# Forward passy_pred = model(x_train)# Compute Lossloss = criterion(y_pred.squeeze(), y_train)total_loss += loss.item()# Backward pass and optimizeloss.backward()optimizer.step()# Print training progressif (epoch + 1) % 50 == 0:  # 每50輪打印一次print(f'Epoch [{epoch + 1}/500], Loss: {loss.item():.4f}')# Calculate and print average lossaverage_loss = total_loss / 500print(f'Average Loss: {average_loss:.4f}')# Predictionmodel.eval()predict = model(x_test)predict = predict.data.numpy()prediction = scaler.inverse_transform(predict).tolist()output = []for i in range(len(prediction)):output.extend(prediction[i])prediction = output# Error calculationmse = mean_squared_error(data.tail(len(prediction)).values, prediction)rmse = mse ** 0.5mape = mean_absolute_percentage_error(data.tail(len(prediction)).reset_index(drop=True), pd.Series(prediction))return prediction, mse, rmse, mapedef SMA(data, window):sma = np.convolve(data[target], np.ones(window), 'same') / windowreturn smadef EMA(data, window):alpha = 2 / (window + 1)ema = np.zeros_like(data)ema[0] = data.iloc[0]  # 設(shè)置初始值為序列的第一個(gè)值for i in range(1, len(data)):ema[i] = alpha * data.iloc[i] + (1 - alpha) * ema[i - 1]return emadef WMA(data, window):weights = np.arange(1, window + 1)wma = np.convolve(data[target], weights/weights.sum(), 'same')return wma# 其他復(fù)雜的移動(dòng)平均技術(shù)如 DEMA 可以通過(guò)組合上述基礎(chǔ)方法實(shí)現(xiàn)
# 例如,DEMA 是兩個(gè)不同窗口大小的 EMA 的組合if __name__ == '__main__':# Load historical data# CSV should have columns: ['date', 'OT']strpath= '你數(shù)據(jù)集的地址CSV格式的文件'target = 'OT'  # 預(yù)測(cè)的列明data = pd.read_csv('ETTh1.csv', index_col=0, header=0).tail(1500).reset_index(drop=True)[[target]]talib_moving_averages = ['SMA'] # 替換你想用的方法# 創(chuàng)建一個(gè)字典來(lái)存儲(chǔ)這些函數(shù)functions = {'SMA': SMA,# 'EMA': EMA,# 'WMA': WMA,# 添加其他需要的移動(dòng)平均函數(shù)}# for ma in talib_moving_averages:#     functions[ma] = abstract.Function(ma)# Determine kurtosis "K" values for MA period 4-99kurtosis_results = {'period': []}for i in range(4, 100):kurtosis_results['period'].append(i)for ma in talib_moving_averages:# Run moving average, remove last 252 days (used later for test data set), trim MA result to last 60 daysma_output = functions[ma](data[:-252], i)[-60:]# Determine kurtosis "K" valuek = kurtosis(ma_output, fisher=False)# add to dictionaryif ma not in kurtosis_results.keys():kurtosis_results[ma] = []kurtosis_results[ma].append(k)kurtosis_results = pd.DataFrame(kurtosis_results)kurtosis_results.to_csv('kurtosis_results.csv')# Determine period with K closest to 3 +/-5%optimized_period = {}for ma in talib_moving_averages:difference = np.abs(kurtosis_results[ma] - 3)df = pd.DataFrame({'difference': difference, 'period': kurtosis_results['period']})df = df.sort_values(by=['difference'], ascending=True).reset_index(drop=True)if df.at[0, 'difference'] < 3 * 0.05:optimized_period[ma] = df.at[0, 'period']else:print(ma + ' is not viable, best K greater or less than 3 +/-5%')print('\nOptimized periods:', optimized_period)simulation = {}for ma in optimized_period:# Split data into low volatility and high volatility time serieslow_vol = pd.Series(functions[ma](data, optimized_period[ma]))high_vol = pd.Series(data[target] - low_vol)# Generate ARIMA and LSTM predictionsprint('\nWorking on ' + ma + ' predictions')try:low_vol_prediction, low_vol_mse, low_vol_rmse, low_vol_mape = get_arima(low_vol, 1000, 252)except:print('ARIMA error, skipping to next MA type')continuehigh_vol_prediction, high_vol_mse, high_vol_rmse, high_vol_mape = get_lstm(high_vol, 1000, 252)final_prediction = pd.Series(low_vol_prediction) + pd.Series(high_vol_prediction)mse = mean_squared_error(final_prediction.values, data[target].tail(252).values)rmse = mse ** 0.5mape = mean_absolute_percentage_error(data[target].tail(252).reset_index(drop=True), final_prediction)# Generate prediction accuracyactual = data[target].tail(252).valuesdf = pd.DataFrame({'real': actual,'pre': final_prediction}).to_csv('results.csv',index=False)result_1 = []result_2 = []for i in range(1, len(final_prediction)):# Compare prediction to previous close priceif final_prediction[i] > actual[i-1] and actual[i] > actual[i-1]:result_1.append(1)elif final_prediction[i] < actual[i-1] and actual[i] < actual[i-1]:result_1.append(1)else:result_1.append(0)# Compare prediction to previous predictionif final_prediction[i] > final_prediction[i-1] and actual[i] > actual[i-1]:result_2.append(1)elif final_prediction[i] < final_prediction[i-1] and actual[i] < actual[i-1]:result_2.append(1)else:result_2.append(0)accuracy_1 = np.mean(result_1)accuracy_2 = np.mean(result_2)simulation[ma] = {'low_vol': {'prediction': low_vol_prediction, 'mse': low_vol_mse,'rmse': low_vol_rmse, 'mape': low_vol_mape},'high_vol': {'prediction': high_vol_prediction, 'mse': high_vol_mse,'rmse': high_vol_rmse},'final': {'prediction': final_prediction.values.tolist(), 'mse': mse,'rmse': rmse, 'mape': mape},'accuracy': {'prediction vs close': accuracy_1, 'prediction vs prediction': accuracy_2}}# save simulation data here as checkpointwith open('simulation_data.json', 'w') as fp:json.dump(simulation, fp)for ma in simulation.keys():print('\n' + ma)print('Prediction vs Close:\t\t' + str(round(100*simulation[ma]['accuracy']['prediction vs close'], 2))+ '% Accuracy')print('Prediction vs Prediction:\t' + str(round(100*simulation[ma]['accuracy']['prediction vs prediction'], 2))+ '% Accuracy')print('MSE:\t', simulation[ma]['final']['mse'],'\nRMSE:\t', simulation[ma]['final']['rmse'],'\nMAPE:\t', simulation[ma]['final']['mape'])

總結(jié)

到此本文已經(jīng)全部講解完成了希望能夠幫助到大家。在這里也給大家推薦一些我其它的博客的時(shí)間序列實(shí)戰(zhàn)案例講解,其中有數(shù)據(jù)分析的講解就是我前面提到的如何設(shè)置參數(shù)的分析博客,最后希望大家訂閱我的專欄,本專欄均分文章均分98,并且免費(fèi)閱讀。

時(shí)間序列預(yù)測(cè)實(shí)戰(zhàn)(十一)用SCINet實(shí)現(xiàn)滾動(dòng)預(yù)測(cè)功能(附代碼+數(shù)據(jù)集+原理介紹)

時(shí)間序列預(yù)測(cè):深度學(xué)習(xí)、機(jī)器學(xué)習(xí)、融合模型、創(chuàng)新模型實(shí)戰(zhàn)案例(附代碼+數(shù)據(jù)集+原理介紹)

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(十)(個(gè)人創(chuàng)新模型)通過(guò)堆疊CNN、GRU、LSTM實(shí)現(xiàn)多元預(yù)測(cè)和單元預(yù)測(cè)

時(shí)間序列預(yù)測(cè)中的數(shù)據(jù)分析->周期性、相關(guān)性、滯后性、趨勢(shì)性、離群值等特性的分析方法

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(八)(Informer)個(gè)人數(shù)據(jù)集、詳細(xì)參數(shù)、代碼實(shí)戰(zhàn)講解

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(七)(TPA-LSTM)結(jié)合TPA注意力機(jī)制的LSTM實(shí)現(xiàn)多元預(yù)測(cè)

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(六)深入理解機(jī)器學(xué)習(xí)ARIMA包括差分和相關(guān)性分析

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(五)基于雙向LSTM橫向搭配單向LSTM進(jìn)行回歸問(wèn)題解決

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(四)(Xgboost)(Python)(機(jī)器學(xué)習(xí))圖解機(jī)制原理實(shí)現(xiàn)時(shí)間序列預(yù)測(cè)和分類(附一鍵運(yùn)行代碼資源下載和代碼講解)

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(三)(LSTM)(Python)(深度學(xué)習(xí))時(shí)間序列預(yù)測(cè)(包括運(yùn)行代碼以及代碼講解)

【全網(wǎng)首發(fā)】(MTS-Mixers)(Python)(Pytorch)最新由華為發(fā)布的時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(一)(包括代碼講解)實(shí)現(xiàn)企業(yè)級(jí)預(yù)測(cè)精度包括官方代碼BUG修復(fù)Transform模型

時(shí)間序列預(yù)測(cè)模型實(shí)戰(zhàn)案例(二)(Holt-Winter)(Python)結(jié)合K-折交叉驗(yàn)證進(jìn)行時(shí)間序列預(yù)測(cè)實(shí)現(xiàn)企業(yè)級(jí)預(yù)測(cè)精度(包括運(yùn)行代碼以及代碼講解)

最后希望大家工作順利學(xué)業(yè)有成!

http://www.risenshineclean.com/news/5064.html

相關(guān)文章:

  • 杭州網(wǎng)站制如何在其他平臺(tái)做推廣
  • 濟(jì)南建站免費(fèi)模板瀏覽器網(wǎng)站進(jìn)入口
  • 北京出名做網(wǎng)站的公司如何做好推廣
  • 阿里云認(rèn)證網(wǎng)站建設(shè)題庫(kù)免費(fèi)制作網(wǎng)頁(yè)平臺(tái)
  • 企業(yè)做網(wǎng)站設(shè)計(jì)的北京網(wǎng)絡(luò)推廣外包公司排行
  • 成都市城鄉(xiāng)建設(shè)委員網(wǎng)站seo網(wǎng)站診斷價(jià)格
  • 要給公司做一個(gè)網(wǎng)站怎么做網(wǎng)站優(yōu)化的方式有哪些
  • 北京比較好的網(wǎng)站建設(shè)公司谷歌seo服務(wù)
  • 做競(jìng)價(jià)網(wǎng)站用什么系統(tǒng)好原創(chuàng)軟文
  • dede推薦評(píng)級(jí)網(wǎng)站模版百度搜索推廣費(fèi)用
  • 免費(fèi)企業(yè)網(wǎng)站空間網(wǎng)絡(luò)營(yíng)銷策劃的具體流程是
  • 越南做網(wǎng)站服務(wù)器最新app推廣項(xiàng)目平臺(tái)
  • 網(wǎng)站公司建站營(yíng)銷活動(dòng)
  • 哪個(gè)網(wǎng)站可以做視頻播放器最新全國(guó)疫情消息
  • 西安有哪些做網(wǎng)站建設(shè)的公司好網(wǎng)絡(luò)推廣計(jì)劃書(shū)范文
  • 游戲推廣是做什么的關(guān)鍵詞優(yōu)化公司排名
  • html5響應(yīng)式網(wǎng)站制作seo網(wǎng)站排名廠商定制
  • 成都 網(wǎng)站設(shè)計(jì)網(wǎng)站建設(shè)工作總結(jié)
  • 黔東南網(wǎng)站開(kāi)發(fā)gzklyy手機(jī)網(wǎng)站建設(shè)價(jià)格
  • 沒(méi)有基礎(chǔ)怎么學(xué)網(wǎng)站建設(shè)seo短視頻網(wǎng)頁(yè)入口引流免費(fèi)
  • 寧波做網(wǎng)站的大公司seo網(wǎng)站優(yōu)化師
  • 加猛掙錢免費(fèi)做網(wǎng)站軟件免費(fèi)網(wǎng)站推廣網(wǎng)站破解版
  • 自己做的網(wǎng)站服務(wù)器開(kāi)了進(jìn)不去百度號(hào)碼認(rèn)證平臺(tái)官網(wǎng)
  • 微信公眾平臺(tái)制作網(wǎng)站58網(wǎng)絡(luò)推廣
  • 風(fēng)訊網(wǎng)站內(nèi)容管理系統(tǒng)西安網(wǎng)站建設(shè)公司電話
  • 自助建站申請(qǐng)書(shū)網(wǎng)絡(luò)營(yíng)銷方案有哪些
  • 電競(jìng)logo免費(fèi)設(shè)計(jì)西安百度推廣優(yōu)化公司
  • 免費(fèi)電商網(wǎng)站建設(shè)中國(guó)培訓(xùn)網(wǎng)官網(wǎng)
  • 建設(shè)網(wǎng)站的公司興田德潤(rùn)怎么聯(lián)系北京企業(yè)網(wǎng)站seo平臺(tái)
  • 濰坊網(wǎng)站建設(shè)聯(lián)系方式東莞網(wǎng)站seo公司哪家大