PriceForecast/原油价格预测准确率计算.ipynb
2024-12-10 17:06:26 +08:00

1104 lines
41 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 130,
"id": "9daadf20-caa6-4b25-901c-6cc3ef563f58",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(50, 9)\n",
"(20, 4)\n",
"(50, 12)\n",
" id PREDICT_DATE CREAT_DATE MIN_PRICE MAX_PRICE HIGH_PRICE_x LOW_PRICE_x \\\n",
"0 1 2024-11-26 2024-11-25 71.071556 76.006900 \n",
"1 2 2024-11-27 2024-11-25 71.003624 75.580560 \n",
"2 3 2024-11-28 2024-11-25 72.083850 76.204260 \n",
"3 4 2024-11-29 2024-11-25 71.329730 75.703950 \n",
"4 5 2024-12-02 2024-11-25 71.720825 76.264275 \n",
"\n",
" RIGHT_ROTE ds 序号 LOW_PRICE_y HIGH_PRICE_y \n",
"0 2024-11-26 9.0 71.63 73.80 \n",
"1 2024-11-27 8.0 71.71 72.85 \n",
"2 2024-11-28 7.0 71.85 72.96 \n",
"3 2024-11-29 6.0 71.75 73.34 \n",
"4 2024-12-02 5.0 71.52 72.89 \n",
" id PREDICT_DATE CREAT_DATE MIN_PRICE MAX_PRICE HIGH_PRICE_x \\\n",
"45 46 2024-12-09 2024-12-06 68.894770 73.909450 \n",
"46 47 2024-12-10 2024-12-06 68.845604 73.921120 \n",
"47 48 2024-12-11 2024-12-06 69.181210 73.906260 \n",
"48 49 2024-12-12 2024-12-06 69.075340 73.862946 \n",
"49 50 2024-12-13 2024-12-06 69.076550 74.007740 \n",
"\n",
" LOW_PRICE_x RIGHT_ROTE ds 序号 LOW_PRICE_y HIGH_PRICE_y \n",
"45 2024-12-09 NaN NaN NaN \n",
"46 2024-12-10 NaN NaN NaN \n",
"47 2024-12-11 NaN NaN NaN \n",
"48 2024-12-12 NaN NaN NaN \n",
"49 2024-12-13 NaN NaN NaN \n"
]
}
],
"source": [
"import sqlite3\n",
"import os\n",
"import pandas as pd\n",
"\n",
"# 预测价格数据\n",
"dbfilename = os.path.join(r'D:\\code\\PriceForecast\\yuanyoudataset','jbsh_yuanyou.db')\n",
"conn = sqlite3.connect(dbfilename)\n",
"query = 'SELECT * FROM accuracy'\n",
"df1 = pd.read_sql_query(query, conn)\n",
"df1['ds'] = df1['PREDICT_DATE']\n",
"conn.close()\n",
"print(df1.shape)\n",
"\n",
"\n",
"\n",
"\n",
"# 最高最低价\n",
"xlsfilename = os.path.join(r'D:\\code\\PriceForecast\\yuanyoudataset','数据项下载.xls')\n",
"df2 = pd.read_excel(xlsfilename)[5:]\n",
"df2 = df2.rename(columns = {'数据项名称':'ds','布伦特最低价':'LOW_PRICE','布伦特最高价':'HIGH_PRICE'})\n",
"print(df2.shape)\n",
"\n",
"\n",
"\n",
"df = pd.merge(df1,df2,on=['ds'],how='left')\n",
"\n",
"df['ds'] = pd.to_datetime(df['ds'])\n",
"df['PREDICT_DATE'] = pd.to_datetime(df['PREDICT_DATE'])\n",
"df = df.reindex()\n",
"\n",
"print(df.shape)\n",
"\n",
"df.to_csv(os.path.join(r'D:\\code\\PriceForecast\\yuanyoudataset','123.csv'))\n",
"# df = df[['ds','min_within_quantile','max_within_quantile']]\n",
"\n",
"\n",
"\n",
"# 打印数据框的前几行\n",
"print(df.head())\n",
"print(df.tail())\n"
]
},
{
"cell_type": "code",
"execution_count": 131,
"id": "e51c3fd0-6bff-45de-b8b6-971e7986c7a7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" ds ACCURACY HIGH_PRICE_y LOW_PRICE_y MIN_PRICE MAX_PRICE\n",
"0 2024-11-26 1.000000 73.80 71.63 71.071556 76.006900\n",
"1 2024-11-27 1.000000 72.85 71.71 71.003624 75.580560\n",
"2 2024-11-28 0.789324 72.96 71.85 72.083850 76.204260\n",
"3 2024-11-29 1.000000 73.34 71.75 71.329730 75.703950\n",
"4 2024-12-02 0.853412 72.89 71.52 71.720825 76.264275\n",
"5 2024-11-27 0.606873 72.85 71.71 72.158165 76.173650\n",
"6 2024-11-28 0.802144 72.96 71.85 72.069620 76.447000\n",
"7 2024-11-29 0.608239 73.34 71.75 72.372900 76.082910\n",
"8 2024-12-02 0.457007 72.89 71.52 72.263900 76.198685\n",
"9 2024-12-03 0.758302 73.93 71.68 72.223820 76.041725\n",
"10 2024-11-28 1.000000 72.96 71.85 70.709750 75.208030\n",
"11 2024-11-29 1.000000 73.34 71.75 69.923110 75.423775\n",
"12 2024-12-02 1.000000 72.89 71.52 70.810356 75.786860\n",
"13 2024-12-03 1.000000 73.93 71.68 70.814430 75.791115\n",
"14 2024-12-04 1.000000 74.28 72.25 70.476650 75.623730\n",
"15 2024-11-29 1.000000 73.34 71.75 70.432760 75.480620\n",
"16 2024-12-02 1.000000 72.89 71.52 69.651825 75.270940\n",
"17 2024-12-03 1.000000 73.93 71.68 70.536285 75.826430\n",
"18 2024-12-04 1.000000 74.28 72.25 70.568340 75.770290\n",
"19 2024-12-05 1.000000 72.92 71.80 70.222640 76.113310\n",
"20 2024-12-02 0.000000 72.89 71.52 81.179990 81.179990\n",
"21 2024-12-03 0.000000 73.93 71.68 80.791550 80.791550\n",
"22 2024-12-04 0.000000 74.28 72.25 80.650894 80.650894\n",
"23 2024-12-05 0.000000 72.92 71.80 80.298000 80.298000\n",
"24 2024-12-06 0.000000 72.19 70.85 75.508380 80.264275\n",
"25 2024-12-03 1.000000 73.93 71.68 69.807790 75.837190\n",
"26 2024-12-04 1.000000 74.28 72.25 71.281296 76.240510\n",
"27 2024-12-05 1.000000 72.92 71.80 70.526230 75.955410\n",
"28 2024-12-06 1.000000 72.19 70.85 70.719320 75.997680\n",
"29 2024-12-09 0.000000 NaN NaN 71.642590 75.828636\n",
"30 2024-12-04 0.943207 74.28 72.25 72.365290 75.890610\n",
"31 2024-12-05 0.643920 72.92 71.80 72.198810 75.729620\n",
"32 2024-12-06 0.040172 72.19 70.85 72.136170 75.977620\n",
"33 2024-12-09 0.000000 NaN NaN 72.165790 75.880104\n",
"34 2024-12-10 0.000000 NaN NaN 72.000620 75.906100\n",
"35 2024-12-05 0.000000 72.92 71.80 82.405370 82.405370\n",
"36 2024-12-06 0.000000 72.19 70.85 82.072700 82.072700\n",
"37 2024-12-09 0.000000 NaN NaN 82.652700 82.652700\n",
"38 2024-12-10 0.000000 NaN NaN 81.920910 81.920910\n",
"39 2024-12-11 0.000000 NaN NaN 81.091270 81.091270\n",
"40 2024-12-06 0.000000 72.19 70.85 83.367485 83.367485\n",
"41 2024-12-09 0.000000 NaN NaN 82.869705 82.869705\n",
"42 2024-12-10 0.000000 NaN NaN 82.580550 82.580550\n",
"43 2024-12-11 0.000000 NaN NaN 82.442154 82.442154\n",
"44 2024-12-12 0.000000 NaN NaN 82.276510 82.276510\n",
"45 2024-12-09 0.000000 NaN NaN 68.894770 73.909450\n",
"46 2024-12-10 0.000000 NaN NaN 68.845604 73.921120\n",
"47 2024-12-11 0.000000 NaN NaN 69.181210 73.906260\n",
"48 2024-12-12 0.000000 NaN NaN 69.075340 73.862946\n",
"49 2024-12-13 0.000000 NaN NaN 69.076550 74.007740\n"
]
}
],
"source": [
"# 定义一个函数来计算准确率\n",
"def calculate_accuracy(row):\n",
" if row['HIGH_PRICE_y'] > row['MIN_PRICE']:\n",
" sorted_prices = sorted([row['LOW_PRICE_y'], row['MIN_PRICE'], row['MAX_PRICE'], row['HIGH_PRICE_y']])\n",
" middle_diff = sorted_prices[2] - sorted_prices[1]\n",
" price_range = row['HIGH_PRICE_y'] - row['LOW_PRICE_y']\n",
" accuracy = middle_diff / price_range\n",
" return accuracy\n",
" else:\n",
" return 0\n",
"\n",
"# 使用 apply 函数来应用计算准确率的函数\n",
"\n",
"columns = ['HIGH_PRICE_y','LOW_PRICE_y','MIN_PRICE','MAX_PRICE']\n",
"df[columns] = df[columns].astype(float)\n",
"df['ACCURACY'] = df.apply(calculate_accuracy, axis=1)\n",
"\n",
"\n",
"# 打印结果\n",
"print(df[['ds','ACCURACY',]+columns])\n",
"\n",
"df = df[['ds','ACCURACY','PREDICT_DATE','CREAT_DATE']+columns]"
]
},
{
"cell_type": "code",
"execution_count": 132,
"id": "0f942c69",
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"# ds 按周取\n",
"df['Ds_Week'] = df['ds'].apply(lambda x: x.strftime('%U'))\n",
"df['Pre_Week'] = df['PREDICT_DATE'].apply(lambda x: x.strftime('%U'))"
]
},
{
"cell_type": "code",
"execution_count": 133,
"id": "a7b05510",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ds</th>\n",
" <th>ACCURACY</th>\n",
" <th>PREDICT_DATE</th>\n",
" <th>CREAT_DATE</th>\n",
" <th>HIGH_PRICE_y</th>\n",
" <th>LOW_PRICE_y</th>\n",
" <th>MIN_PRICE</th>\n",
" <th>MAX_PRICE</th>\n",
" <th>Ds_Week</th>\n",
" <th>Pre_Week</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2024-11-26</td>\n",
" <td>1.000000</td>\n",
" <td>2024-11-26</td>\n",
" <td>2024-11-25</td>\n",
" <td>73.80</td>\n",
" <td>71.63</td>\n",
" <td>71.071556</td>\n",
" <td>76.006900</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2024-11-27</td>\n",
" <td>1.000000</td>\n",
" <td>2024-11-27</td>\n",
" <td>2024-11-25</td>\n",
" <td>72.85</td>\n",
" <td>71.71</td>\n",
" <td>71.003624</td>\n",
" <td>75.580560</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2024-11-28</td>\n",
" <td>0.789324</td>\n",
" <td>2024-11-28</td>\n",
" <td>2024-11-25</td>\n",
" <td>72.96</td>\n",
" <td>71.85</td>\n",
" <td>72.083850</td>\n",
" <td>76.204260</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2024-11-29</td>\n",
" <td>1.000000</td>\n",
" <td>2024-11-29</td>\n",
" <td>2024-11-25</td>\n",
" <td>73.34</td>\n",
" <td>71.75</td>\n",
" <td>71.329730</td>\n",
" <td>75.703950</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2024-12-02</td>\n",
" <td>0.853412</td>\n",
" <td>2024-12-02</td>\n",
" <td>2024-11-25</td>\n",
" <td>72.89</td>\n",
" <td>71.52</td>\n",
" <td>71.720825</td>\n",
" <td>76.264275</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>2024-11-27</td>\n",
" <td>0.606873</td>\n",
" <td>2024-11-27</td>\n",
" <td>2024-11-26</td>\n",
" <td>72.85</td>\n",
" <td>71.71</td>\n",
" <td>72.158165</td>\n",
" <td>76.173650</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>2024-11-28</td>\n",
" <td>0.802144</td>\n",
" <td>2024-11-28</td>\n",
" <td>2024-11-26</td>\n",
" <td>72.96</td>\n",
" <td>71.85</td>\n",
" <td>72.069620</td>\n",
" <td>76.447000</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>2024-11-29</td>\n",
" <td>0.608239</td>\n",
" <td>2024-11-29</td>\n",
" <td>2024-11-26</td>\n",
" <td>73.34</td>\n",
" <td>71.75</td>\n",
" <td>72.372900</td>\n",
" <td>76.082910</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>2024-12-02</td>\n",
" <td>0.457007</td>\n",
" <td>2024-12-02</td>\n",
" <td>2024-11-26</td>\n",
" <td>72.89</td>\n",
" <td>71.52</td>\n",
" <td>72.263900</td>\n",
" <td>76.198685</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>2024-12-03</td>\n",
" <td>0.758302</td>\n",
" <td>2024-12-03</td>\n",
" <td>2024-11-26</td>\n",
" <td>73.93</td>\n",
" <td>71.68</td>\n",
" <td>72.223820</td>\n",
" <td>76.041725</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>2024-11-28</td>\n",
" <td>1.000000</td>\n",
" <td>2024-11-28</td>\n",
" <td>2024-11-27</td>\n",
" <td>72.96</td>\n",
" <td>71.85</td>\n",
" <td>70.709750</td>\n",
" <td>75.208030</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>2024-11-29</td>\n",
" <td>1.000000</td>\n",
" <td>2024-11-29</td>\n",
" <td>2024-11-27</td>\n",
" <td>73.34</td>\n",
" <td>71.75</td>\n",
" <td>69.923110</td>\n",
" <td>75.423775</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>2024-12-02</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-02</td>\n",
" <td>2024-11-27</td>\n",
" <td>72.89</td>\n",
" <td>71.52</td>\n",
" <td>70.810356</td>\n",
" <td>75.786860</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>2024-12-03</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-03</td>\n",
" <td>2024-11-27</td>\n",
" <td>73.93</td>\n",
" <td>71.68</td>\n",
" <td>70.814430</td>\n",
" <td>75.791115</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>2024-12-04</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-04</td>\n",
" <td>2024-11-27</td>\n",
" <td>74.28</td>\n",
" <td>72.25</td>\n",
" <td>70.476650</td>\n",
" <td>75.623730</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>2024-11-29</td>\n",
" <td>1.000000</td>\n",
" <td>2024-11-29</td>\n",
" <td>2024-11-28</td>\n",
" <td>73.34</td>\n",
" <td>71.75</td>\n",
" <td>70.432760</td>\n",
" <td>75.480620</td>\n",
" <td>47</td>\n",
" <td>47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>2024-12-02</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-02</td>\n",
" <td>2024-11-28</td>\n",
" <td>72.89</td>\n",
" <td>71.52</td>\n",
" <td>69.651825</td>\n",
" <td>75.270940</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>2024-12-03</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-03</td>\n",
" <td>2024-11-28</td>\n",
" <td>73.93</td>\n",
" <td>71.68</td>\n",
" <td>70.536285</td>\n",
" <td>75.826430</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>2024-12-04</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-04</td>\n",
" <td>2024-11-28</td>\n",
" <td>74.28</td>\n",
" <td>72.25</td>\n",
" <td>70.568340</td>\n",
" <td>75.770290</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>2024-12-05</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-05</td>\n",
" <td>2024-11-28</td>\n",
" <td>72.92</td>\n",
" <td>71.80</td>\n",
" <td>70.222640</td>\n",
" <td>76.113310</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>2024-12-02</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-02</td>\n",
" <td>2024-11-29</td>\n",
" <td>72.89</td>\n",
" <td>71.52</td>\n",
" <td>81.179990</td>\n",
" <td>81.179990</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>2024-12-03</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-03</td>\n",
" <td>2024-11-29</td>\n",
" <td>73.93</td>\n",
" <td>71.68</td>\n",
" <td>80.791550</td>\n",
" <td>80.791550</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>2024-12-04</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-04</td>\n",
" <td>2024-11-29</td>\n",
" <td>74.28</td>\n",
" <td>72.25</td>\n",
" <td>80.650894</td>\n",
" <td>80.650894</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>2024-12-05</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-05</td>\n",
" <td>2024-11-29</td>\n",
" <td>72.92</td>\n",
" <td>71.80</td>\n",
" <td>80.298000</td>\n",
" <td>80.298000</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>2024-12-06</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-06</td>\n",
" <td>2024-11-29</td>\n",
" <td>72.19</td>\n",
" <td>70.85</td>\n",
" <td>75.508380</td>\n",
" <td>80.264275</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>2024-12-03</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-03</td>\n",
" <td>2024-12-02</td>\n",
" <td>73.93</td>\n",
" <td>71.68</td>\n",
" <td>69.807790</td>\n",
" <td>75.837190</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>2024-12-04</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-04</td>\n",
" <td>2024-12-02</td>\n",
" <td>74.28</td>\n",
" <td>72.25</td>\n",
" <td>71.281296</td>\n",
" <td>76.240510</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>2024-12-05</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-05</td>\n",
" <td>2024-12-02</td>\n",
" <td>72.92</td>\n",
" <td>71.80</td>\n",
" <td>70.526230</td>\n",
" <td>75.955410</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>2024-12-06</td>\n",
" <td>1.000000</td>\n",
" <td>2024-12-06</td>\n",
" <td>2024-12-02</td>\n",
" <td>72.19</td>\n",
" <td>70.85</td>\n",
" <td>70.719320</td>\n",
" <td>75.997680</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>2024-12-09</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-09</td>\n",
" <td>2024-12-02</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>71.642590</td>\n",
" <td>75.828636</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>2024-12-04</td>\n",
" <td>0.943207</td>\n",
" <td>2024-12-04</td>\n",
" <td>2024-12-03</td>\n",
" <td>74.28</td>\n",
" <td>72.25</td>\n",
" <td>72.365290</td>\n",
" <td>75.890610</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>2024-12-05</td>\n",
" <td>0.643920</td>\n",
" <td>2024-12-05</td>\n",
" <td>2024-12-03</td>\n",
" <td>72.92</td>\n",
" <td>71.80</td>\n",
" <td>72.198810</td>\n",
" <td>75.729620</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>2024-12-06</td>\n",
" <td>0.040172</td>\n",
" <td>2024-12-06</td>\n",
" <td>2024-12-03</td>\n",
" <td>72.19</td>\n",
" <td>70.85</td>\n",
" <td>72.136170</td>\n",
" <td>75.977620</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>2024-12-09</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-09</td>\n",
" <td>2024-12-03</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>72.165790</td>\n",
" <td>75.880104</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>2024-12-10</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-10</td>\n",
" <td>2024-12-03</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>72.000620</td>\n",
" <td>75.906100</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>2024-12-05</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-05</td>\n",
" <td>2024-12-04</td>\n",
" <td>72.92</td>\n",
" <td>71.80</td>\n",
" <td>82.405370</td>\n",
" <td>82.405370</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>36</th>\n",
" <td>2024-12-06</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-06</td>\n",
" <td>2024-12-04</td>\n",
" <td>72.19</td>\n",
" <td>70.85</td>\n",
" <td>82.072700</td>\n",
" <td>82.072700</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>37</th>\n",
" <td>2024-12-09</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-09</td>\n",
" <td>2024-12-04</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>82.652700</td>\n",
" <td>82.652700</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38</th>\n",
" <td>2024-12-10</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-10</td>\n",
" <td>2024-12-04</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>81.920910</td>\n",
" <td>81.920910</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>39</th>\n",
" <td>2024-12-11</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-11</td>\n",
" <td>2024-12-04</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>81.091270</td>\n",
" <td>81.091270</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40</th>\n",
" <td>2024-12-06</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-06</td>\n",
" <td>2024-12-05</td>\n",
" <td>72.19</td>\n",
" <td>70.85</td>\n",
" <td>83.367485</td>\n",
" <td>83.367485</td>\n",
" <td>48</td>\n",
" <td>48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41</th>\n",
" <td>2024-12-09</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-09</td>\n",
" <td>2024-12-05</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>82.869705</td>\n",
" <td>82.869705</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>42</th>\n",
" <td>2024-12-10</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-10</td>\n",
" <td>2024-12-05</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>82.580550</td>\n",
" <td>82.580550</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>2024-12-11</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-11</td>\n",
" <td>2024-12-05</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>82.442154</td>\n",
" <td>82.442154</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>44</th>\n",
" <td>2024-12-12</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-12</td>\n",
" <td>2024-12-05</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>82.276510</td>\n",
" <td>82.276510</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>2024-12-09</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-09</td>\n",
" <td>2024-12-06</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>68.894770</td>\n",
" <td>73.909450</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46</th>\n",
" <td>2024-12-10</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-10</td>\n",
" <td>2024-12-06</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>68.845604</td>\n",
" <td>73.921120</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>47</th>\n",
" <td>2024-12-11</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-11</td>\n",
" <td>2024-12-06</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>69.181210</td>\n",
" <td>73.906260</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>48</th>\n",
" <td>2024-12-12</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-12</td>\n",
" <td>2024-12-06</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>69.075340</td>\n",
" <td>73.862946</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49</th>\n",
" <td>2024-12-13</td>\n",
" <td>0.000000</td>\n",
" <td>2024-12-13</td>\n",
" <td>2024-12-06</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>69.076550</td>\n",
" <td>74.007740</td>\n",
" <td>49</td>\n",
" <td>49</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ds ACCURACY PREDICT_DATE CREAT_DATE HIGH_PRICE_y LOW_PRICE_y \\\n",
"0 2024-11-26 1.000000 2024-11-26 2024-11-25 73.80 71.63 \n",
"1 2024-11-27 1.000000 2024-11-27 2024-11-25 72.85 71.71 \n",
"2 2024-11-28 0.789324 2024-11-28 2024-11-25 72.96 71.85 \n",
"3 2024-11-29 1.000000 2024-11-29 2024-11-25 73.34 71.75 \n",
"4 2024-12-02 0.853412 2024-12-02 2024-11-25 72.89 71.52 \n",
"5 2024-11-27 0.606873 2024-11-27 2024-11-26 72.85 71.71 \n",
"6 2024-11-28 0.802144 2024-11-28 2024-11-26 72.96 71.85 \n",
"7 2024-11-29 0.608239 2024-11-29 2024-11-26 73.34 71.75 \n",
"8 2024-12-02 0.457007 2024-12-02 2024-11-26 72.89 71.52 \n",
"9 2024-12-03 0.758302 2024-12-03 2024-11-26 73.93 71.68 \n",
"10 2024-11-28 1.000000 2024-11-28 2024-11-27 72.96 71.85 \n",
"11 2024-11-29 1.000000 2024-11-29 2024-11-27 73.34 71.75 \n",
"12 2024-12-02 1.000000 2024-12-02 2024-11-27 72.89 71.52 \n",
"13 2024-12-03 1.000000 2024-12-03 2024-11-27 73.93 71.68 \n",
"14 2024-12-04 1.000000 2024-12-04 2024-11-27 74.28 72.25 \n",
"15 2024-11-29 1.000000 2024-11-29 2024-11-28 73.34 71.75 \n",
"16 2024-12-02 1.000000 2024-12-02 2024-11-28 72.89 71.52 \n",
"17 2024-12-03 1.000000 2024-12-03 2024-11-28 73.93 71.68 \n",
"18 2024-12-04 1.000000 2024-12-04 2024-11-28 74.28 72.25 \n",
"19 2024-12-05 1.000000 2024-12-05 2024-11-28 72.92 71.80 \n",
"20 2024-12-02 0.000000 2024-12-02 2024-11-29 72.89 71.52 \n",
"21 2024-12-03 0.000000 2024-12-03 2024-11-29 73.93 71.68 \n",
"22 2024-12-04 0.000000 2024-12-04 2024-11-29 74.28 72.25 \n",
"23 2024-12-05 0.000000 2024-12-05 2024-11-29 72.92 71.80 \n",
"24 2024-12-06 0.000000 2024-12-06 2024-11-29 72.19 70.85 \n",
"25 2024-12-03 1.000000 2024-12-03 2024-12-02 73.93 71.68 \n",
"26 2024-12-04 1.000000 2024-12-04 2024-12-02 74.28 72.25 \n",
"27 2024-12-05 1.000000 2024-12-05 2024-12-02 72.92 71.80 \n",
"28 2024-12-06 1.000000 2024-12-06 2024-12-02 72.19 70.85 \n",
"29 2024-12-09 0.000000 2024-12-09 2024-12-02 NaN NaN \n",
"30 2024-12-04 0.943207 2024-12-04 2024-12-03 74.28 72.25 \n",
"31 2024-12-05 0.643920 2024-12-05 2024-12-03 72.92 71.80 \n",
"32 2024-12-06 0.040172 2024-12-06 2024-12-03 72.19 70.85 \n",
"33 2024-12-09 0.000000 2024-12-09 2024-12-03 NaN NaN \n",
"34 2024-12-10 0.000000 2024-12-10 2024-12-03 NaN NaN \n",
"35 2024-12-05 0.000000 2024-12-05 2024-12-04 72.92 71.80 \n",
"36 2024-12-06 0.000000 2024-12-06 2024-12-04 72.19 70.85 \n",
"37 2024-12-09 0.000000 2024-12-09 2024-12-04 NaN NaN \n",
"38 2024-12-10 0.000000 2024-12-10 2024-12-04 NaN NaN \n",
"39 2024-12-11 0.000000 2024-12-11 2024-12-04 NaN NaN \n",
"40 2024-12-06 0.000000 2024-12-06 2024-12-05 72.19 70.85 \n",
"41 2024-12-09 0.000000 2024-12-09 2024-12-05 NaN NaN \n",
"42 2024-12-10 0.000000 2024-12-10 2024-12-05 NaN NaN \n",
"43 2024-12-11 0.000000 2024-12-11 2024-12-05 NaN NaN \n",
"44 2024-12-12 0.000000 2024-12-12 2024-12-05 NaN NaN \n",
"45 2024-12-09 0.000000 2024-12-09 2024-12-06 NaN NaN \n",
"46 2024-12-10 0.000000 2024-12-10 2024-12-06 NaN NaN \n",
"47 2024-12-11 0.000000 2024-12-11 2024-12-06 NaN NaN \n",
"48 2024-12-12 0.000000 2024-12-12 2024-12-06 NaN NaN \n",
"49 2024-12-13 0.000000 2024-12-13 2024-12-06 NaN NaN \n",
"\n",
" MIN_PRICE MAX_PRICE Ds_Week Pre_Week \n",
"0 71.071556 76.006900 47 47 \n",
"1 71.003624 75.580560 47 47 \n",
"2 72.083850 76.204260 47 47 \n",
"3 71.329730 75.703950 47 47 \n",
"4 71.720825 76.264275 48 48 \n",
"5 72.158165 76.173650 47 47 \n",
"6 72.069620 76.447000 47 47 \n",
"7 72.372900 76.082910 47 47 \n",
"8 72.263900 76.198685 48 48 \n",
"9 72.223820 76.041725 48 48 \n",
"10 70.709750 75.208030 47 47 \n",
"11 69.923110 75.423775 47 47 \n",
"12 70.810356 75.786860 48 48 \n",
"13 70.814430 75.791115 48 48 \n",
"14 70.476650 75.623730 48 48 \n",
"15 70.432760 75.480620 47 47 \n",
"16 69.651825 75.270940 48 48 \n",
"17 70.536285 75.826430 48 48 \n",
"18 70.568340 75.770290 48 48 \n",
"19 70.222640 76.113310 48 48 \n",
"20 81.179990 81.179990 48 48 \n",
"21 80.791550 80.791550 48 48 \n",
"22 80.650894 80.650894 48 48 \n",
"23 80.298000 80.298000 48 48 \n",
"24 75.508380 80.264275 48 48 \n",
"25 69.807790 75.837190 48 48 \n",
"26 71.281296 76.240510 48 48 \n",
"27 70.526230 75.955410 48 48 \n",
"28 70.719320 75.997680 48 48 \n",
"29 71.642590 75.828636 49 49 \n",
"30 72.365290 75.890610 48 48 \n",
"31 72.198810 75.729620 48 48 \n",
"32 72.136170 75.977620 48 48 \n",
"33 72.165790 75.880104 49 49 \n",
"34 72.000620 75.906100 49 49 \n",
"35 82.405370 82.405370 48 48 \n",
"36 82.072700 82.072700 48 48 \n",
"37 82.652700 82.652700 49 49 \n",
"38 81.920910 81.920910 49 49 \n",
"39 81.091270 81.091270 49 49 \n",
"40 83.367485 83.367485 48 48 \n",
"41 82.869705 82.869705 49 49 \n",
"42 82.580550 82.580550 49 49 \n",
"43 82.442154 82.442154 49 49 \n",
"44 82.276510 82.276510 49 49 \n",
"45 68.894770 73.909450 49 49 \n",
"46 68.845604 73.921120 49 49 \n",
"47 69.181210 73.906260 49 49 \n",
"48 69.075340 73.862946 49 49 \n",
"49 69.076550 74.007740 49 49 "
]
},
"execution_count": 133,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 134,
"id": "1374e354",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['2024-11-29', '2024-11-30', '2024-12-01', '2024-12-02', '2024-12-03', '2024-12-04', '2024-12-05', '2024-12-06']\n",
"(15, 10)\n"
]
}
],
"source": [
"# 取结束日期上一周的日期\n",
"endtime = '2024-12-9'\n",
"endtimeweek = datetime.datetime.strptime(endtime, '%Y-%m-%d')\n",
"up_week = endtimeweek - datetime.timedelta(days=endtimeweek.weekday() + 14)\n",
"up_week_dates = [up_week + datetime.timedelta(days=i) for i in range(14)][4:-2]\n",
"up_week_dates = [date.strftime('%Y-%m-%d') for date in up_week_dates]\n",
"print(up_week_dates)\n",
"\n",
"\n",
"df3 = df.copy()\n",
"df3 = df3[df3['CREAT_DATE'].isin(up_week_dates)]\n",
"df3 = df3[df3['PREDICT_DATE'].isin(up_week_dates)]\n",
"print(df3.shape)\n",
"df3.to_csv('up_week_dates.csv',index=False)"
]
},
{
"cell_type": "code",
"execution_count": 135,
"id": "8aa47e90",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2024-12-02 00:00:00\n",
"权重: 0.07\n",
"准确率: 0.0\n",
"2024-12-03 00:00:00\n",
"权重: 0.13\n",
"准确率: 7.5\n",
"2024-12-04 00:00:00\n",
"权重: 0.2\n",
"准确率: 9.716034482758616\n",
"2024-12-05 00:00:00\n",
"权重: 0.27\n",
"准确率: 6.1646986607143\n",
"2024-12-06 00:00:00\n",
"权重: 0.33\n",
"准确率: 3.1205149253731137\n",
"26.50124806884603\n"
]
}
],
"source": [
"total = len(df3)\n",
"accuracy_rote = 0\n",
"# for i,group in df3.groupby('CREAT_DATE'):\n",
"for i,group in df3.groupby('ds'):\n",
" print(i)\n",
" print('权重:',round(len(group)/total,2))\n",
" print('准确率:',group['ACCURACY'].sum()/(len(group)/total))\n",
" accuracy_rote += group['ACCURACY'].sum()/(len(group)/total)\n",
"\n",
"print(accuracy_rote)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e69cacc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}