更改准确率计算方法

This commit is contained in:
liurui 2024-12-24 16:57:03 +08:00
parent 09e43f8ac1
commit dc53680b5f

View File

@ -463,11 +463,11 @@ def model_losss(sqlitedb,end_time):
# 准确率基准与绘图上下界逻辑一致 # 准确率基准与绘图上下界逻辑一致
# predict_y[['min_price','max_price']] = predict_y[['min_within_quantile','max_within_quantile']] # predict_y[['min_price','max_price']] = predict_y[['min_within_quantile','max_within_quantile']]
# 模型评估前五均值 # 模型评估前五均值
predict_y['min_price'] = predict_y[modelnames].mean(axis=1) -1 # predict_y['min_price'] = predict_y[modelnames].mean(axis=1) -1
predict_y['max_price'] = predict_y[modelnames].mean(axis=1) +1 # predict_y['max_price'] = predict_y[modelnames].mean(axis=1) +1
# 模型评估前十均值 # 模型评估前十均值
# predict_y['min_price'] = predict_y[allmodelnames[0:10]].mean(axis=1) -1 predict_y['min_price'] = predict_y[allmodelnames[0:10]].mean(axis=1) -1.5
# predict_y['max_price'] = predict_y[allmodelnames[0:10]].mean(axis=1) +1 predict_y['max_price'] = predict_y[allmodelnames[0:10]].mean(axis=1) +1.5
# 模型评估前十最大最小 # 模型评估前十最大最小
# allmodelnames 和 predict_y 列 重复的 # allmodelnames 和 predict_y 列 重复的
# allmodelnames = [col for col in allmodelnames if col in predict_y.columns] # allmodelnames = [col for col in allmodelnames if col in predict_y.columns]
@ -523,26 +523,26 @@ def model_losss(sqlitedb,end_time):
endtime = end_time endtime = end_time
endtimeweek = datetime.datetime.strptime(endtime, '%Y-%m-%d') endtimeweek = datetime.datetime.strptime(endtime, '%Y-%m-%d')
up_week = endtimeweek - datetime.timedelta(days=endtimeweek.weekday() + 14) up_week = endtimeweek - datetime.timedelta(days=endtimeweek.weekday() + 14)
up_week_dates = [up_week + datetime.timedelta(days=i) for i in range(14)][4:-2] up_week_dates = [up_week + datetime.timedelta(days=i) for i in range(14)]
up_week_dates = [date.strftime('%Y-%m-%d') for date in up_week_dates] create_dates = [date.strftime('%Y-%m-%d') for date in up_week_dates[4:-3]]
return up_week_dates ds_dates = [date.strftime('%Y-%m-%d') for date in up_week_dates[-7:-2]]
up_week_dates = get_week_date(end_time) return create_dates,ds_dates
create_dates,ds_dates = get_week_date(end_time)
# 计算准确率并保存结果 # 计算准确率并保存结果
def _get_accuracy_rate(df,up_week_dates,endtime): def _get_accuracy_rate(df,create_dates,ds_dates):
df3 = df.copy() df3 = df.copy()
df3 = df3[df3['CREAT_DATE'].isin(up_week_dates)] df3 = df3[df3['CREAT_DATE'].isin(create_dates)]
df3 = df3[df3['ds'].isin(up_week_dates)] df3 = df3[df3['ds'].isin(ds_dates)]
accuracy_rote = 0 accuracy_rote = 0
for i,group in df3.groupby('ds'): for i,group in df3.groupby('CREAT_DATE'):
print('权重:',weight_dict[len(group)-1])
print('准确率:',(group['ACCURACY'].sum()/len(group))*weight_dict[len(group)-1])
accuracy_rote += (group['ACCURACY'].sum()/len(group))*weight_dict[len(group)-1] accuracy_rote += (group['ACCURACY'].sum()/len(group))*weight_dict[len(group)-1]
df3.to_csv(os.path.join(dataset,f'accuracy_{endtime}.csv'),index=False)
df4 = pd.DataFrame(columns=['开始日期','结束日期','准确率']) df4 = pd.DataFrame(columns=['开始日期','结束日期','准确率'])
df4.loc[len(df4)] = {'开始日期':up_week_dates[0],'结束日期':up_week_dates[-1],'准确率':accuracy_rote} 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) df4.to_sql("accuracy_rote", con=sqlitedb.connection, if_exists='append', index=False)
_get_accuracy_rate(df,up_week_dates,end_time) # return df4
_get_accuracy_rate(df,create_dates,ds_dates)
def _add_abs_error_rate(): def _add_abs_error_rate():
# 计算每个预测值与真实值之间的偏差率 # 计算每个预测值与真实值之间的偏差率