From 0893fbde4dffed3032d7458f8dbb473932ba02cb Mon Sep 17 00:00:00 2001 From: jingboyitiji Date: Thu, 13 Feb 2025 17:05:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0eta=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=97=A5=E5=BF=97=E6=9B=B4=E6=96=B0=EF=BC=8C?= =?UTF-8?q?=E8=81=9A=E7=83=AF=E7=83=83=E5=8F=AA=E4=B8=8A=E4=BC=A0=E7=AC=AC?= =?UTF-8?q?=E4=BA=94=E5=A4=A9=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_juxiting.py | 2 +- lib/dataread.py | 4 ++-- models/nerulforcastmodels.py | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/config_juxiting.py b/config_juxiting.py index 2505e40..7150d18 100644 --- a/config_juxiting.py +++ b/config_juxiting.py @@ -225,7 +225,7 @@ print("数据库连接成功",host,dbname,dbusername) # 数据截取日期 start_year = 2020 # 数据开始年份 -end_time = '' # 数据截取日期 +end_time = '2025-01-27' # 数据截取日期 freq = 'B' # 时间频率,"D": 天 "W": 周"M": 月"Q": 季度"A": 年 "H": 小时 "T": 分钟 "S": 秒 "B": 工作日 delweekenday = True if freq == 'B' else False # 是否删除周末数据 is_corr = False # 特征是否参与滞后领先提升相关系数 diff --git a/lib/dataread.py b/lib/dataread.py index 2c5b09a..adb101e 100644 --- a/lib/dataread.py +++ b/lib/dataread.py @@ -1667,14 +1667,14 @@ class EtaReader(): } # 发送post请求 上传数据 - logger.info('请求参数:',data) + logger.info(f'请求参数:{data}') response = requests.post(self.edbdatapushurl, headers=self.headers,data=json.dumps(data)) # 检查响应状态码 if response.status_code == 200: data = response.json() # 假设接口返回的是JSON数据 - logger.info('上传成功,响应为:', data) + logger.info(f'上传成功,响应为:{data}') else: # 请求失败,打印错误信息 diff --git a/models/nerulforcastmodels.py b/models/nerulforcastmodels.py index 1356506..b17d55c 100644 --- a/models/nerulforcastmodels.py +++ b/models/nerulforcastmodels.py @@ -379,17 +379,20 @@ def ex_Model_Juxiting(df,horizon,input_size,train_steps,val_check_steps,early_st logger.info('读取模型:'+ filename) nf = load(filename) # 测试集预测 - nf_test_preds = nf.cross_validation(df=df_test, val_size=val_size, test_size=test_size, n_windows=None) - # 测试集预测结果保存 - nf_test_preds.to_csv(os.path.join(dataset,"cross_validation.csv"),index=False) + # nf_test_preds = nf.cross_validation(df=df_test, val_size=val_size, test_size=test_size, n_windows=None) + # # 测试集预测结果保存 + # nf_test_preds.to_csv(os.path.join(dataset,"cross_validation.csv"),index=False) - df_test['ds'] = pd.to_datetime(df_test['ds'], errors='coerce') + # df_test['ds'] = pd.to_datetime(df_test['ds'], errors='coerce') #进行未来时间预测 df_predict=nf.predict(df_test).reset_index() # 去掉index列 df_predict.drop(columns=['index'], inplace=True) - df_predict.astype({col: 'float32' for col in df_predict.columns if col not in ['ds'] }) + # 处理非有限值(NA 或 inf),将其替换为 0 + df_predict = df_predict.fillna(0) + df_predict = df_predict.replace([np.inf, -np.inf], 0) + df_predict.astype({col: 'int' for col in df_predict.columns if col not in ['ds'] }) # 添加预测时间 df_predict['created_dt'] = end_time @@ -407,13 +410,13 @@ def ex_Model_Juxiting(df,horizon,input_size,train_steps,val_check_steps,early_st for m in modelsindex.keys(): list = [] - for date,value in zip(dates,df_predict[m].round(2)): + for date,value in zip(dates,df_predict[m]): list.append({'Date':date,'Value':value}) - data['DataList'] = list + data['DataList'] = [list[-1]] data['IndexCode'] = modelsindex[m] - data['IndexName'] = f'价格预测{m}模型' + data['IndexName'] = f'聚烯烃价格预测{m}模型' data['Remark'] = m - etadata.push_data(data) + etadata.push_data(data=data) # return nf_test_preds