{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":96164,"databundleVersionId":11418275,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:19:37.927708Z","iopub.execute_input":"2025-05-26T04:19:37.927984Z","iopub.status.idle":"2025-05-26T04:19:56.320203Z","shell.execute_reply.started":"2025-05-26T04:19:37.927960Z","shell.execute_reply":"2025-05-26T04:19:56.319351Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# tpu = tf.distribute.cluster_resolver.TPUClusterResolver('TPU VM v3-8')\n# tf.tpu.experimental.initialize_tpu_system(tpu)\n# tpu_strategy = tf.distribute.TPUStrategy(tpu)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:19:56.322238Z","iopub.execute_input":"2025-05-26T04:19:56.322815Z","iopub.status.idle":"2025-05-26T04:19:56.326793Z","shell.execute_reply.started":"2025-05-26T04:19:56.322791Z","shell.execute_reply":"2025-05-26T04:19:56.325841Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data = pd.read_parquet(r'/kaggle/input/drw-crypto-market-prediction/train.parquet')\ndata.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:19:56.327721Z","iopub.execute_input":"2025-05-26T04:19:56.328162Z","iopub.status.idle":"2025-05-26T04:20:20.527633Z","shell.execute_reply.started":"2025-05-26T04:19:56.328134Z","shell.execute_reply":"2025-05-26T04:20:20.526820Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(12, 6))\nax.plot(data.index,data['label'])\nax.set_title('label trending')\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:20:20.528576Z","iopub.execute_input":"2025-05-26T04:20:20.528916Z","iopub.status.idle":"2025-05-26T04:20:21.028025Z","shell.execute_reply.started":"2025-05-26T04:20:20.528887Z","shell.execute_reply":"2025-05-26T04:20:21.027202Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig1, ax = plt.subplots(figsize=(18, 10))\nsns.histplot(data['label'], kde=True, bins=50)\nax.set_xlabel('Frequency')\nax.set_ylabel('label value')\nax.set_title('label trending')\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:20:21.028998Z","iopub.execute_input":"2025-05-26T04:20:21.029251Z","iopub.status.idle":"2025-05-26T04:20:23.821411Z","shell.execute_reply.started":"2025-05-26T04:20:21.029232Z","shell.execute_reply":"2025-05-26T04:20:23.820663Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"features = ['bid_qty', 'ask_qty', 'buy_qty', 'sell_qty', 'volume', 'X1', 'X2', 'X3']\n\nfig, axes = plt.subplots(2, 4, figsize=(18, 10))\nfor i, feature in enumerate(features):\n    sns.scatterplot(x=data[feature], y=data['label'], ax=axes[i//4, i%4])\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:20:23.822490Z","iopub.execute_input":"2025-05-26T04:20:23.822860Z","iopub.status.idle":"2025-05-26T04:20:33.795805Z","shell.execute_reply.started":"2025-05-26T04:20:23.822833Z","shell.execute_reply":"2025-05-26T04:20:33.794873Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"correlation_matrix = data[features + ['label']].corr()\nprint(correlation_matrix['label'].sort_values(ascending=False))\nplt.figure(figsize=(10, 8))\nsns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt='.2f')\nplt.title('Feature Correlation with Label')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:20:33.798996Z","iopub.execute_input":"2025-05-26T04:20:33.799584Z","iopub.status.idle":"2025-05-26T04:20:34.359837Z","shell.execute_reply.started":"2025-05-26T04:20:33.799554Z","shell.execute_reply":"2025-05-26T04:20:34.358872Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"window_size = 10  # 分钟\ndata['rolling_volume'] = data['volume'].rolling(window=window_size).mean()\ndata['rolling_label_std'] = data['label'].rolling(window=window_size).std()\n\nfig, ax1 = plt.subplots(figsize=(18, 10))\nax1.plot(data.index, data['rolling_volume'], color='blue', label='Rolling Volume')\nax1.set_xlabel('Time')\nax1.set_ylabel('Rolling Volume', color='blue')\n\nax2 = ax1.twinx()\nax2.plot(data.index, data['rolling_label_std'], color='red', label='Label Volatility')\nax2.set_ylabel('Label Volatility', color='red')\n\nplt.title('Volume vs Label Volatility')\nfig.legend(loc=\"upper right\")\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:20:34.360725Z","iopub.execute_input":"2025-05-26T04:20:34.360991Z","iopub.status.idle":"2025-05-26T04:20:35.207417Z","shell.execute_reply.started":"2025-05-26T04:20:34.360961Z","shell.execute_reply":"2025-05-26T04:20:35.206535Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data['hour'] = data.index.hour\nhourly_stats = data.groupby('hour')['label'].agg(['mean', 'std']).reset_index()\nfig, ax = plt.subplots(figsize=(10, 6))\nax.bar(hourly_stats['hour'], hourly_stats['mean'], yerr=hourly_stats['std'], capsize=5)\nplt.title('Hourly Average Label with Std Dev')\nplt.xlabel('Hour of Day')\nplt.ylabel('Average Label')\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:20:35.208579Z","iopub.execute_input":"2025-05-26T04:20:35.208812Z","iopub.status.idle":"2025-05-26T04:20:35.478868Z","shell.execute_reply.started":"2025-05-26T04:20:35.208787Z","shell.execute_reply":"2025-05-26T04:20:35.477941Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data['minute'] = data.index.minute\nminute_volatility = data.groupby('minute')['label'].std().reset_index()\n\nplt.figure(figsize=(10, 6))\nsns.barplot(x='minute', y='label', data=minute_volatility)\nplt.title('Minute-wise Label Volatility')\nplt.xlabel('Minute of Hour')\nplt.ylabel('Label Volatility')\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-26T04:20:35.479881Z","iopub.execute_input":"2025-05-26T04:20:35.480376Z","iopub.status.idle":"2025-05-26T04:20:36.045503Z","shell.execute_reply.started":"2025-05-26T04:20:35.480353Z","shell.execute_reply":"2025-05-26T04:20:36.044757Z"}},"outputs":[],"execution_count":null}]}