{ "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
dsACCURACYPREDICT_DATECREAT_DATEHIGH_PRICE_yLOW_PRICE_yMIN_PRICEMAX_PRICEDs_WeekPre_Week
02024-11-261.0000002024-11-262024-11-2573.8071.6371.07155676.0069004747
12024-11-271.0000002024-11-272024-11-2572.8571.7171.00362475.5805604747
22024-11-280.7893242024-11-282024-11-2572.9671.8572.08385076.2042604747
32024-11-291.0000002024-11-292024-11-2573.3471.7571.32973075.7039504747
42024-12-020.8534122024-12-022024-11-2572.8971.5271.72082576.2642754848
52024-11-270.6068732024-11-272024-11-2672.8571.7172.15816576.1736504747
62024-11-280.8021442024-11-282024-11-2672.9671.8572.06962076.4470004747
72024-11-290.6082392024-11-292024-11-2673.3471.7572.37290076.0829104747
82024-12-020.4570072024-12-022024-11-2672.8971.5272.26390076.1986854848
92024-12-030.7583022024-12-032024-11-2673.9371.6872.22382076.0417254848
102024-11-281.0000002024-11-282024-11-2772.9671.8570.70975075.2080304747
112024-11-291.0000002024-11-292024-11-2773.3471.7569.92311075.4237754747
122024-12-021.0000002024-12-022024-11-2772.8971.5270.81035675.7868604848
132024-12-031.0000002024-12-032024-11-2773.9371.6870.81443075.7911154848
142024-12-041.0000002024-12-042024-11-2774.2872.2570.47665075.6237304848
152024-11-291.0000002024-11-292024-11-2873.3471.7570.43276075.4806204747
162024-12-021.0000002024-12-022024-11-2872.8971.5269.65182575.2709404848
172024-12-031.0000002024-12-032024-11-2873.9371.6870.53628575.8264304848
182024-12-041.0000002024-12-042024-11-2874.2872.2570.56834075.7702904848
192024-12-051.0000002024-12-052024-11-2872.9271.8070.22264076.1133104848
202024-12-020.0000002024-12-022024-11-2972.8971.5281.17999081.1799904848
212024-12-030.0000002024-12-032024-11-2973.9371.6880.79155080.7915504848
222024-12-040.0000002024-12-042024-11-2974.2872.2580.65089480.6508944848
232024-12-050.0000002024-12-052024-11-2972.9271.8080.29800080.2980004848
242024-12-060.0000002024-12-062024-11-2972.1970.8575.50838080.2642754848
252024-12-031.0000002024-12-032024-12-0273.9371.6869.80779075.8371904848
262024-12-041.0000002024-12-042024-12-0274.2872.2571.28129676.2405104848
272024-12-051.0000002024-12-052024-12-0272.9271.8070.52623075.9554104848
282024-12-061.0000002024-12-062024-12-0272.1970.8570.71932075.9976804848
292024-12-090.0000002024-12-092024-12-02NaNNaN71.64259075.8286364949
302024-12-040.9432072024-12-042024-12-0374.2872.2572.36529075.8906104848
312024-12-050.6439202024-12-052024-12-0372.9271.8072.19881075.7296204848
322024-12-060.0401722024-12-062024-12-0372.1970.8572.13617075.9776204848
332024-12-090.0000002024-12-092024-12-03NaNNaN72.16579075.8801044949
342024-12-100.0000002024-12-102024-12-03NaNNaN72.00062075.9061004949
352024-12-050.0000002024-12-052024-12-0472.9271.8082.40537082.4053704848
362024-12-060.0000002024-12-062024-12-0472.1970.8582.07270082.0727004848
372024-12-090.0000002024-12-092024-12-04NaNNaN82.65270082.6527004949
382024-12-100.0000002024-12-102024-12-04NaNNaN81.92091081.9209104949
392024-12-110.0000002024-12-112024-12-04NaNNaN81.09127081.0912704949
402024-12-060.0000002024-12-062024-12-0572.1970.8583.36748583.3674854848
412024-12-090.0000002024-12-092024-12-05NaNNaN82.86970582.8697054949
422024-12-100.0000002024-12-102024-12-05NaNNaN82.58055082.5805504949
432024-12-110.0000002024-12-112024-12-05NaNNaN82.44215482.4421544949
442024-12-120.0000002024-12-122024-12-05NaNNaN82.27651082.2765104949
452024-12-090.0000002024-12-092024-12-06NaNNaN68.89477073.9094504949
462024-12-100.0000002024-12-102024-12-06NaNNaN68.84560473.9211204949
472024-12-110.0000002024-12-112024-12-06NaNNaN69.18121073.9062604949
482024-12-120.0000002024-12-122024-12-06NaNNaN69.07534073.8629464949
492024-12-130.0000002024-12-132024-12-06NaNNaN69.07655074.0077404949
\n", "
" ], "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 }