{"id":357,"date":"2025-11-05T01:38:03","date_gmt":"2025-11-04T17:38:03","guid":{"rendered":"https:\/\/snaili.com\/?p=357"},"modified":"2025-11-05T01:38:03","modified_gmt":"2025-11-04T17:38:03","slug":"100%e4%b8%aa%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e4%bb%a3%e7%a0%81%e6%b7%b1%e5%ba%a6%e5%89%96%e6%9e%90%ef%bc%881%ef%bc%89%e8%82%a1%e7%a5%a8%e9%a2%84%e6%b5%8b","status":"publish","type":"post","link":"https:\/\/snaili.com\/index.php\/2025\/11\/05\/100%e4%b8%aa%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e4%bb%a3%e7%a0%81%e6%b7%b1%e5%ba%a6%e5%89%96%e6%9e%90%ef%bc%881%ef%bc%89%e8%82%a1%e7%a5%a8%e9%a2%84%e6%b5%8b\/","title":{"rendered":"100\u4e2a\u673a\u5668\u5b66\u4e60\u4ee3\u7801\u6df1\u5ea6\u5256\u6790\uff081\uff09\u80a1\u7968\u9884\u6d4b"},"content":{"rendered":"\n<p>import matplotlib.pyplot as plt<\/p>\n\n\n\n<p>import numpy as np<\/p>\n\n\n\n<p>import pandas as pd<\/p>\n\n\n\n<p>import torch<\/p>\n\n\n\n<p>import torch.nn as nn<\/p>\n\n\n\n<p>import tushare as ts<\/p>\n\n\n\n<p>from sklearn.preprocessing import StandardScaler<\/p>\n\n\n\n<p>from torch.utils.data import TensorDataset<\/p>\n\n\n\n<p>from tqdm import tqdm<\/p>\n\n\n\n<p>timestep = 1 &nbsp;# \u65f6\u95f4\u6b65\u957f\uff0c\u5c31\u662f\u5229\u7528\u591a\u5c11\u65f6\u95f4\u7a97\u53e3<\/p>\n\n\n\n<p># \u5728 LSTM \u4e2d\uff0c\u201c\u65f6\u95f4\u6b65\u957f\u201d\uff08time step \u6216 sequence length\uff09\u662f\u6307\u8f93\u5165\u5e8f\u5217\u4e2d\u6bcf\u4e2a\u6837\u672c\u5305\u542b\u7684\u65f6\u95f4\u70b9\u6570\u91cf\u3002<\/p>\n\n\n\n<p># \u5b83\u662f\u65f6\u95f4\u5e8f\u5217\u7684\u4e00\u4e2a\u7ef4\u5ea6\uff0c\u51b3\u5b9a\u4e86\u6a21\u578b\u4e00\u6b21\u5904\u7406\u591a\u5c11\u4e2a\u8fde\u7eed\u7684\u65f6\u95f4\u70b9\u3002<\/p>\n\n\n\n<p># \u65f6\u95f4\u6b65\u957f\u662f\u4f60\u5e0c\u671b\u6a21\u578b\u4e00\u6b21\u6027\u201c\u8bb0\u4f4f\u201d\u7684\u65f6\u95f4\u957f\u5ea6\uff0c\u5b83\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u65f6\u95f4\u7279\u6027\u3001\u4efb\u52a1\u76ee\u6807\u3001\u8ba1\u7b97\u8d44\u6e90\u548c\u6a21\u578b\u8bbe\u8ba1\u3002<\/p>\n\n\n\n<p># \u5982\u679c\u4f60\u7684\u6570\u636e\u662f\u65f6\u95f4\u5e8f\u5217\uff08\u5982\u80a1\u7968\u3001\u4f20\u611f\u5668\u3001\u89c6\u9891\u5e27\uff09\uff0c\u65f6\u95f4\u6b65\u957f\u901a\u5e38\u5bf9\u5e94\u4e8e\u4f60\u5e0c\u671b\u6a21\u578b\u4e00\u6b21\u770b\u5230\u7684\u65f6\u95f4\u957f\u5ea6\u3002<\/p>\n\n\n\n<p># \u4f8b\u5982\uff1a\u80a1\u7968\u6570\u636e\uff1a\u4f60\u53ef\u80fd\u5e0c\u671b\u6a21\u578b\u6bcf\u6b21\u770b\u5230\u8fc7\u53bb 30 \u5929\u7684\u6570\u636e \u2192 \u65f6\u95f4\u6b65\u957f = 30<\/p>\n\n\n\n<p>batch_size = 16 &nbsp;# \u6279\u6b21\u5927\u5c0f<\/p>\n\n\n\n<p># 1. \u63d0\u9ad8\u8bad\u7ec3\u6548\u7387<\/p>\n\n\n\n<p># \u4e00\u6b21\u5904\u7406\u591a\u4e2a\u6837\u672c\uff08\u6bd4\u5982 16 \u4e2a\uff09\u53ef\u4ee5\u5145\u5206\u5229\u7528 GPU \u5e76\u884c\u8ba1\u7b97\u80fd\u529b\u3002<\/p>\n\n\n\n<p># \u6bd4\u8d77\u6bcf\u6b21\u53ea\u5904\u7406\u4e00\u4e2a\u6837\u672c\uff08\u5373 batch_size = 1\uff09\uff0c\u901f\u5ea6\u66f4\u5feb\u3002<\/p>\n\n\n\n<p># 2. \u7a33\u5b9a\u68af\u5ea6\u66f4\u65b0<\/p>\n\n\n\n<p># \u6bcf\u6b21\u8bad\u7ec3\u4f1a\u8ba1\u7b97\u4e00\u4e2a\u201c\u5e73\u5747\u68af\u5ea6\u201d\uff0c\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u7684\u6ce2\u52a8\u3002<\/p>\n\n\n\n<p># \u5982\u679c batch \u592a\u5c0f\uff0c\u68af\u5ea6\u53ef\u80fd\u4e0d\u7a33\u5b9a\uff1b\u592a\u5927\u5219\u53ef\u80fd\u8fc7\u4e8e\u5e73\u6ed1\uff0c\u5b66\u4e60\u53d8\u6162\u3002<\/p>\n\n\n\n<p>input_dim = 4 &nbsp;# \u6bcf\u4e2a\u6b65\u957f\u5bf9\u5e94\u7684\u7279\u5f81\u6570\u91cf\uff0c\u5c31\u662f\u4f7f\u7528\u6bcf\u5929\u76844\u4e2a\u7279\u5f81\uff0c\u6700\u9ad8\u3001\u6700\u4f4e\u3001\u5f00\u76d8\u3001\u843d\u76d8<\/p>\n\n\n\n<p>hidden_dim = 64 &nbsp;# \u9690\u5c42\u5927\u5c0f<\/p>\n\n\n\n<p># \u7b2c\u4e00\u5c42\u5904\u7406\u539f\u59cb\u8f93\u5165\uff08\u6bd4\u5982 [open, high, low, close]\uff09\u3002<\/p>\n\n\n\n<p># \u7b2c\u4e8c\u5c42\u5904\u7406\u7b2c\u4e00\u5c42\u7684\u8f93\u51fa\u3002<\/p>\n\n\n\n<p># \u7b2c\u4e09\u5c42\u5904\u7406\u7b2c\u4e8c\u5c42\u7684\u8f93\u51fa\u3002<\/p>\n\n\n\n<p># \u6bcf\u5c42\u7684\u9690\u85cf\u72b6\u6001\u7ef4\u5ea6\u90fd\u662f hidden_dim\uff0864\uff09\u3002<\/p>\n\n\n\n<p>output_dim = 1 &nbsp;# \u7531\u4e8e\u662f\u56de\u5f52\u4efb\u52a1\uff0c\u6700\u7ec8\u8f93\u51fa\u5c42\u5927\u5c0f\u4e3a1<\/p>\n\n\n\n<p># \u5982\u679c\u662f\u56de\u5f52\u4efb\u52a1\uff08\u9884\u6d4b\u4e00\u4e2a\u8fde\u7eed\u503c\uff09\uff0c\u901a\u5e38\u8f93\u51fa\u7ef4\u5ea6\u5c31\u662f 1\u3002<\/p>\n\n\n\n<p># \u5982\u679c\u662f\u5206\u7c7b\u4efb\u52a1\uff08\u6bd4\u5982\u9884\u6d4b\u6da8\u8dcc\uff09\uff0c\u8f93\u51fa\u7ef4\u5ea6\u53ef\u80fd\u662f\u7c7b\u522b\u6570\uff08\u6bd4\u5982 2 \u6216\u66f4\u591a\uff09\u3002<\/p>\n\n\n\n<p># \u76ee\u6807\u53d8\u91cf\uff08\u4f60\u8981\u9884\u6d4b\u7684\u4e1c\u897f\uff09\uff1a<\/p>\n\n\n\n<p># \u5982\u679c\u76ee\u6807\u662f \u8fde\u7eed\u503c\uff08\u53ef\u4ee5\u65e0\u9650\u53d6\u503c\uff0c\u6bd4\u5982\u4ef7\u683c\u3001\u6e29\u5ea6\u3001\u957f\u5ea6\uff09 \u2192 \u56de\u5f52\u4efb\u52a1\u7ebf\u6027\u56de\u5f52\u7528\u4e8e\u56de\u5f52<\/p>\n\n\n\n<p># \u5982\u679c\u76ee\u6807\u662f \u79bb\u6563\u7c7b\u522b\uff08\u6709\u9650\u4e2a\u6807\u7b7e\uff0c\u6bd4\u5982\u6da8\u8dcc\u3001\u732b\u72d7\u3001\u4eba\u7fa4\u5206\u7c7b\uff09 \u2192 \u5206\u7c7b\u4efb\u52a1\u903b\u8f91\u56de\u5f52<\/p>\n\n\n\n<p>num_layers = 3 &nbsp;# LSTM\u7684\u5c42\u6570<\/p>\n\n\n\n<p># \u5355\u5c42 LSTM \u53ef\u4ee5\u6355\u6349\u65f6\u95f4\u5e8f\u5217\u7684\u57fa\u672c\u6a21\u5f0f\uff0c\u4f46\u53ef\u80fd\u4e0d\u8db3\u4ee5\u5b66\u4e60\u590d\u6742\u7684\u957f\u671f\u4f9d\u8d56\u3002<\/p>\n\n\n\n<p># \u591a\u5c42 LSTM\uff08\u5806\u53e0 LSTM\uff09\uff1a<\/p>\n\n\n\n<p># \u7b2c\u4e00\u5c42\u63d0\u53d6\u4f4e\u7ea7\u65f6\u95f4\u7279\u5f81\uff08\u6bd4\u5982\u77ed\u671f\u6ce2\u52a8\uff09\u3002<\/p>\n\n\n\n<p># \u7b2c\u4e8c\u5c42\u63d0\u53d6\u66f4\u62bd\u8c61\u7684\u6a21\u5f0f\uff08\u6bd4\u5982\u8d8b\u52bf\uff09\u3002<\/p>\n\n\n\n<p># \u7b2c\u4e09\u5c42\u8fdb\u4e00\u6b65\u6574\u5408\u4fe1\u606f\uff0c\u6355\u6349\u66f4\u590d\u6742\u7684\u5173\u7cfb\u3002<\/p>\n\n\n\n<p># \u7c7b\u4f3c\u4e8e CNN \u5806\u53e0\u5377\u79ef\u5c42\uff0c\u6df1\u5ea6\u589e\u52a0\u53ef\u4ee5\u5b66\u4e60\u66f4\u590d\u6742\u7684\u7279\u5f81\u3002<\/p>\n\n\n\n<p># \u7ecf\u9a8c\u503c\uff1a<\/p>\n\n\n\n<p># 1~3 \u5c42\u662f\u5e38\u89c1\u9009\u62e9\uff0c\u8d85\u8fc7 3 \u5c42\u9700\u8981\u66f4\u591a\u6570\u636e\u548c\u6b63\u5219\u5316\uff0c\u5426\u5219\u5bb9\u6613\u8fc7\u62df\u5408\u3002<\/p>\n\n\n\n<p>epochs = 10<\/p>\n\n\n\n<p>best_loss = 0<\/p>\n\n\n\n<p># \u6bcf\u4e00\u8f6e\uff08epoch\uff09\u6a21\u578b\u4f1a\u904d\u5386\u6240\u6709\u8bad\u7ec3\u6570\u636e\uff0c\u66f4\u65b0\u53c2\u6570\u3002<\/p>\n\n\n\n<p># \u4e00\u6b21\u904d\u5386\u901a\u5e38\u4e0d\u8db3\u4ee5\u8ba9\u6a21\u578b\u6536\u655b\uff08\u5b66\u5230\u89c4\u5f8b\uff09\uff0c\u6240\u4ee5\u8981\u591a\u6b21\u8fed\u4ee3\u3002<\/p>\n\n\n\n<p># \u6bcf\u6b21\u8fed\u4ee3\uff0c\u6a21\u578b\u901a\u8fc7 \u68af\u5ea6\u4e0b\u964d \u8c03\u6574\u53c2\u6570\uff0c\u4f7f\u635f\u5931\u51fd\u6570\u9010\u6e10\u51cf\u5c0f\u3002<\/p>\n\n\n\n<p># 1 \u4e2a epoch = \u6240\u6709\u8bad\u7ec3\u6837\u672c\u90fd\u88ab\u7528\u6765\u8bad\u7ec3\u4e00\u6b21\u3002<\/p>\n\n\n\n<p># \u5982\u679c batch_size = 16\uff0c\u8bad\u7ec3\u96c6\u6709 1600 \u4e2a\u6837\u672c\uff1a<\/p>\n\n\n\n<p># \u6bcf\u4e2a epoch \u4f1a\u5206\u6210 1600 \/ 16 = 100 \u4e2a batch\u3002<\/p>\n\n\n\n<p># \u6bcf\u4e2a batch \u66f4\u65b0\u4e00\u6b21\u53c2\u6570\u3002<\/p>\n\n\n\n<p># \u6b20\u62df\u5408\uff1a\u6a21\u578b\u592a\u7b80\u5355\u6216\u8bad\u7ec3\u4e0d\u591f \u2192 \u5b66\u4e0d\u5230\u89c4\u5f8b<\/p>\n\n\n\n<p># \u8fc7\u62df\u5408\uff1a\u6a21\u578b\u592a\u590d\u6742\u6216\u8bad\u7ec3\u592a\u4e45 \u2192 \u8bb0\u4f4f\u8bad\u7ec3\u96c6\uff0c\u6cdb\u5316\u80fd\u529b\u5dee<\/p>\n\n\n\n<p>model_name = &#8216;LSTM&#8217;<\/p>\n\n\n\n<p>save_path = &#8216;.\/{}.pth&#8217;.format(model_name)#\u5b9a\u4e49\u6a21\u578b\u540d\u79f0\u5e76\u8bbe\u7f6e\u6a21\u578b\u4fdd\u5b58\u8def\u5f84<\/p>\n\n\n\n<p># 1.\u52a0\u8f7d\u80a1\u7968\u6570\u636e<\/p>\n\n\n\n<p>pro = ts.pro_api(&#8216;f89befcaababe24c69c6e4cfb0614e45b43e2c1e95709f9ad6bb2598&#8217;)<\/p>\n\n\n\n<p>df = pro.daily(ts_code=&#8217;000001.SZ&#8217;, start_date=&#8217;20130711&#8242;, end_date=&#8217;20220711&#8242;)<\/p>\n\n\n\n<p># \u8c03\u7528 TuShare \u7684 \u65e5\u7ebf\u884c\u60c5\u63a5\u53e3\uff0c\u83b7\u53d6\u80a1\u7968\u6bcf\u5929\u7684\u4ea4\u6613\u6570\u636e\u3002<\/p>\n\n\n\n<p># \u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n\n\n\n<p># ts_code=&#8217;000001.SZ&#8217;\uff1a\u80a1\u7968\u4ee3\u7801\uff0c\u8fd9\u91cc\u662f \u5e73\u5b89\u94f6\u884c\uff08\u6df1\u5733\u4ea4\u6613\u6240\uff09\u3002<\/p>\n\n\n\n<p># start_date=&#8217;20130711&#8217;\uff1a\u5f00\u59cb\u65e5\u671f\uff082013\u5e747\u670811\u65e5\uff09\u3002<\/p>\n\n\n\n<p># end_date=&#8217;20220711&#8217;\uff1a\u7ed3\u675f\u65e5\u671f\uff082022\u5e747\u670811\u65e5\uff09\u3002<\/p>\n\n\n\n<p># \u8fd4\u56de\u503c\uff1a\u4e00\u4e2a DataFrame\uff0c\u5305\u542b\u6bcf\u5929\u7684\u5f00\u76d8\u4ef7\u3001\u6536\u76d8\u4ef7\u3001\u6700\u9ad8\u4ef7\u3001\u6700\u4f4e\u4ef7\u3001\u6210\u4ea4\u91cf\u7b49\u3002<\/p>\n\n\n\n<p>pro.daily()<\/p>\n\n\n\n<p>df.index = pd.to_datetime(df.trade_date) &nbsp;# \u7d22\u5f15\u8f6c\u4e3a\u65e5\u671f<\/p>\n\n\n\n<p>df = df.iloc[::-1] &nbsp;# \u7531\u4e8e\u83b7\u53d6\u7684\u6570\u636e\u662f\u5012\u5e8f\u7684\uff0c\u9700\u8981\u5c06\u5176\u8c03\u6574\u4e3a\u6b63\u5e8f<\/p>\n\n\n\n<p># \u628a trade_date\uff08\u539f\u672c\u662f\u5b57\u7b26\u4e32\uff09\u8f6c\u6362\u6210 datetime \u7c7b\u578b\uff0c\u5e76\u8bbe\u4e3a\u7d22\u5f15\uff0c\u65b9\u4fbf\u540e\u7eed\u6309\u65f6\u95f4\u5904\u7406\u3002<\/p>\n\n\n\n<p># TuShare \u8fd4\u56de\u7684\u6570\u636e\u9ed8\u8ba4\u662f \u6700\u65b0\u65e5\u671f\u5728\u524d\uff08\u5012\u5e8f\uff09\uff0c\u4e3a\u4e86\u8bad\u7ec3\u6a21\u578b\uff0c\u901a\u5e38\u9700\u8981 \u65f6\u95f4\u6b63\u5e8f\uff08\u6700\u65e9\u65e5\u671f\u5728\u524d\uff09\uff0c\u6240\u4ee5\u7528 iloc[::-1] \u7ffb\u8f6c\u3002<\/p>\n\n\n\n<p># 2.\u5c06\u6570\u636e\u8fdb\u884c\u6807\u51c6\u5316<\/p>\n\n\n\n<p>scaler = StandardScaler()<\/p>\n\n\n\n<p>scaler_model = StandardScaler()<\/p>\n\n\n\n<p>data = scaler_model.fit_transform(np.array(df[[&#8216;open&#8217;, &#8216;high&#8217;, &#8216;low&#8217;, &#8216;close&#8217;]]).reshape(-1, 4))<\/p>\n\n\n\n<p>scaler.fit_transform(np.array(df[&#8216;close&#8217;]).reshape(-1, 1))<\/p>\n\n\n\n<p># \u521b\u5efa\u4e00\u4e2a StandardScaler \u5bf9\u8c61\uff0c\u7528\u4e8e\u6807\u51c6\u5316 \u76ee\u6807\u53d8\u91cf\uff08\u6536\u76d8\u4ef7\uff09\u3002<\/p>\n\n\n\n<p># StandardScaler \u4f1a\u628a\u6570\u636e\u8f6c\u6362\u4e3a\u5747\u503c 0\u3001\u65b9\u5dee 1 \u7684\u5206\u5e03\uff0c\u516c\u5f0f\uff1a<\/p>\n\n\n\n<p># x\u2032=x\u2212\u03bc\u200b\/\u03c3<\/p>\n\n\n\n<p># \u5176\u4e2d \u03bc \u662f\u5747\u503c\uff0c\u03c3\u662f\u6807\u51c6\u5dee\u3002<\/p>\n\n\n\n<p># \u518d\u521b\u5efa\u4e00\u4e2a StandardScaler \u5bf9\u8c61\uff0c\u7528\u4e8e\u6807\u51c6\u5316 \u8f93\u5165\u7279\u5f81\uff08open\u3001high\u3001low\u3001close\uff09\u3002<\/p>\n\n\n\n<p># \u4e3a\u4ec0\u4e48\u8981\u4e24\u4e2a\uff1f<\/p>\n\n\n\n<p># \u4e00\u4e2a\u7528\u4e8e\u8f93\u5165\u7279\u5f81\uff0c\u4e00\u4e2a\u7528\u4e8e\u8f93\u51fa\u76ee\u6807\uff0c\u65b9\u4fbf\u540e\u7eed\u53cd\u5411\u8f6c\u6362\uff08inverse_transform\uff09\u3002<\/p>\n\n\n\n<p># \u4ece df \u4e2d\u53d6\u51fa\u56db\u4e2a\u7279\u5f81\u5217\uff1aopen\u3001high\u3001low\u3001close\u3002<\/p>\n\n\n\n<p># \u8f6c\u6362\u6210 NumPy \u6570\u7ec4\uff0c\u5e76 reshape \u6210 (\u6837\u672c\u6570, 4)\u3002<\/p>\n\n\n\n<p># \u7528 scaler_model \u6807\u51c6\u5316\u8fd9\u4e9b\u7279\u5f81\u3002<\/p>\n\n\n\n<p># data \u662f\u4e00\u4e2a\u6807\u51c6\u5316\u540e\u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u6bcf\u884c\u5bf9\u5e94\u4e00\u5929\u7684\u56db\u4e2a\u7279\u5f81\u3002<\/p>\n\n\n\n<p># \u4ece df \u4e2d\u53d6\u51fa close\uff08\u6536\u76d8\u4ef7\uff09\u3002<\/p>\n\n\n\n<p># \u8f6c\u6362\u6210\u4e8c\u7ef4\u6570\u7ec4 (\u6837\u672c\u6570, 1)\u3002<\/p>\n\n\n\n<p># \u7528 scaler \u6807\u51c6\u5316\u6536\u76d8\u4ef7\u3002<\/p>\n\n\n\n<p># \u4e3a\u4ec0\u4e48\u8981\u5355\u72ec\u5904\u7406\u6536\u76d8\u4ef7\uff1f<\/p>\n\n\n\n<p># \u56e0\u4e3a\u5b83\u662f\u9884\u6d4b\u76ee\u6807\uff0c\u540e\u7eed\u7ed8\u56fe\u6216\u8bc4\u4f30\u65f6\u9700\u8981\u53cd\u6807\u51c6\u5316\uff08\u6062\u590d\u539f\u59cb\u4ef7\u683c\uff09\u3002<\/p>\n\n\n\n<p># \u5f62\u6210\u8bad\u7ec3\u6570\u636e\uff0c\u4f8b\u598212345\u53d8\u621012-3\uff0c23-4\uff0c34-5<\/p>\n\n\n\n<p>def split_data(data, timestep):<\/p>\n\n\n\n<p>&nbsp; &nbsp; dataX = [] &nbsp;# \u4fdd\u5b58X<\/p>\n\n\n\n<p>&nbsp; &nbsp; dataY = [] &nbsp;# \u4fdd\u5b58Y<\/p>\n\n\n\n<p>&nbsp; &nbsp; # dataX\uff1a\u4fdd\u5b58\u6bcf\u4e2a\u6837\u672c\u7684\u8f93\u5165\u5e8f\u5217\uff08\u4f8b\u5982\u8fc7\u53bb\u51e0\u5929\u7684\u7279\u5f81\uff09<\/p>\n\n\n\n<p>&nbsp; &nbsp; # dataY\uff1a\u4fdd\u5b58\u6bcf\u4e2a\u6837\u672c\u5bf9\u5e94\u7684\u9884\u6d4b\u76ee\u6807\uff08\u4f8b\u5982\u4e0b\u4e00\u5929\u7684\u6536\u76d8\u4ef7\uff09<\/p>\n\n\n\n<p>&nbsp; &nbsp; # \u5c06\u6574\u4e2a\u7a97\u53e3\u7684\u6570\u636e\u4fdd\u5b58\u5230X\u4e2d\uff0c\u5c06\u672a\u6765\u4e00\u5929\u4fdd\u5b58\u5230Y\u4e2d<\/p>\n\n\n\n<p>&nbsp; &nbsp; for index in range(len(data) &#8211; timestep):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; dataX.append(data[index: index + timestep])<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; dataY.append(data[index + timestep][3])<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; data[index: index + timestep]<\/p>\n\n\n\n<p># \u53d6\u51fa\u4e00\u4e2a\u65f6\u95f4\u7a97\u53e3\u7684\u6570\u636e\uff08\u4f8b\u5982\u8fc7\u53bb1\u5929\u3001\u8fc7\u53bb30\u5929\uff09<\/p>\n\n\n\n<p># data[index + timestep][3]\uff1a\u53d6\u51fa\u65f6\u95f4\u7a97\u53e3\u4e4b\u540e\u4e00\u5929\u7684\u7b2c4\u4e2a\u7279\u5f81\uff08\u5373\u6536\u76d8\u4ef7\uff09<\/p>\n\n\n\n<p>&nbsp; &nbsp; dataX = np.array(dataX)<\/p>\n\n\n\n<p>&nbsp; &nbsp; dataY = np.array(dataY)<\/p>\n\n\n\n<p># \u628a Python \u7684\u5217\u8868\u8f6c\u6362\u6210 NumPy \u6570\u7ec4<\/p>\n\n\n\n<p>&nbsp; &nbsp; # \u83b7\u53d6\u8bad\u7ec3\u96c6\u5927\u5c0f 80%\u8bad\u7ec3\u96c6 round\u6362\u6210\u6574\u6570 \u7ed3\u679cint\u6574\u6570<\/p>\n\n\n\n<p>&nbsp; &nbsp; train_size = int(np.round(0.8 * dataX.shape[0]))<\/p>\n\n\n\n<p>&nbsp; &nbsp; # \u5212\u5206\u8bad\u7ec3\u96c6\u3001\u6d4b\u8bd5\u96c6<\/p>\n\n\n\n<p>&nbsp; &nbsp; x_train = dataX[: train_size, :].reshape(-1, timestep, 4)<\/p>\n\n\n\n<p>&nbsp; &nbsp; y_train = dataY[: train_size]<\/p>\n\n\n\n<p>&nbsp; &nbsp; x_test = dataX[train_size:, :].reshape(-1, timestep, 4)<\/p>\n\n\n\n<p>&nbsp; &nbsp; y_test = dataY[train_size:]<\/p>\n\n\n\n<p>&nbsp; &nbsp; return [x_train, y_train, x_test, y_test]<\/p>\n\n\n\n<p># dataX[: train_size, :]\uff1a\u53d6\u524d train_size \u4e2a\u6837\u672c\u4f5c\u4e3a\u8bad\u7ec3\u96c6\u7684\u8f93\u5165\u6570\u636e\u3002<\/p>\n\n\n\n<p># .reshape(-1, timestep, 4)\uff1a\u628a\u6570\u636e\u91cd\u65b0\u8c03\u6574\u6210 LSTM \u6240\u9700\u7684\u4e09\u7ef4\u683c\u5f0f\uff1a<\/p>\n\n\n\n<p># -1 \u8868\u793a\u81ea\u52a8\u8ba1\u7b97\u6837\u672c\u6570\u91cf\uff1b<\/p>\n\n\n\n<p># timestep \u662f\u65f6\u95f4\u6b65\u957f\uff081\uff09\uff1b<\/p>\n\n\n\n<p># 4 \u662f\u6bcf\u4e2a\u65f6\u95f4\u6b65\u7684\u7279\u5f81\u6570\u91cf\uff08open\u3001high\u3001low\u3001close\uff09\u3002<\/p>\n\n\n\n<p># # 3.\u83b7\u53d6\u8bad\u7ec3\u6570\u636e &nbsp; x_train: 1700,1,4<\/p>\n\n\n\n<p>x_train, y_train, x_test, y_test = split_data(data, timestep)<\/p>\n\n\n\n<p># 4.\u5c06\u6570\u636e\u8f6c\u4e3atensor<\/p>\n\n\n\n<p>x_train_tensor = torch.from_numpy(x_train).to(torch.float32)<\/p>\n\n\n\n<p>y_train_tensor = torch.from_numpy(y_train).to(torch.float32)<\/p>\n\n\n\n<p>x_test_tensor = torch.from_numpy(x_test).to(torch.float32)<\/p>\n\n\n\n<p>y_test_tensor = torch.from_numpy(y_test).to(torch.float32)<\/p>\n\n\n\n<p># 1. torch.from_numpy(&#8230;)<\/p>\n\n\n\n<p># \u628a NumPy \u6570\u7ec4\uff08\u5982 x_train\uff09\u8f6c\u6362\u6210 PyTorch \u7684\u5f20\u91cf\u3002<\/p>\n\n\n\n<p># NumPy \u662f Python \u4e2d\u5904\u7406\u6570\u636e\u7684\u6807\u51c6\u5de5\u5177\uff0c\u4f46 PyTorch \u6a21\u578b\u4e0d\u80fd\u76f4\u63a5\u7528 NumPy \u6570\u636e\u3002<\/p>\n\n\n\n<p># 2. .to(torch.float32)<\/p>\n\n\n\n<p># \u628a\u5f20\u91cf\u7684\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u6210 float32\uff0832\u4f4d\u6d6e\u70b9\u6570\uff09\uff0c\u8fd9\u662f\u6df1\u5ea6\u5b66\u4e60\u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n\n\n\n<p># \u5982\u679c\u4e0d\u8f6c\u6362\uff0c\u6709\u53ef\u80fd\u4f1a\u62a5\u9519\u6216\u5bfc\u81f4\u6a21\u578b\u8bad\u7ec3\u4e0d\u7a33\u5b9a\u3002<\/p>\n\n\n\n<p># 5.\u5f62\u6210\u8bad\u7ec3\u6570\u636e\u96c6<\/p>\n\n\n\n<p>train_data = TensorDataset(x_train_tensor, y_train_tensor)<\/p>\n\n\n\n<p>test_data = TensorDataset(x_test_tensor, y_test_tensor)<\/p>\n\n\n\n<p># 6.\u5c06\u6570\u636e\u52a0\u8f7d\u6210\u8fed\u4ee3\u5668<\/p>\n\n\n\n<p>train_loader = torch.utils.data.DataLoader(train_data,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;batch_size,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;True)<\/p>\n\n\n\n<p>test_loader = torch.utils.data.DataLoader(test_data,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; batch_size,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; False)<\/p>\n\n\n\n<p># train_data\uff1a\u4f60\u4e4b\u524d\u7528 TensorDataset \u5c01\u88c5\u597d\u7684\u8bad\u7ec3\u6570\u636e\uff08\u5305\u542b\u8f93\u5165\u548c\u6807\u7b7e\uff09\u3002<\/p>\n\n\n\n<p># batch_size\uff1a\u6bcf\u6b21\u8bad\u7ec3\u5904\u7406\u591a\u5c11\u4e2a\u6837\u672c\uff08\u4f60\u8bbe\u7f6e\u7684\u662f 16\uff09\u3002<\/p>\n\n\n\n<p># True\uff1a\u8868\u793a\u5728\u6bcf\u4e2a epoch \u4e2d \u6253\u4e71\u6570\u636e\u987a\u5e8f\uff08shuffle\uff09\uff0c\u6709\u52a9\u4e8e\u63d0\u9ad8\u6a21\u578b\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n\n\n\n<p># DataLoader<\/p>\n\n\n\n<p># \u81ea\u52a8\u5206\u6279\u5904\u7406\u6570\u636e\uff1a\u4e0d\u7528\u624b\u52a8\u5199\u5faa\u73af\u6765\u5206\u5272\u6570\u636e\u3002<\/p>\n\n\n\n<p># \u652f\u6301\u6253\u4e71\u6570\u636e\u987a\u5e8f\uff1a\u8bad\u7ec3\u65f6\u6253\u4e71\u6570\u636e\u53ef\u4ee5\u9632\u6b62\u6a21\u578b\u8bb0\u4f4f\u6570\u636e\u987a\u5e8f\uff0c\u63d0\u5347\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n\n\n\n<p># \u63d0\u9ad8\u6548\u7387\uff1a\u53ef\u4ee5\u7ed3\u5408 GPU \u5e76\u884c\u5904\u7406\uff0c\u63d0\u5347\u8bad\u7ec3\u901f\u5ea6\u3002<\/p>\n\n\n\n<p># \u7edf\u4e00\u63a5\u53e3\uff1a\u8bad\u7ec3\u548c\u6d4b\u8bd5\u90fd\u53ef\u4ee5\u7528\u76f8\u540c\u7684\u65b9\u5f0f\u8fed\u4ee3\u6570\u636e<\/p>\n\n\n\n<p># 7.\u5b9a\u4e49LSTM\u7f51\u7edc<\/p>\n\n\n\n<p>class LSTM(nn.Module):<\/p>\n\n\n\n<p>&nbsp; &nbsp; def __init__(self, input_dim, hidden_dim, num_layers, output_dim):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; super(LSTM, self).__init__()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.hidden_dim = hidden_dim &nbsp;# \u9690\u5c42\u5927\u5c0f<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.num_layers = num_layers &nbsp;# LSTM\u5c42\u6570<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; # input_dim\u4e3a\u7279\u5f81\u7ef4\u5ea6\uff0c\u5c31\u662f\u6bcf\u4e2a\u65f6\u95f4\u70b9\u5bf9\u5e94\u7684\u7279\u5f81\u6570\u91cf\uff0c\u8fd9\u91cc\u4e3a4<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.lstm = nn.LSTM(input_dim, hidden_dim, num_layers, batch_first=True)#batch_first=True \u8868\u793a\u8f93\u5165\u7684\u5f62\u72b6\u662f (batch_size, time_step, input_dim)\u3002<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.fc = nn.Linear(hidden_dim, output_dim)<\/p>\n\n\n\n<p>#\u521b\u5efa\u4e00\u4e2a\u5168\u8fde\u63a5\u5c42\uff0c\u7528\u4e8e\u5c06 LSTM \u7684\u8f93\u51fa\u6620\u5c04\u5230\u6700\u7ec8\u7684\u9884\u6d4b\u503c<\/p>\n\n\n\n<p>&nbsp; &nbsp; def forward(self, x):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; output, (h_n, c_n) = self.lstm(x) &nbsp;# output\u4e3a\u6240\u6709\u65f6\u95f4\u7247\u7684\u8f93\u51fa\uff0c\u5f62\u72b6\u4e3a\uff1a16,1,4<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; # print(output.shape) torch.Size([16, 1, 64]) batch_size,timestep,hidden_dim<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; # print(h_n.shape) torch.Size([3, 16, 64]) num_layers,batch_size,hidden_dim<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; # print(c_n.shape) torch.Size([3, 16, 64]) num_layers,batch_size,hidden_dim<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; batch_size, timestep, hidden_dim = output.shape<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; # \u5c06output\u53d8\u6210 batch_size * timestep, hidden_dim<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; output = output.reshape(-1, hidden_dim)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; output = self.fc(output) &nbsp;# \u5f62\u72b6\u4e3abatch_size * timestep, 1<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; output = output.reshape(timestep, batch_size, -1)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; return output[-1] &nbsp;# \u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u65f6\u95f4\u7247\u7684\u8f93\u51fa<\/p>\n\n\n\n<p># \u628a LSTM \u7684\u8f93\u51fa reshape \u6210\u9002\u5408\u5168\u8fde\u63a5\u5c42\u7684\u683c\u5f0f\u3002<\/p>\n\n\n\n<p># \u7528 fc \u5c42\u5f97\u5230\u9884\u6d4b\u7ed3\u679c\u3002<\/p>\n\n\n\n<p># \u6700\u540e\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u65f6\u95f4\u6b65\u7684\u8f93\u51fa\u4f5c\u4e3a\u9884\u6d4b\u503c\u3002<\/p>\n\n\n\n<p>model = LSTM(input_dim, hidden_dim, num_layers, output_dim) &nbsp;# \u5b9a\u4e49LSTM\u7f51\u7edc<\/p>\n\n\n\n<p>loss_function = nn.MSELoss() &nbsp;# \u5b9a\u4e49\u635f\u5931\u51fd\u6570<\/p>\n\n\n\n<p>optimizer = torch.optim.Adam(model.parameters(), lr=0.01) &nbsp;# \u5b9a\u4e49\u4f18\u5316\u5668<\/p>\n\n\n\n<p># 8.\u6a21\u578b\u8bad\u7ec3<\/p>\n\n\n\n<p>for epoch in range(epochs):<\/p>\n\n\n\n<p># epochs \u662f\u4f60\u8bbe\u7f6e\u7684\u8bad\u7ec3\u8f6e\u6570\uff08\u6bd4\u5982 10\uff09\uff0c\u6bcf\u4e00\u8f6e\u90fd\u4f1a\u904d\u5386\u6574\u4e2a\u8bad\u7ec3\u96c6\u4e00\u6b21\u3002<\/p>\n\n\n\n<p># \u591a\u8f6e\u8bad\u7ec3\u53ef\u4ee5\u8ba9\u6a21\u578b\u9010\u6e10\u5b66\u4e60\u6570\u636e\u4e2d\u7684\u89c4\u5f8b\u3002<\/p>\n\n\n\n<p>&nbsp; &nbsp; model.train()<\/p>\n\n\n\n<p>&nbsp; &nbsp; running_loss = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; train_bar = tqdm(train_loader) &nbsp;# \u5f62\u6210\u8fdb\u5ea6\u6761<\/p>\n\n\n\n<p>&nbsp; &nbsp; for data in train_bar:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; x_train, y_train = data &nbsp;# \u89e3\u5305\u8fed\u4ee3\u5668\u4e2d\u7684X\u548cY<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; optimizer.zero_grad()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; y_train_pred = model(x_train)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; loss = loss_function(y_train_pred, y_train.reshape(-1, 1))<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; loss.backward()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; optimizer.step()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; running_loss += loss.item()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; train_bar.desc = &#8220;train epoch[{}\/{}] loss:{:.3f}&#8221;.format(epoch + 1,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;epochs,<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;loss)<\/p>\n\n\n\n<p># x_train, y_train = data\uff1a\u4ece DataLoader \u4e2d\u53d6\u51fa\u4e00\u4e2a batch \u7684\u6570\u636e\u3002<\/p>\n\n\n\n<p># optimizer.zero_grad()\uff1a\u6e05\u9664\u4e0a\u4e00\u6b21\u7684\u68af\u5ea6\u3002<\/p>\n\n\n\n<p># model(x_train)\uff1a\u524d\u5411\u4f20\u64ad\uff0c\u5f97\u5230\u9884\u6d4b\u503c\u3002<\/p>\n\n\n\n<p># loss_function(&#8230;)\uff1a\u8ba1\u7b97\u9884\u6d4b\u503c\u4e0e\u771f\u5b9e\u503c\u4e4b\u95f4\u7684\u8bef\u5dee\uff08MSE\uff09\u3002<\/p>\n\n\n\n<p># loss.backward()\uff1a\u53cd\u5411\u4f20\u64ad\uff0c\u8ba1\u7b97\u68af\u5ea6\u3002<\/p>\n\n\n\n<p># optimizer.step()\uff1a\u66f4\u65b0\u6a21\u578b\u53c2\u6570\u3002<\/p>\n\n\n\n<p>&nbsp; &nbsp; # \u6a21\u578b\u9a8c\u8bc1<\/p>\n\n\n\n<p>&nbsp; &nbsp; model.eval()<\/p>\n\n\n\n<p>&nbsp; &nbsp; test_loss = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; with torch.no_grad():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; test_bar = tqdm(test_loader)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for data in test_bar:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x_test, y_test = data<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y_test_pred = model(x_test)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; test_loss = loss_function(y_test_pred, y_test.reshape(-1, 1))<\/p>\n\n\n\n<p>&nbsp; &nbsp; if test_loss &lt; best_loss:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; best_loss = test_loss<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; torch.save(model.state_dict(), save_path)<\/p>\n\n\n\n<p># \u5982\u679c\u5f53\u524d\u9a8c\u8bc1\u635f\u5931\u6bd4\u4e4b\u524d\u7684\u6700\u597d\u7ed3\u679c\u8fd8\u4f4e\uff0c\u5c31\u4fdd\u5b58\u6a21\u578b\u53c2\u6570\u3002<\/p>\n\n\n\n<p># model.state_dict() \u662f\u6a21\u578b\u7684\u53c2\u6570\u5b57\u5178\u3002<\/p>\n\n\n\n<p># save_path \u662f\u4f60\u8bbe\u7f6e\u7684\u4fdd\u5b58\u8def\u5f84\u3002<\/p>\n\n\n\n<p>#\u8bad\u7ec3\u96c6\u7528\u4e8e\u201c\u5b66\u4e60\u201d\u6a21\u578b\u53c2\u6570\uff0c\u800c \u6d4b\u8bd5\u96c6\u7528\u4e8e\u201c\u8bc4\u4f30\u201d\u6a21\u578b\u6548\u679c\uff0c\u4e0d\u53c2\u4e0e\u5b66\u4e60\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p>print(&#8216;Finished Training&#8217;)<\/p>\n\n\n\n<p># 9.\u7ed8\u5236\u7ed3\u679c<\/p>\n\n\n\n<p>plt.figure(figsize=(12, 8))<\/p>\n\n\n\n<p>plt.plot(scaler.inverse_transform((model(x_train_tensor).detach().numpy()).reshape(-1, 1)), &#8220;b&#8221;)<\/p>\n\n\n\n<p>plt.plot(scaler.inverse_transform(y_train_tensor.detach().numpy().reshape(-1, 1)), &#8220;r&#8221;)<\/p>\n\n\n\n<p>plt.legend()<\/p>\n\n\n\n<p>plt.show()<\/p>\n\n\n\n<p>y_test_pred = model(x_test_tensor)<\/p>\n\n\n\n<p>plt.figure(figsize=(12, 8))<\/p>\n\n\n\n<p>plt.plot(scaler.inverse_transform(y_test_pred.detach().numpy()), &#8220;b&#8221;)<\/p>\n\n\n\n<p>plt.plot(scaler.inverse_transform(y_test_tensor.detach().numpy().reshape(-1, 1)), &#8220;r&#8221;)<\/p>\n\n\n\n<p>plt.legend()<\/p>\n\n\n\n<p>plt.show()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>import matplotlib.pyplot as plt import numpy as np impo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/comments?post=357"}],"version-history":[{"count":1,"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":358,"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/posts\/357\/revisions\/358"}],"wp:attachment":[{"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/media?parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/categories?post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/snaili.com\/index.php\/wp-json\/wp\/v2\/tags?post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}