{"id":1518,"date":"2024-09-19T07:49:00","date_gmt":"2024-09-18T23:49:00","guid":{"rendered":"https:\/\/blog.laoyulaoyu.top\/?p=1518"},"modified":"2024-09-20T21:03:46","modified_gmt":"2024-09-20T13:03:46","slug":"%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e4%bc%9a%e4%bd%a0%e7%94%a8-ai-%e5%92%8c-python-%e8%bf%9b%e8%a1%8c%e8%82%a1%e7%a5%a8%e4%ba%a4%e6%98%93%e9%a2%84%e6%b5%8b%ef%bc%88%e5%ae%8c%e6%95%b4%e4%bb%a3","status":"publish","type":"post","link":"https:\/\/laoyulaoyu.com\/index.php\/2024\/09\/19\/%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e4%bc%9a%e4%bd%a0%e7%94%a8-ai-%e5%92%8c-python-%e8%bf%9b%e8%a1%8c%e8%82%a1%e7%a5%a8%e4%ba%a4%e6%98%93%e9%a2%84%e6%b5%8b%ef%bc%88%e5%ae%8c%e6%95%b4%e4%bb%a3\/","title":{"rendered":"\u624b\u628a\u624b\u6559\u4f1a\u4f60\u7528\u00a0AI \u548c Python \u8fdb\u884c\u80a1\u7968\u4ea4\u6613\u9884\u6d4b\uff08\u5b8c\u6574\u4ee3\u7801\u5e72\u8d27\uff09"},"content":{"rendered":"\n<p>\u4f5c\u8005\uff1a<a href=\"https:\/\/www.laoyulaoyu.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u8001\u4f59\u635e\u9c7c<\/a><\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-cyan-bluish-gray-color\">\u539f\u521b\u4e0d\u6613\uff0c\u8f6c\u8f7d\u8bf7\u6807\u660e\u51fa\u5904\u53ca\u539f\u4f5c\u8005\u3002<\/mark><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.laoyulaoyu.com\/wp-content\/uploads\/2024\/09\/image-165.png\" alt=\"\" class=\"wp-image-2123\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-verse\"><strong>\u5199\u5728\u524d\u9762\u7684\u8bdd\uff1a<\/strong>\u672c\u6587<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">\u624b\u628a\u624b\u6559\u4f1a\u5927\u5bb6\u4f7f\u7528 Python \u548c AI \u8fdb\u884c\u80a1\u7968\u4ea4\u6613\u9884\u6d4b\u3002<\/mark>\u9996\u5148\u4ecb\u7ecd\u4e86\u4e0d\u540c\u7684\u9884\u6d4b\u65b9\u6cd5\uff0c\u7279\u522b\u662f LSTM \u5904\u7406\u5e8f\u5217\u9884\u6d4b\u7684\u80fd\u529b\u3002\u7136\u540e\u63d0\u4f9b\u4e86\u6982\u5ff5\u9a8c\u8bc1\u6b65\u9aa4\uff0c\u5305\u62ec\u5b89\u88c5\u3001\u521b\u5efa\u9879\u76ee\u7b49\uff0c\u8fd8\u5c55\u793a\u4ee3\u7801\u5efa\u7acb\uff0c\u5982\u5bfc\u5165\u5e93\u3001\u7528\u51fd\u6570\u8bad\u7ec3\u6d4b\u8bd5\u6a21\u578b\uff0c\u6700\u540e\u8fd8\u8bc4\u4f30\u4e86\u6a21\u578b\u7684\u6027\u80fd\u3002<\/pre>\n<\/blockquote>\n\n\n\n<p>\u6211\u4eec\u63a2\u5bfb\u4e86\u591a\u79cd\u9884\u6d4b\u80a1\u4ef7\u7684\u65b9\u5f0f\uff0c\u50cf Facebook \u7684 Prophet \u7b49\u9884\u6d4b\u5de5\u5177\u3001SARIMA \u6a21\u578b\u7b49\u7edf\u8ba1\u624b\u6bb5\u3001\u591a\u9879\u5f0f\u56de\u5f52\u7b49\u673a\u5668\u5b66\u4e60\u7b56\u7565\uff0c\u8fd8\u6709\u57fa\u4e8e\u4eba\u5de5\u667a\u80fd\u7684\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\uff08RNN\uff09\u3002\u5728\u4f17\u591a\u4eba\u5de5\u667a\u80fd\u6a21\u578b\u4e0e\u6280\u672f\u91cc\uff0c<strong>\u6211\u4eec\u53d1\u73b0\u957f\u77ed\u65f6\u8bb0\u5fc6\uff08LSTM\uff09\u6a21\u578b\u80fd\u5e26\u6765\u6700\u7406\u60f3\u7684\u7ed3\u679c\u3002<\/strong><\/p>\n\n\n\n<p>LSTM \u6a21\u578b\u662f\u9012\u5f52\u795e\u7ecf\u7f51\u7edc\u67b6\u6784\u7684\u4e00\u79cd\u53d8\u5f62\uff0c\u64c5\u957f\u5904\u7406\u5e8f\u5217\u9884\u6d4b\u96be\u9898\u3002\u5b83\u4e0e\u4f20\u7edf\u7684\u524d\u9988\u795e\u7ecf\u7f51\u7edc\u4e0d\u540c\uff0c\u5177\u6709\u7c7b\u4f3c\u8bb0\u5fc6\u7684\u7ed3\u6784\uff0c\u80fd\u5728\u5927\u91cf\u5e8f\u5217\u4e2d\u4fdd\u7559\u4e0a\u4e0b\u6587\u6570\u636e\u3002\u8fd9\u4e00\u7279\u6027\u4f7f\u5176\u975e\u5e38\u9002\u5408\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u3001\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4ee5\u53ca\u5176\u4ed6\u4f9d\u8d56\u5e8f\u5217\u6570\u636e\u7684\u4efb\u52a1\u3002\u5b83\u901a\u8fc7\u7f13\u89e3\u6d88\u5931\u548c\u68af\u5ea6\u7206\u70b8\u95ee\u9898\uff0c\u89e3\u51b3\u4e86\u6807\u51c6 RNN \u7684\u57fa\u672c\u7f3a\u9677\uff0c\u4ece\u800c\u63d0\u5347\u4e86\u6a21\u578b\u8bc6\u522b\u6570\u636e\u96c6\u5185\u957f\u671f\u4f9d\u8d56\u5173\u7cfb\u7684\u80fd\u529b\u3002\u56e0\u6b64\uff0cLSTM \u5df2\u6210\u4e3a\u9700\u8981\u957f\u65f6\u95f4\u6df1\u5165\u7406\u89e3\u6570\u636e\u7684\u590d\u6742\u4efb\u52a1\u7684\u9996\u9009\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u9a8c\u8bc1\u5176\u6709\u6548\u6027\uff0c\u6211\u4eec\u5f00\u53d1\u4e86\u4e00\u4e2a\u6982\u5ff5\u9a8c\u8bc1\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"52f5\"><strong>\u4e00\u3001\u51c6\u5907\u5de5\u4f5c<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f60\u9700\u8981\u5728\u4f60\u7684\u8ba1\u7b97\u673a\u4e2d\uff08<em>\u6216\u9009\u62e9\u4f7f\u7528&nbsp;<a href=\"https:\/\/code.visualstudio.com\/\">VSCode<\/a>&nbsp;\u4f1a\u66f4\u52a0\u65b9\u4fbf<\/em>\uff09\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684 Python \u548c PIP\u3002<\/li>\n\n\n\n<li>\u521b\u5efa\u4e00\u4e2a\u5e26\u6709 &#8220;main.py &#8220;\u6587\u4ef6\u7684 Python \u9879\u76ee\u3002<\/li>\n\n\n\n<li>\u5728\u9879\u76ee\u4e2d\u6dfb\u52a0 \u201cdata\u201d\u76ee\u5f55\u3002<\/li>\n\n\n\n<li>\u8bbe\u7f6e\u5e76\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>trading-ai-lstm $ python3 -m venv venv\ntrading-ai-lstm $ source venv\/.bin\/activate\n(venv) trading-ai-lstm $<\/code><\/pre>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a &#8220;requirements.txt &#8220;\u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pandas\nnumpy\nscikit-learn\nscipy\nmatplotlib\ntensorflow\neodhd\npython-dotenv<\/code><\/pre>\n\n\n\n<p>\u786e\u4fdd\u5df2\u5728\u865a\u62df\u73af\u5883\u4e2d\u5347\u7ea7 PIP \u5e76\u5b89\u88c5\u4f9d\u8d56\u9879\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(venv) trading-ai-lstm $ pip install --upgrade pip\n(venv) trading-ai-lstm $ python3 -m pip install -r requirements.txt<\/code><\/pre>\n\n\n\n<p id=\"1378\">\u9700\u8981\u5728&#8221;.env &#8220;\u6587\u4ef6\u4e2d\u52a0\u5165\u4e86 EODHD API \u7684 API \u5bc6\u94a5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>API_TOKEN=&lt;YOUR_API_KEY_GOES_HERE&gt;<\/code><\/pre>\n\n\n\n<p id=\"3674\">\u4e00\u5207\u5c31\u7eea\u3002\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528 \u00a0<a href=\"https:\/\/code.visualstudio.com\/\">VSCode<\/a>\u00a0\uff0c\u5e76\u5e0c\u671b\u4f7f\u7528\u4e0e\u6211\u4eec\u76f8\u540c\u7684&#8221;.vscode\/settings.json &#8220;\u6587\u4ef6\uff0c\u8bf7\u70b9\u51fb Fork \u672c\u9879\u76ee <a href=\"https:\/\/github.com\/alexyu2013\/trading-ai-lstm\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub <\/a>\u4ed3\u5e93\uff0c\u4ee5\u5907\u4e0d\u65f6\u4e4b\u9700\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"python.formatting.provider\": \"none\",\n  \"python.formatting.blackArgs\": &#91;\"--line-length\", \"160\"],\n  \"python.linting.flake8Args\": &#91;\n    \"--max-line-length=160\",\n    \"--ignore=E203,E266,E501,W503,F403,F401,C901\"\n  ],\n  \"python.analysis.diagnosticSeverityOverrides\": {\n    \"reportUnusedImport\": \"information\",\n    \"reportMissingImports\": \"none\"\n  },\n  \"&#91;python]\": {\n    \"editor.defaultFormatter\": \"ms-python.black-formatter\"\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7e99\"><strong>\u4e8c\u3001\u4ee3\u7801\u6784\u5efa<\/strong><\/h2>\n\n\n\n<p id=\"0557\">\u7b2c\u4e00\u6b65\u662f\u5bfc\u5165\u5fc5\u8981\u7684\u5e93\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nos.environ&#91;\"TF_CPP_MIN_LOG_LEVEL\"] = \"1\"\n\nimport pickle\nimport pandas as pd\nimport numpy as np\nfrom dotenv import load_dotenv\nfrom sklearn.metrics import mean_squared_error, mean_absolute_error\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import LSTM, Dense, Dropout\nfrom tensorflow.keras.models import load_model\nfrom sklearn.preprocessing import MinMaxScaler\nimport matplotlib.pyplot as plt\nfrom eodhd import APIClient<\/code><\/pre>\n\n\n\n<p id=\"0e6d\">TensorFlow \u5f80\u5f80\u4f1a\u81ea\u52a8\u751f\u6210\u8bf8\u591a\u8b66\u544a\u4e0e\u8c03\u8bd5\u4fe1\u606f\u3002\u800c\u6211\u4eec\u66f4\u503e\u5411\u4e8e\u7b80\u6d01\u660e\u4e86\u7684\u8f93\u51fa\uff0c\u6545\u800c\u5bf9\u8fd9\u4e9b\u901a\u77e5\u8fdb\u884c\u4e86\u63a7\u5236\u3002\u8fd9\u53ef\u4ee5\u5728\u5bfc\u5165\u201cos\u201d\u6a21\u5757\u540e\uff0c\u501f\u52a9 os.environ \u6765\u8fbe\u6210\u3002<\/p>\n\n\n\n<p id=\"9242\">\u673a\u5668\u5b66\u4e60\u548c\u4eba\u5de5\u667a\u80fd\u6a21\u578b\u7684\u8bad\u7ec3\u8fc7\u7a0b\u9700\u8981\u5927\u91cf\u7684\u5fae\u8c03\uff0c\u4e3b\u8981\u662f\u901a\u8fc7\u6240\u8c13\u7684<strong>\u8d85\u53c2\u6570<\/strong>\uff08hyperparameters\uff09\u8fdb\u884c\u7ba1\u7406\u3002\u8fd9\u4e2a\u95ee\u9898\u9519\u7efc\u590d\u6742\uff0c\u638c\u63e1\u5b83\u9700\u8981\u4e0d\u65ad\u5b66\u4e60\u548c\u8010\u5fc3\uff0c\u6700\u4f73\u8d85\u53c2\u6570\u7684\u9009\u62e9\u53d7\u5230\u5404\u79cd\u56e0\u7d20\u7684\u5f71\u54cd\u3002\u6839\u636e\u6211\u4eec\u901a\u8fc7 <a href=\"https:\/\/eodhd.com\/\">EODHD API<\/a> \u83b7\u53d6\u7684\u6807\u51c6\u666e\u5c14 500 \u6307\u6570\u6bcf\u65e5\u6570\u636e\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528\u4e86\u4e00\u4e9b\u5e7f\u4e3a\u8ba4\u53ef\u7684\u8bbe\u7f6e\u3002\u6211\u4eec\u9f13\u52b1\u60a8\u4fee\u6539\u8fd9\u4e9b\u8bbe\u7f6e\u4ee5\u63d0\u9ad8\u7ed3\u679c\u3002\u76ee\u524d\uff0c\u5efa\u8bae\u5c06\u5e8f\u5217\u957f\u5ea6\u4fdd\u6301\u5728 20\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Configurable hyperparameters\nseq_length = 20\nbatch_size = 64\nlstm_units = 50\nepochs = 100<\/code><\/pre>\n\n\n\n<p id=\"0ee2\">\u4e0b\u4e00\u6b65\u662f\u4ece\u6211\u4eec\u7684&#8221;.env &#8220;\u6587\u4ef6\u4e2d\u83b7\u53d6 <a href=\"https:\/\/eodhd.com\/\">EODHD API\u2019s<\/a> \u7684 API_TOKEN\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Load environment variables from the .env file\nload_dotenv()\n\n# Retrieve the API key\nAPI_TOKEN = os.getenv(\"API_TOKEN\")\n\nif API_TOKEN is not None:\n    print(f\"API key loaded: {API_TOKEN&#91;:4]}********\")\nelse:\n    raise LookupError(\"Failed to load API key.\")<\/code><\/pre>\n\n\n\n<p id=\"eba2\">\u9700\u8981\u786e\u4fdd\u62e5\u6709\u6709\u6548\u7684 EODHD API \u7684 API_TOKEN \u624d\u80fd\u6210\u529f\u8bbf\u95ee\u6570\u636e\u3002<\/p>\n\n\n\n<p id=\"fef8\">\u6211\u4eec\u5df2\u7ecf\u5efa\u7acb\u4e86\u51e0\u4e2a\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u51fd\u6570\uff0c\u5e76\u5c06\u5728\u4e0b\u6587\u4e2d\u8be6\u7ec6\u4ecb\u7ecd\u5b83\u4eec\u7684\u529f\u80fd\u3002\u6211\u628a\u8fd9\u4e9b\u51fd\u6570\u8fdb\u884c\u4e86\u4ee3\u7801\u6ce8\u91ca\uff0c\u4ee5\u8bf4\u660e\u5176\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def get_ohlc_data(use_cache: bool = False) -&gt; pd.DataFrame:\n    ohlcv_file = \"data\/ohlcv.csv\"\n\n    if use_cache:\n        if os.path.exists(ohlcv_file):\n            return pd.read_csv(ohlcv_file, index_col=None)\n        else:\n            api = APIClient(API_TOKEN)\n            df = api.get_historical_data(\n                symbol=\"HSPX.LSE\",\n                interval=\"d\",\n                iso8601_start=\"2010-05-17\",\n                iso8601_end=\"2023-10-04\",\n            )\n            df.to_csv(ohlcv_file, index=False)\n            return df\n    else:\n        api = APIClient(API_TOKEN)\n        return api.get_historical_data(\n            symbol=\"HSPX.LSE\",\n            interval=\"d\",\n            iso8601_start=\"2010-05-17\",\n            iso8601_end=\"2023-10-04\",\n        )\n\ndef create_sequences(data, seq_length):\n    x, y = &#91;], &#91;]\n    for i in range(len(data) - seq_length):\n        x.append(data&#91;i : i + seq_length])\n        y.append(data&#91;i + seq_length, 3])  # The prediction target \"close\" is the 4th column (index 3)\n    return np.array(x), np.array(y)\n\ndef get_features(df: pd.DataFrame = None, feature_columns: list = &#91;\"open\", \"high\", \"low\", \"close\", \"volume\"]) -&gt; list:\n    return df&#91;feature_columns].values\n\ndef get_target(df: pd.DataFrame = None, target_column: str = \"close\") -&gt; list:\n    return df&#91;target_column].values\n\ndef get_scaler(use_cache: bool = True) -&gt; MinMaxScaler:\n    scaler_file = \"data\/scaler.pkl\"\n\n    if use_cache:\n        if os.path.exists(scaler_file):\n            # Load the scaler\n            with open(scaler_file, \"rb\") as f:\n                return pickle.load(f)\n        else:\n            scaler = MinMaxScaler(feature_range=(0, 1))\n            with open(scaler_file, \"wb\") as f:\n                pickle.dump(scaler, f)\n            return scaler\n    else:\n        return MinMaxScaler(feature_range=(0, 1))\n\ndef scale_features(scaler: MinMaxScaler = None, features: list = &#91;]):\n    return scaler.fit_transform(features)\n\ndef get_lstm_model(use_cache: bool = False) -&gt; Sequential:\n    model_file = \"data\/lstm_model.h5\"\n\n    if use_cache:\n        if os.path.exists(model_file):\n            # Load the model\n            return load_model(model_file)\n        else:\n            # Train the LSTM model and save it\n            model = Sequential()\n            model.add(LSTM(units=lstm_units, activation='tanh', input_shape=(seq_length, 5)))\n            model.add(Dropout(0.2))\n            model.add(Dense(units=1))\n\n            model.compile(optimizer=\"adam\", loss=\"mean_squared_error\")\n            model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size, validation_data=(x_test, y_test))\n\n            # Save the entire model to a HDF5 file\n            model.save(model_file)\n\n            return model\n\n    else:\n        # Train the LSTM model\n        model = Sequential()\n        model.add(LSTM(units=lstm_units, activation='tanh', input_shape=(seq_length, 5)))\n        model.add(Dropout(0.2))\n        model.add(Dense(units=1))\n\n        model.compile(optimizer=\"adam\", loss=\"mean_squared_error\")\n        model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size, validation_data=(x_test, y_test))\n\n        return model\n\ndef get_predicted_x_test_prices(x_test: np.ndarray = None):\n    predicted = model.predict(x_test)\n\n    # Create a zero-filled matrix to aid in inverse transformation\n    zero_filled_matrix = np.zeros((predicted.shape&#91;0], 5))\n\n    # Replace the 'close' column of zero_filled_matrix with the predicted values\n    zero_filled_matrix&#91;:, 3] = np.squeeze(predicted)\n\n    # Perform inverse transformation\n    return scaler.inverse_transform(zero_filled_matrix)&#91;:, 3]\n\ndef plot_x_test_actual_vs_predicted(actual_close_prices: list = &#91;], predicted_x_test_close_prices = &#91;]) -&gt; None:\n    # Plotting the actual and predicted close prices\n    plt.figure(figsize=(14, 7))\n    plt.plot(actual_close_prices, label=\"Actual Close Prices\", color=\"blue\")\n    plt.plot(predicted_x_test_close_prices, label=\"Predicted Close Prices\", color=\"red\")\n    plt.title(\"Actual vs Predicted Close Prices\")\n    plt.xlabel(\"Time\")\n    plt.ylabel(\"Price\")\n    plt.legend()\n    plt.show()\n\ndef predict_next_close(df: pd.DataFrame = None, scaler: MinMaxScaler = None) -&gt; float:\n    # Take the last X days of data and scale it\n    last_x_days = df.iloc&#91;-seq_length:]&#91;&#91;\"open\", \"high\", \"low\", \"close\", \"volume\"]].values\n    last_x_days_scaled = scaler.transform(last_x_days)\n\n    # Reshape this data to be a single sequence and make the prediction\n    last_x_days_scaled = np.reshape(last_x_days_scaled, (1, seq_length, 5))\n\n    # Predict the future close price\n    future_close_price = model.predict(last_x_days_scaled)\n\n    # Create a zero-filled matrix for the inverse transformation\n    zero_filled_matrix = np.zeros((1, 5))\n\n    # Put the predicted value in the 'close' column (index 3)\n    zero_filled_matrix&#91;0, 3] = np.squeeze(future_close_price)\n\n    # Perform the inverse transformation to get the future price on the original scale\n    return scaler.inverse_transform(zero_filled_matrix)&#91;0, 3]\n\ndef evaluate_model(x_test: list = &#91;]) -&gt; None:\n    # Evaluate the model\n    y_pred = model.predict(x_test)\n    mse = mean_squared_error(y_test, y_pred)\n    mae = mean_absolute_error(y_test, y_pred)\n    rmse = np.sqrt(mse)\n\n    print(f\"Mean Squared Error: {mse}\")\n    print(f\"Mean Absolute Error: {mae}\")\n    print(f\"Root Mean Squared Error: {rmse}\")<\/code><\/pre>\n\n\n\n<p id=\"fd8e\">\u6211\u4eec\u9700\u7740\u91cd\u6307\u51fa\u7684\u662f\uff0c\u5728\u5404\u7c7b\u51fd\u6570\u4e2d\u589e\u6dfb\u4e86\u201cuse_cache\u201d\u53d8\u91cf\u3002\u6b64\u7b56\u7565\u610f\u5728\u964d\u4f4e\u5bf9 EODHD \u5e94\u7528\u7a0b\u5e8f\u63a5\u53e3\u7684\u5197\u4f59 API \u8c03\u7528\uff0c\u9632\u6b62\u5229\u7528\u76f8\u540c\u7684\u6bcf\u65e5\u6570\u636e\u5bf9\u6a21\u578b\u8fdb\u884c\u91cd\u590d\u7684\u91cd\u65b0\u8bad\u7ec3\u3002\u6fc0\u6d3b\u201cuse_cache\u201d\u53d8\u91cf\u4f1a\u5c06\u6570\u636e\u5b58\u50a8\u81f3\u201cdata\/\u201d\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u91cc\u3002\u82e5\u6570\u636e\u4e0d\u5b58\u5728\uff0c\u5219\u4f1a\u521b\u5efa\uff1b\u82e5\u5df2\u5b58\u5728\uff0c\u5219\u4f1a\u52a0\u8f7d\u3002\u5f53\u591a\u6b21\u8fd0\u884c\u811a\u672c\u65f6\uff0c\u6b64\u65b9\u6cd5\u80fd\u663e\u8457\u63d0\u5347\u6548\u7387\u3002\u82e5\u8981\u5728\u6bcf\u6b21\u8fd0\u884c\u65f6\u83b7\u53d6\u65b0\u6570\u636e\uff0c\u53ea\u9700\u5728\u8c03\u7528\u51fd\u6570\u65f6\u7981\u7528\u201cuse_cache\u201d\u9009\u9879\u6216\u6e05\u7a7a\u201cdata\/\u201d\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff0c\u5c31\u80fd\u5f97\u5230\u76f8\u540c\u7684\u7ed3\u679c\u3002<\/p>\n\n\n\n<p id=\"e0c6\"><strong>\u73b0\u5728\u8fdb\u5165\u4ee3\u7801\u7684\u6838\u5fc3\u90e8\u5206&#8230;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if __name__ == \"__main__\":\n    # Retrieve 3369 days of S&amp;P 500 data\n    df = get_ohlc_data(use_cache=True)\n    print(df)<\/code><\/pre>\n\n\n\n<p id=\"ebb2\">\u9996\u5148\uff0c\u6211\u4eec\u4ece <a href=\"https:\/\/eodhd.com\/\">EODHD API<\/a>&nbsp; \u83b7\u53d6 OHLCV \u6570\u636e\uff0c\u5e76\u5c06\u5176\u5b58\u5165\u540d\u4e3a &#8220;df &#8220;\u7684 Pandas DataFrame\u3002OHLCV \u8868\u793a\u5f00\u76d8\u4ef7\u3001\u6700\u9ad8\u4ef7\u3001\u6700\u4f4e\u4ef7\u3001\u6536\u76d8\u4ef7\u548c\u6210\u4ea4\u91cf\uff0c\u662f\u4ea4\u6613\u8721\u70db\u56fe\u6570\u636e\u7684\u6807\u51c6\u5c5e\u6027\u3002\u5982\u524d\u6240\u8ff0\uff0c\u6211\u4eec\u542f\u7528\u4e86\u7f13\u5b58\u4ee5\u7b80\u5316\u6d41\u7a0b\u3002\u6211\u4eec\u8fd8\u53ef\u4ee5\u9009\u62e9\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"0750\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.readmedium.com\/v2\/resize:fit:800\/1*PlQYJ-cGDz1P6l_7rjkP7w.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"16aa\">\u6211\u4eec\u5c06\u4e00\u6b21\u6027\u4ecb\u7ecd\u4ee5\u4e0b\u4ee3\u7801\u5757&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    features = get_features(df)\n    target = get_target(df)\n\n    scaler = get_scaler(use_cache=True)\n    scaled_features = scale_features(scaler, features)\n\n    x, y = create_sequences(scaled_features, seq_length)\n\n    train_size = int(0.8 * len(x))  # Create a train\/test split of 80\/20%\n    x_train, x_test = x&#91;:train_size], x&#91;train_size:]\n    y_train, y_test = y&#91;:train_size], y&#91;train_size:]\n\n    # Re-shape input to fit lstm layer\n    x_train = np.reshape(x_train, (x_train.shape&#91;0], seq_length, 5))  # 5 features\n    x_test = np.reshape(x_test, (x_test.shape&#91;0], seq_length, 5))  # 5 features<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u201cfeatures<\/strong>\u201d \u5305\u62ec\u6211\u4eec\u5c06\u7528\u6765\u9884\u6d4b\u76ee\u6807\uff08\u5373 \u201c<strong>close<\/strong>\u201d\uff09\u7684\u4e00\u7cfb\u5217\u8f93\u5165\u3002<\/li>\n\n\n\n<li><strong>\u201ctarget<\/strong>\u201d \u5305\u542b\u4e00\u4e2a\u76ee\u6807\u503c\u5217\u8868\uff0c\u5982 <strong>&#8220;close<\/strong>&#8220;\u3002<\/li>\n\n\n\n<li><strong>\u201cscaler<\/strong>\u201d\u4ee3\u8868\u4e00\u79cd\u7528\u4e8e\u5c06\u6570\u5b57\u6807\u51c6\u5316\u7684\u65b9\u6cd5\uff0c\u4f7f\u5b83\u4eec\u5177\u6709\u53ef\u6bd4\u6027\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u7684\u6570\u636e\u96c6\u5f00\u59cb\u65f6\u7684\u63a5\u8fd1\u503c\u53ef\u80fd\u662f 784\uff0c\u6700\u540e\u53ef\u80fd\u662f 3538\u3002\u6700\u540e\u4e00\u884c\u7684\u6570\u5b57\u8d8a\u9ad8\uff0c\u5e76\u4e0d\u610f\u5473\u7740\u9884\u6d4b\u7684\u610f\u4e49\u8d8a\u5927\u3002\u5f52\u4e00\u5316\u53ef\u786e\u4fdd\u53ef\u6bd4\u6027\u3002<\/li>\n\n\n\n<li><strong>\u201cscaled_features<\/strong>\u201d \u662f\u7f29\u653e\u8fc7\u7a0b\u7684\u7ed3\u679c\uff0c\u6211\u4eec\u5c06\u7528\u5b83\u6765\u8bad\u7ec3\u4eba\u5de5\u667a\u80fd\u6a21\u578b\u3002<\/li>\n\n\n\n<li><strong>\u201cx_train<\/strong>\u201d and \u201c<strong>x_test<\/strong>\u201d \u5206\u522b\u8868\u793a\u6211\u4eec\u5c06\u7528\u4e8e\u8bad\u7ec3\u548c\u6d4b\u8bd5\u4eba\u5de5\u667a\u80fd\u6a21\u578b\u7684\u6570\u636e\u96c6\uff0c\u901a\u5e38\u7684\u505a\u6cd5\u662f 80\/20 \u5206\u914d\u3002\u8fd9\u610f\u5473\u7740 80% \u7684\u4ea4\u6613\u6570\u636e\u7528\u4e8e\u8bad\u7ec3\uff0c20% \u7528\u4e8e\u6d4b\u8bd5\u6a21\u578b\u3002x &#8220;\u8868\u793a\u8fd9\u4e9b\u7279\u5f81\u6216\u8f93\u5165\u3002<\/li>\n\n\n\n<li><strong>\u201cy_train<\/strong>\u201d and \u201c<strong>y_test<\/strong>\u201d \u7684\u529f\u80fd\u7c7b\u4f3c\uff0c\u4f46\u53ea\u5305\u542b\u76ee\u6807\u503c\uff0c\u5982 &#8220;close&#8221;\u3002<\/li>\n\n\n\n<li>\u6700\u540e\uff0c\u5fc5\u987b\u5bf9\u6570\u636e\u8fdb\u884c\u91cd\u5851\uff0c\u4ee5\u6ee1\u8db3 LSTM \u5c42\u7684\u8981\u6c42\u3002<\/li>\n<\/ul>\n\n\n\n<p id=\"6c44\">\u6211\u4eec\u5f00\u53d1\u4e86\u4e00\u79cd\u529f\u80fd\uff0c\u65e2\u80fd\u5bf9\u6a21\u578b\u8fdb\u884c\u91cd\u65b0\u8bad\u7ec3\uff0c\u53c8\u80fd\u8f7d\u5165\u4e4b\u524d\u5df2\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>model = get_lstm_model(use_cache=True)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\" id=\"5b4f\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.readmedium.com\/v2\/resize:fit:800\/1*xsr8sbWISJWYJl6Y2wOfSQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"9b45\">\u4ece\u663e\u793a\u7684\u56fe\u7247\u4e2d\u53ef\u4ee5\u4e00\u7aa5\u8bad\u7ec3\u5e8f\u5217\u3002\u4f60\u4f1a\u53d1\u73b0\uff0c\u6700\u521d\uff0c&nbsp;<strong>\u201closs<\/strong>\u201d\u548c \u201c<strong>val_loss<\/strong>\u201d  \u6307\u6807\u53ef\u80fd\u5e76\u4e0d\u5b8c\u5168\u4e00\u81f4\u3002\u4e0d\u8fc7\uff0c\u968f\u7740\u8bad\u7ec3\u7684\u8fdb\u884c\uff0c\u8fd9\u4e9b\u6570\u636e\u6709\u671b\u8d8b\u4e8e\u4e00\u81f4\uff0c\u8fd9\u8868\u660e\u8bad\u7ec3\u53d6\u5f97\u4e86\u8fdb\u5c55\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Loss<\/strong>: \u8fd9\u662f\u5728\u8bad\u7ec3\u6570\u636e\u96c6\u4e0a\u8ba1\u7b97\u7684\u5747\u65b9\u8bef\u5dee\uff08MSE\uff09\u3002\u5b83\u53cd\u6620\u4e86\u6bcf\u4e2a\u8bad\u7ec3\u671f\u9884\u6d4b\u6807\u7b7e\u548c\u771f\u5b9e\u6807\u7b7e\u4e4b\u95f4\u7684\u201c<strong>cost<\/strong>\u201d \u6216 \u201c<strong>error<\/strong>\u201d \u3002\u6211\u4eec\u7684\u76ee\u6807\u662f\u901a\u8fc7\u8fde\u7eed\u7684\u5386\u65f6\u6765\u51cf\u5c11\u8fd9\u4e00\u6570\u5b57\u3002<\/li>\n\n\n\n<li><strong>Val_loss<\/strong>: \u8fd9\u4e2a\u5747\u65b9\u8bef\u5dee\u662f\u5728\u9a8c\u8bc1\u6570\u636e\u96c6\u4e0a\u786e\u5b9a\u7684\uff0c\u7528\u4e8e\u8861\u91cf\u6a21\u578b\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u672a\u9047\u5230\u7684\u6570\u636e\u4e0a\u7684\u8868\u73b0\u3002\u5b83\u662f\u6a21\u578b\u6cdb\u5316\u5230\u65b0\u7684\u672a\u89c1\u6570\u636e\u80fd\u529b\u7684\u6307\u6807\u3002<\/li>\n<\/ul>\n\n\n\n<p id=\"149b\">\u67e5\u770b\u6d4b\u8bd5\u96c6\u7684\u9884\u6d4b\u6536\u76d8\u4ef7\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b64\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    predicted_x_test_close_prices = get_predicted_x_test_prices(x_test)\n    print(\"Predicted close prices:\", predicted_x_test_close_prices)<\/code><\/pre>\n\n\n\n<p id=\"fa73\">\u5355\u770b\u8fd9\u4e9b\u6570\u636e\uff0c\u53ef\u80fd\u5e76\u4e0d\u7279\u522b\u5177\u6709\u542f\u53d1\u6027\u6216\u76f4\u89c2\u3002\u4e0d\u8fc7\uff0c\u901a\u8fc7\u7ed8\u5236\u5b9e\u9645\u6536\u76d8\u4ef7\u4e0e\u9884\u6d4b\u6536\u76d8\u4ef7\u7684\u5bf9\u6bd4\u56fe\uff08\u8bf7\u6ce8\u610f\uff0c\u8fd9\u53ea\u5360\u6574\u4e2a\u6570\u636e\u96c6\u7684 20%\uff09\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u66f4\u6e05\u6670\u7684\u56fe\u50cf\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    # Plot the actual and predicted close prices for the test data\n    plot_x_test_actual_vs_predicted(df&#91;\"close\"].tail(len(predicted_x_test_close_prices)).values, predicted_x_test_close_prices)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\" id=\"6ebb\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.readmedium.com\/v2\/resize:fit:800\/1*AYDtBWpcn19_WmTvXsVjTg.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"254f\">\u7ed3\u679c\u8868\u660e\uff0c\u5728\u6d4b\u8bd5\u9636\u6bb5\uff0c\u8be5\u6a21\u578b\u5728\u9884\u6d4b\u6536\u76d8\u4ef7\u65b9\u9762\u8868\u73b0\u51fa\u8272\u3002<\/p>\n\n\n\n<p id=\"35e7\">\u73b0\u5728\uff0c\u6211\u4eec\u6765\u770b\u770b\u6700\u4ee4\u4eba\u671f\u5f85\u7684\u65b9\u9762\uff1a\u6211\u4eec\u80fd\u786e\u5b9a\u660e\u5929\u7684\u9884\u6d4b\u6536\u76d8\u4ef7\u5417\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   # Predict the next close price\n    predicted_next_close =  predict_next_close(df, scaler)\n    print(\"Predicted next close price:\", predicted_next_close)\n\nPredicted next close price: 3536.906685638428<\/code><\/pre>\n\n\n\n<p id=\"f08e\">\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u6559\u80b2\u76ee\u7684\u7684\u57fa\u672c\u793a\u4f8b\uff0c\u4ec5\u4ec5\u662f\u4e00\u4e2a\u5f00\u59cb\u3002\u4ece\u8fd9\u91cc\u5f00\u59cb\uff0c\u60a8\u53ef\u4ee5\u8003\u8651\u52a0\u5165\u66f4\u591a\u7684\u8bad\u7ec3\u6570\u636e\uff0c\u8c03\u6574\u8d85\u53c2\u6570\uff0c\u6216\u5c06\u6a21\u578b\u5e94\u7528\u4e8e\u4e0d\u540c\u7684\u5e02\u573a\u548c\u65f6\u95f4\u533a\u95f4\u3002<\/p>\n\n\n\n<p id=\"3ca9\">\u5982\u679c\u60a8\u60f3\u5bf9\u6a21\u578b\u8fdb\u884c\u8bc4\u4f30\uff0c\u53ef\u4ee5\u5c06\u5176\u5305\u62ec\u5728\u5185\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> # Evaluate the model\n    evaluate_model(x_test)<\/code><\/pre>\n\n\n\n<p id=\"dda9\">\u5728\u6211\u4eec\u7684\u65b9\u6848\u4e2d\u7684\u8f93\u51fa\u60c5\u51b5\u662f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Mean Squared Error: 0.00021641664334765608\nMean Absolute Error: 0.01157513692221611\nRoot Mean Squared Error: 0.014711106122506767<\/code><\/pre>\n\n\n\n<p id=\"b70e\">&#8220;\u5e73\u5747\u5e73\u65b9\u8bef\u5dee&#8221;\uff08<strong>mean_squared_error<\/strong>\uff09\u548c &#8220;\u5e73\u5747\u7edd\u5bf9\u8bef\u5dee&#8221;\uff08<strong>mean_absolute_error<\/strong>\uff09\u51fd\u6570\u6765\u81ea scikit-learn \u7684\u5ea6\u91cf\u6a21\u5757\uff0c\u5206\u522b\u7528\u4e8e\u8ba1\u7b97\u5e73\u5747\u5e73\u65b9\u8bef\u5dee\uff08MSE\uff09\u548c\u5e73\u5747\u7edd\u5bf9\u8bef\u5dee\uff08MAE\uff09\u3002\u5747\u65b9\u6839\u8bef\u5dee (RMSE) \u662f\u901a\u8fc7\u5bf9 MSE \u53d6\u5e73\u65b9\u6839\u5f97\u51fa\u7684\u3002<\/p>\n\n\n\n<p id=\"5646\">\u8fd9\u4e9b\u6307\u6807\u4e3a\u6a21\u578b\u7684\u51c6\u786e\u6027\u63d0\u4f9b\u4e86\u6570\u5b57\u5316\u7684\u8bc4\u4f30\uff0c\u4e5f\u4e3a\u6a21\u578b\u7684\u6027\u80fd\u8fdb\u884c\u4e86\u5b9a\u91cf\u7684\u5206\u6790\uff0c\u800c\u56fe\u5f62\u5316\u7684\u5c55\u793a\u5219\u66f4\u6709\u5229\u4e8e\u76f4\u89c2\u5730\u5bf9\u6bd4\u9884\u6d4b\u503c\u4e0e\u5b9e\u9645\u6570\u503c\uff0c\u4ee5\u53ca\u76f4\u89c2\u5730\u6bd4\u8f83\u9884\u6d4b\u503c\u548c\u5b9e\u9645\u503c\u3002<\/p>\n\n\n\n<p id=\"017b\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001<strong>\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<p>\u5728\u672c\u6587\u4e2d\u6211\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u7528 Python \u548c AI \u505a\u4ea4\u6613\u9884\u6d4b\u7684\u6d41\u7a0b\u3002\u9996\u5148\u662f\u5404\u79cd\u9884\u6d4b\u529e\u6cd5\uff0c\u50cf Facebook \u7684 Prophet\u3001SARIMA \u6a21\u578b\u3001\u591a\u9879\u5f0f\u56de\u5f52\uff0c\u8fd8\u6709\u57fa\u4e8e\u4eba\u5de5\u667a\u80fd\u7684\u5faa\u73af\u795e\u7ecf\u7f51\u7edc\uff08RNN\uff09\uff0c\u8fd9\u91cc\u9762\u6211\u89c9\u5f97 LSTM \u6a21\u578b\u6700\u5389\u5bb3\u3002LSTM \u6a21\u578b\u662f\u79cd\u7279\u6b8a\u7684\u9012\u5f52\u795e\u7ecf\u7f51\u7edc\uff0c\u80fd\u5904\u7406\u5e8f\u5217\u9884\u6d4b\u95ee\u9898\uff0c\u8fd8\u89e3\u51b3\u4e86\u6807\u51c6 RNN \u7684\u6d88\u5931\u548c\u68af\u5ea6\u7206\u70b8\u95ee\u9898\uff0c\u9002\u5408\u65f6\u95f4\u5e8f\u5217\u9884\u6d4b\u548c\u81ea\u7136\u8bed\u8a00\u5904\u7406\u8fd9\u4e9b\u4efb\u52a1\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u7ed9\u5927\u5bb6\u63d0\u4f9b\u4e86\u4e00\u4e2a\u6982\u5ff5\u9a8c\u8bc1\u7684\u51c6\u5907\u6b65\u9aa4\uff0c\u5305\u62ec\u5b89\u88c5Python\u548cPIP\u3001\u521b\u5efa\u9879\u76ee\u548c\u6587\u4ef6\u3001\u8bbe\u7f6e\u865a\u62df\u73af\u5883\u4ee5\u53ca\u521b\u5efarequirements.txt\u6587\u4ef6\u3002\u8fd8\u5305\u62ec\u00a0<a href=\"https:\/\/code.visualstudio.com\/\">VSCode<\/a>\u7684\u8bbe\u7f6e\u6587\u4ef6\u793a\u4f8b\uff0c\u4ee5\u53ca\u672c\u9879\u76ee\u7684 <a href=\"https:\/\/github.com\/alexyu2013\/trading-ai-lstm\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a> \u4ee3\u7801\u4ed3\u5e93\u3002<\/p>\n\n\n\n<p>\u800c\u5728\u5efa\u7acb\u4ee3\u7801\u7684\u90e8\u5206\uff0c\u6211\u8be6\u7ec6\u8bf4\u660e\u4e86\u5982\u4f55\u5bfc\u5165\u5fc5\u8981\u7684\u5e93\u548c\u8c03\u7528 <a href=\"https:\/\/eodhd.com\/\">EODHD API\u2019s<\/a>\uff0c\u5e76\u4ecb\u7ecd\u4e86\u4e00\u7cfb\u5217\u53ef\u91cd\u7528\u7684\u51fd\u6570\uff0c\u8fd9\u4e9b\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u6570\u636e\u3001\u521b\u5efa\u5e8f\u5217\u3001\u83b7\u53d6\u7279\u5f81\u548c\u76ee\u6807\u503c\u3001\u7f29\u653e\u7279\u5f81\u3001\u83b7\u53d6LSTM\u6a21\u578b\u3001\u8fdb\u884c\u9884\u6d4b\u4ee5\u53ca\u8bc4\u4f30\u6a21\u578b\u3002\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u8ba8\u8bba\u4e86\u5982\u4f55\u4f7f\u7528\u7f13\u5b58\u6765\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684API\u8c03\u7528\u548c\u6570\u636e\u91cd\u590d\u52a0\u8f7d\u3002<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u672c\u6587\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u6765\u8bad\u7ec3\u548c\u6d4b\u8bd5LSTM\u6a21\u578b\uff0c\u5e76\u5c55\u793a\u4e86\u5982\u4f55\u9884\u6d4b\u4e0b\u4e00\u4e2a\u4ea4\u6613\u65e5\u7684\u6536\u76d8\u4ef7\u3002\u901a\u8fc7\u6bd4\u8f83\u5b9e\u9645\u6536\u76d8\u4ef7\u548c\u9884\u6d4b\u6536\u76d8\u4ef7\u7684\u56fe\u8868\uff0c\u4ee5\u53ca\u8ba1\u7b97\u5747\u65b9\u8bef\u5dee\uff08MSE\uff09\u3001\u5747\u65b9\u6839\u8bef\u5dee\uff08RMSE\uff09\u548c\u5747\u7edd\u5bf9\u8bef\u5dee\uff08MAE\uff09\u7b49\u6307\u6807\uff0c\u6765\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\u3002\u7b80\u5355\u603b\u7ed3\u8d77\u6765\u5c31\u662f\u4e0b\u97626\u53e5\u8bdd\uff1a<\/p>\n\n\n\n<p><strong>LSTM\u6a21\u578b\u5728\u4ea4\u6613\u9884\u6d4b\u4e2d\u7684\u6548\u679c\u4f18\u4e8e\u5176\u4ed6\u65b9\u6cd5<\/strong>\uff0c\u56e0\u4e3a\u5b83\u80fd\u591f\u66f4\u597d\u5730\u5904\u7406\u957f\u671f\u4f9d\u8d56\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>\u4f7f\u7528\u7f13\u5b58\u673a\u5236\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387<\/strong>\uff0c\u907f\u514d\u91cd\u590d\u7684API\u8c03\u7528\u548c\u6a21\u578b\u8bad\u7ec3\u3002<\/p>\n\n\n\n<p><strong>\u901a\u8fc7\u53ef\u89c6\u5316\u5b9e\u9645\u548c\u9884\u6d4b\u7684\u6536\u76d8\u4ef7\uff0c\u4ee5\u53ca\u8ba1\u7b97\u76f8\u5173\u7684\u8bef\u5dee\u6307\u6807<\/strong>\uff0c\u53ef\u4ee5\u76f4\u89c2\u5730\u8bc4\u4f30\u6a21\u578b\u7684\u9884\u6d4b\u51c6\u786e\u6027\u3002<\/p>\n\n\n\n<p><strong>\u6a21\u578b\u7684\u8bad\u7ec3\u548c\u6d4b\u8bd5\u5e94\u8be5\u4f7f\u7528\u4e0d\u540c\u7684\u6570\u636e\u96c6<\/strong>\uff0c\u4ee5\u786e\u4fdd\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n\n\n\n<p><strong>\u8c03\u6574\u8d85\u53c2\u6570\u548c\u4f7f\u7528\u989d\u5916\u7684\u8bad\u7ec3\u6570\u636e\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6a21\u578b\u7684\u6027\u80fd<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u6a21\u578b\u7684\u9884\u6d4b\u7ed3\u679c\u53ef\u4ee5\u4f5c\u4e3a\u4ea4\u6613\u51b3\u7b56\u7684\u53c2\u8003<\/strong>\uff0c\u4f46\u5e94\u8c28\u614e\u4f7f\u7528\uff0c\u56e0\u4e3a\u9884\u6d4b\u5e76\u4e0d\u603b\u662f\u51c6\u786e\u7684\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><mark style=\"background-color:#ffffff\" class=\"has-inline-color has-cyan-bluish-gray-color\">\u672c\u6587\u5185\u5bb9\u4ec5\u4ec5\u662f\u6280\u672f\u63a2\u8ba8\u548c\u5b66\u4e60\uff0c\u5e76\u4e0d\u6784\u6210\u4efb\u4f55\u6295\u8d44\u5efa\u8bae\u3002<\/mark><\/strong><\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><mark style=\"background-color:#ffffff\" class=\"has-inline-color has-cyan-bluish-gray-color\">\u8f6c\u53d1\u8bf7\u6ce8\u660e\u539f\u4f5c\u8005\u548c\u51fa\u5904<\/mark><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u8001\u4f59\u635e\u9c7c \u539f\u521b\u4e0d\u6613\uff0c\u8f6c\u8f7d\u8bf7\u6807\u660e\u51fa\u5904\u53ca\u539f\u4f5c\u8005\u3002&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/laoyulaoyu.com\/index.php\/2024\/09\/19\/%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e4%bc%9a%e4%bd%a0%e7%94%a8-ai-%e5%92%8c-python-%e8%bf%9b%e8%a1%8c%e8%82%a1%e7%a5%a8%e4%ba%a4%e6%98%93%e9%a2%84%e6%b5%8b%ef%bc%88%e5%ae%8c%e6%95%b4%e4%bb%a3\/\">Continue reading<span class=\"screen-reader-text\">\u624b\u628a\u624b\u6559\u4f1a\u4f60\u7528\u00a0AI \u548c Python \u8fdb\u884c\u80a1\u7968\u4ea4\u6613\u9884\u6d4b\uff08\u5b8c\u6574\u4ee3\u7801\u5e72\u8d27\uff09<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,6],"class_list":["post-1518","post","type-post","status-publish","format-standard","hentry","category-aiinvest","tag-ai","tag-6","entry"],"_links":{"self":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/comments?post=1518"}],"version-history":[{"count":2,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1518\/revisions"}],"predecessor-version":[{"id":1520,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/posts\/1518\/revisions\/1520"}],"wp:attachment":[{"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/media?parent=1518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/categories?post=1518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laoyulaoyu.com\/index.php\/wp-json\/wp\/v2\/tags?post=1518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}