沥青定性模型添加数据更改逻辑;画图横轴时间自动展示
This commit is contained in:
parent
6250220f38
commit
16ec8f02a9
File diff suppressed because it is too large
Load Diff
@ -176,15 +176,15 @@ table_name = 'v_tbl_crude_oil_warning'
|
||||
### 开关
|
||||
is_train = False # 是否训练
|
||||
is_debug = False # 是否调试
|
||||
is_eta = True # 是否使用eta接口
|
||||
is_eta = False # 是否使用eta接口
|
||||
is_market = True # 是否通过市场信息平台获取特征 ,在is_eta 为true 的情况下生效
|
||||
is_timefurture = True # 是否使用时间特征
|
||||
is_fivemodels = False # 是否使用之前保存的最佳的5个模型
|
||||
is_edbcode = False # 特征使用edbcoding列表中的
|
||||
is_edbnamelist = False # 自定义特征,对应上面的edbnamelist
|
||||
is_update_eta = False # 预测结果上传到eta
|
||||
is_update_report = True # 是否上传报告
|
||||
is_update_warning_data = True # 是否上传预警数据
|
||||
is_update_report = False # 是否上传报告
|
||||
is_update_warning_data = False # 是否上传预警数据
|
||||
is_del_corr = 0.6 # 是否删除相关性高的特征,取值为 0-1 ,0 为不删除,0.6 表示删除相关性小于0.6的特征
|
||||
is_del_tow_month = True # 是否删除两个月不更新的特征
|
||||
|
||||
@ -239,7 +239,7 @@ settings = f'{input_size}-{horizon}-{train_steps}--{k}-{data_set}-{y}'
|
||||
# 获取日期时间
|
||||
# now = datetime.datetime.now().strftime('%Y%m%d%H%M%S') # 获取当前日期时间
|
||||
now = datetime.datetime.now().strftime('%Y-%m-%d') # 获取当前日期时间
|
||||
reportname = f'Brent原油大模型预测--{now}.pdf' # 报告文件名
|
||||
reportname = f'Brent原油大模型预测--{end_time}.pdf' # 报告文件名
|
||||
reportname = reportname.replace(':', '-') # 替换冒号
|
||||
if end_time == '':
|
||||
end_time = now
|
||||
|
@ -41,9 +41,9 @@ plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
|
||||
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
|
||||
|
||||
# from config_jingbo_pro import *
|
||||
# from config_jingbo import *
|
||||
from config_jingbo import *
|
||||
# from config_yongan import *
|
||||
from config_juxiting import *
|
||||
# from config_juxiting import *
|
||||
|
||||
|
||||
|
||||
@ -722,7 +722,8 @@ def datachuli(df_zhibiaoshuju,df_zhibiaoliebiao,datecol='date',end_time='',y='y'
|
||||
# 按月取样
|
||||
df = df.resample('M', on='ds').mean().reset_index()
|
||||
# 删除预测列空值的行
|
||||
df = df.dropna(subset=['y'])
|
||||
''' 工作日缺失,如果删除,会影响预测结果,导致统计准确率出错 '''
|
||||
# df = df.dropna(subset=['y'])
|
||||
logger.info(f'删除预测列为空值的行后数据量:{df.shape}')
|
||||
df = df.dropna(axis=1, how='all')
|
||||
logger.info(f'删除全为空值的列后数据量:{df.shape}')
|
||||
|
@ -284,15 +284,15 @@ def predict_main():
|
||||
file=max(glob.glob(os.path.join(dataset,'*.pdf')), key=os.path.getctime),
|
||||
ssl=ssl,
|
||||
)
|
||||
m.send_mail()
|
||||
# m.send_mail()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# global end_time
|
||||
# is_on = True
|
||||
# # 遍历2024-11-25 到 2024-12-3 之间的工作日日期
|
||||
# for i_time in pd.date_range('2024-12-27', '2024-12-28', freq='B'):
|
||||
# end_time = i_time.strftime('%Y-%m-%d')
|
||||
# predict_main()
|
||||
|
||||
global end_time
|
||||
is_on = True
|
||||
# 遍历2024-11-25 到 2024-12-3 之间的工作日日期
|
||||
for i_time in pd.date_range('2024-10-7', '2024-10-30', freq='B'):
|
||||
end_time = i_time.strftime('%Y-%m-%d')
|
||||
predict_main()
|
||||
|
||||
# predict_main()
|
@ -889,7 +889,7 @@ def model_losss(sqlitedb,end_time):
|
||||
# df['ACCURACY'] = df.apply(is_within_range, axis=1)
|
||||
|
||||
# 计算准确率并保存结果
|
||||
def _get_accuracy_rate(df,create_dates,ds_dates,endtime):
|
||||
def _get_accuracy_rate(df,create_dates,ds_dates):
|
||||
df3 = df.copy()
|
||||
df3 = df3[df3['CREAT_DATE'].isin(create_dates)]
|
||||
df3 = df3[df3['ds'].isin(ds_dates)]
|
||||
@ -901,7 +901,7 @@ def model_losss(sqlitedb,end_time):
|
||||
df4.loc[len(df4)] = {'开始日期':ds_dates[0],'结束日期':ds_dates[-1],'准确率':accuracy_rote}
|
||||
df4.to_sql("accuracy_rote", con=sqlitedb.connection, if_exists='append', index=False)
|
||||
create_dates,ds_dates = get_week_date(end_time)
|
||||
_get_accuracy_rate(df,create_dates,ds_dates,end_time)
|
||||
_get_accuracy_rate(df,create_dates,ds_dates)
|
||||
|
||||
def _add_abs_error_rate():
|
||||
# 计算每个预测值与真实值之间的偏差率
|
||||
@ -941,6 +941,9 @@ def model_losss(sqlitedb,end_time):
|
||||
df = df[-lens:] # 取180个数据点画图
|
||||
# 历史价格
|
||||
plt.figure(figsize=(20, 10))
|
||||
# 时间格式更改
|
||||
df['ds'] = pd.to_datetime(df['ds'])
|
||||
|
||||
plt.plot(df['ds'], df['y'], label='真实值')
|
||||
# 颜色填充
|
||||
plt.fill_between(df['ds'], df['max_within_quantile'], df['min_within_quantile'], alpha=0.2)
|
||||
@ -962,6 +965,11 @@ def model_losss(sqlitedb,end_time):
|
||||
plt.axvline(x=df['ds'].iloc[-horizon], color='r', linestyle='--')
|
||||
plt.legend()
|
||||
plt.xlabel('日期')
|
||||
# 设置横轴日期格式为年-月-日
|
||||
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
||||
# 自动设置横轴日期显示
|
||||
plt.gca().xaxis.set_major_locator(mdates.AutoDateLocator())
|
||||
plt.xticks(rotation=45) # 日期标签旋转45度,防止重叠
|
||||
plt.ylabel('价格')
|
||||
|
||||
plt.savefig(os.path.join(dataset,'历史价格-预测值.png'), bbox_inches='tight')
|
||||
@ -969,6 +977,7 @@ def model_losss(sqlitedb,end_time):
|
||||
|
||||
|
||||
def _plt_modeltopten_predict_ture(df):
|
||||
df['ds'] = pd.to_datetime(df['ds'])
|
||||
df['max_cutoff'] = df.groupby('ds')['CREAT_DATE'].transform('max')
|
||||
df = df[df['CREAT_DATE'] == df['max_cutoff']]
|
||||
df['mean'] = df['mean'].astype(float)
|
||||
@ -996,6 +1005,10 @@ def model_losss(sqlitedb,end_time):
|
||||
plt.axvline(x=df['ds'].iloc[-horizon], color='r', linestyle='--')
|
||||
plt.legend()
|
||||
plt.xlabel('日期')
|
||||
# 自动设置横轴日期显示
|
||||
plt.gca().xaxis.set_major_locator(mdates.AutoDateLocator())
|
||||
plt.xticks(rotation=45) # 日期标签旋转45度,防止重叠
|
||||
|
||||
plt.ylabel('价格')
|
||||
|
||||
plt.savefig(os.path.join(dataset,'历史价格-预测值1.png'), bbox_inches='tight')
|
||||
@ -1367,7 +1380,7 @@ def brent_export_pdf(num_indicators=475,num_models=21, num_dayindicator=202,inpu
|
||||
|
||||
|
||||
### 添加标题
|
||||
content.append(Graphs.draw_title(f'{y}{end_time}预测报告'))
|
||||
content.append(Graphs.draw_title(f'{y}{time}预测报告'))
|
||||
|
||||
### 预测结果
|
||||
content.append(Graphs.draw_little_title('一、预测结果:'))
|
||||
|
Loading…
Reference in New Issue
Block a user