From dbaf99fe38b4da03ea0028183cabd4d5136f7eb7 Mon Sep 17 00:00:00 2001 From: workpc Date: Wed, 6 Nov 2024 15:28:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=9A=E7=83=AF=E7=83=83=E9=A2=84=E6=B5=8B?= =?UTF-8?q?=E5=9B=BE=E4=B8=8A=E4=B8=8B=E7=95=8C=E7=94=A85=E4=B8=AA?= =?UTF-8?q?=E6=9C=80=E4=BD=B3=E6=A8=A1=E5=9E=8B=E8=BF=9B=E8=A1=8C=E7=BB=98?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/nerulforcastmodels.py | 41 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/models/nerulforcastmodels.py b/models/nerulforcastmodels.py index 0a29cb4..7126085 100644 --- a/models/nerulforcastmodels.py +++ b/models/nerulforcastmodels.py @@ -508,12 +508,13 @@ def model_losss_juxiting(sqlitedb): modelnames.remove('y') df_combined3 = df_combined.copy() # 备份df_combined,后面画图需要 - # 每行预测值找到10%分位数和90%分位数 + + # 使用最佳五个模型进行绘图 + best_models = pd.read_csv(os.path.join(dataset,'best_modelnames.txt'),header=None).values.flatten().tolist() def find_min_max_within_quantile(row): - row.drop(['ds','y'], inplace=True) - # 获取分位数10%和90%的值 - q10 = row.quantile(0.1) - q90 = row.quantile(0.9) + row = row[best_models] + q10 = row.min() + q90 = row.max() # 获取 row行10%分位值对应的模型名称 min_model = row[row == q10].idxmin() max_model = row[row == q90].idxmin() @@ -526,18 +527,32 @@ def model_losss_juxiting(sqlitedb): df_combined3[['min_within_quantile', 'max_within_quantile','min_model','max_model']] = df_combined3.apply(find_min_max_within_quantile, axis=1) df_combined = df_combined.round(4) print(df_combined3) + + + + + # 通道使用预测模型的80%置信度 + # def find_min_max_within_quantile(row): + # row.drop(['ds','y'], inplace=True) + # # 获取分位数10%和90%的值 + # q10 = row.quantile(0.1) + # q90 = row.quantile(0.9) + # # 获取 row行10%分位值对应的模型名称 + # min_model = row[row == q10].idxmin() + # max_model = row[row == q90].idxmin() + + # # # 判断flot值是否为空值 + # # if pd.isna(q10) or pd.isna(q90): + # return pd.Series([q10, q90,min_model,max_model], index=['min_within_quantile','max_within_quantile','min_model','max_model']) + + # # 遍历行 + # df_combined3[['min_within_quantile', 'max_within_quantile','min_model','max_model']] = df_combined3.apply(find_min_max_within_quantile, axis=1) + # df_combined = df_combined.round(4) + # print(df_combined3) - - - - - - - - # # 计算波动率 # df_combined3['volatility'] = df_combined3['y'].pct_change().round(4) # # 计算近60日的波动率 10% 90%分位数