整理代码
This commit is contained in:
parent
98c24327ee
commit
1ddbd5badc
@ -250,9 +250,9 @@ is_corr = False # 特征是否参与滞后领先提升相关系数
|
|||||||
add_kdj = False # 是否添加kdj指标
|
add_kdj = False # 是否添加kdj指标
|
||||||
if add_kdj and is_edbnamelist:
|
if add_kdj and is_edbnamelist:
|
||||||
edbnamelist = edbnamelist+['K','D','J']
|
edbnamelist = edbnamelist+['K','D','J']
|
||||||
|
|
||||||
### 模型参数
|
### 模型参数
|
||||||
y = 'Brent连1合约价格' # 原油指标数据的目标变量 Brent连1合约价格 Brent活跃合约
|
y = 'Brent连1合约价格' # 原油指标数据的目标变量 Brent连1合约价格 Brent活跃合约
|
||||||
# y = '期货结算价(连续):布伦特原油:前一个观测值' # ineoil的目标变量
|
|
||||||
horizon =5 # 预测的步长
|
horizon =5 # 预测的步长
|
||||||
input_size = 40 # 输入序列长度
|
input_size = 40 # 输入序列长度
|
||||||
train_steps = 50 if is_debug else 1000 # 训练步数,用来限定epoch次数
|
train_steps = 50 if is_debug else 1000 # 训练步数,用来限定epoch次数
|
||||||
@ -267,10 +267,12 @@ k = 100 # 特征筛选数量,如果是0或者值比特征数量大,代表全
|
|||||||
corr_threshold = 0.6 # 相关性大于0.6的特征
|
corr_threshold = 0.6 # 相关性大于0.6的特征
|
||||||
rote = 0.06 # 绘图上下界阈值
|
rote = 0.06 # 绘图上下界阈值
|
||||||
|
|
||||||
|
### 计算准确率
|
||||||
|
weight_dict = [0.4,0.15,0.1,0.1,0.25] # 权重
|
||||||
|
|
||||||
|
|
||||||
### 文件
|
### 文件
|
||||||
data_set = '原油指标数据.xlsx' # 数据集文件
|
data_set = '原油指标数据.xlsx' # 数据集文件
|
||||||
# data_set = 'INE_OIL(1).csv'
|
|
||||||
### 文件夹
|
|
||||||
dataset = 'yuanyoudataset' # 数据集文件夹
|
dataset = 'yuanyoudataset' # 数据集文件夹
|
||||||
|
|
||||||
# 数据库名称
|
# 数据库名称
|
||||||
|
@ -495,29 +495,31 @@ def model_losss(sqlitedb,end_time):
|
|||||||
df['ACCURACY'] = df.apply(calculate_accuracy, axis=1)
|
df['ACCURACY'] = df.apply(calculate_accuracy, axis=1)
|
||||||
# df['ACCURACY'] = df.apply(is_within_range, axis=1)
|
# df['ACCURACY'] = df.apply(is_within_range, axis=1)
|
||||||
# 取结束日期上一周的日期
|
# 取结束日期上一周的日期
|
||||||
endtime = end_time
|
def get_week_date(end_time):
|
||||||
endtimeweek = datetime.datetime.strptime(endtime, '%Y-%m-%d')
|
endtime = end_time
|
||||||
up_week = endtimeweek - datetime.timedelta(days=endtimeweek.weekday() + 14)
|
endtimeweek = datetime.datetime.strptime(endtime, '%Y-%m-%d')
|
||||||
up_week_dates = [up_week + datetime.timedelta(days=i) for i in range(14)][4:-2]
|
up_week = endtimeweek - datetime.timedelta(days=endtimeweek.weekday() + 14)
|
||||||
up_week_dates = [date.strftime('%Y-%m-%d') for date in up_week_dates]
|
up_week_dates = [up_week + datetime.timedelta(days=i) for i in range(14)][4:-2]
|
||||||
#
|
up_week_dates = [date.strftime('%Y-%m-%d') for date in up_week_dates]
|
||||||
df3 = df.copy()
|
return up_week_dates
|
||||||
df3 = df3[df3['CREAT_DATE'].isin(up_week_dates)]
|
up_week_dates = get_week_date(end_time)
|
||||||
df3 = df3[df3['ds'].isin(up_week_dates)]
|
|
||||||
# df3.to_csv(os.path.join(dataset,f'accuracy_{endtime}.csv'),index=False)
|
# 计算准确率并保存结果
|
||||||
total = len(df3)
|
def _get_accuracy_rate(df,up_week_dates,endtime):
|
||||||
accuracy_rote = 0
|
df3 = df.copy()
|
||||||
# 设置权重字典
|
df3 = df3[df3['CREAT_DATE'].isin(up_week_dates)]
|
||||||
weight_dict = [0.4,0.15,0.1,0.1,0.25]
|
df3 = df3[df3['ds'].isin(up_week_dates)]
|
||||||
for i,group in df3.groupby('ds'):
|
accuracy_rote = 0
|
||||||
print('权重:',weight_dict[len(group)-1])
|
for i,group in df3.groupby('ds'):
|
||||||
print('准确率:',(group['ACCURACY'].sum()/len(group))*weight_dict[len(group)-1])
|
print('权重:',weight_dict[len(group)-1])
|
||||||
accuracy_rote += (group['ACCURACY'].sum()/len(group))*weight_dict[len(group)-1]
|
print('准确率:',(group['ACCURACY'].sum()/len(group))*weight_dict[len(group)-1])
|
||||||
df4 = pd.DataFrame(columns=['开始日期','结束日期','准确率'])
|
accuracy_rote += (group['ACCURACY'].sum()/len(group))*weight_dict[len(group)-1]
|
||||||
df4.loc[len(df4)] = {'开始日期':up_week_dates[0],'结束日期':up_week_dates[-1],'准确率':accuracy_rote}
|
df3.to_csv(os.path.join(dataset,f'accuracy_{endtime}.csv'),index=False)
|
||||||
print(df4)
|
df4 = pd.DataFrame(columns=['开始日期','结束日期','准确率'])
|
||||||
df4.to_sql("accuracy_rote", con=sqlitedb.connection, if_exists='append', index=False)
|
df4.loc[len(df4)] = {'开始日期':up_week_dates[0],'结束日期':up_week_dates[-1],'准确率':accuracy_rote}
|
||||||
|
df4.to_sql("accuracy_rote", con=sqlitedb.connection, if_exists='append', index=False)
|
||||||
|
_get_accuracy_rate(df,up_week_dates,end_time)
|
||||||
|
|
||||||
def _add_abs_error_rate():
|
def _add_abs_error_rate():
|
||||||
# 计算每个预测值与真实值之间的偏差率
|
# 计算每个预测值与真实值之间的偏差率
|
||||||
for model in allmodelnames:
|
for model in allmodelnames:
|
||||||
@ -534,7 +536,6 @@ def model_losss(sqlitedb,end_time):
|
|||||||
# 将最小偏差率对应的模型的预测值添加到DataFrame中
|
# 将最小偏差率对应的模型的预测值添加到DataFrame中
|
||||||
df_combined3['min_abs_error_rate_prediction'] = min_abs_error_rate_predictions
|
df_combined3['min_abs_error_rate_prediction'] = min_abs_error_rate_predictions
|
||||||
df_combined3['min_abs_error_rate_column_name'] = min_abs_error_rate_column_name
|
df_combined3['min_abs_error_rate_column_name'] = min_abs_error_rate_column_name
|
||||||
|
|
||||||
# _add_abs_error_rate()
|
# _add_abs_error_rate()
|
||||||
|
|
||||||
# 判断 df 的数值列转为float
|
# 判断 df 的数值列转为float
|
||||||
|
Loading…
Reference in New Issue
Block a user