准确率调试

This commit is contained in:
workpc 2024-12-12 17:07:34 +08:00
parent e6e217df16
commit d1415d065f
2 changed files with 47 additions and 21 deletions

View File

@ -135,10 +135,6 @@ ClassifyId = 1214
# } # }
# 生产环境数据库 # 生产环境数据库
# url: jdbc:mysql://rm-2zehj3r1n60ttz9x5.mysql.rds.aliyuncs.com:3306/jingbo?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&useSSL=false&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
# username: jingbo
# password: shihua@123
# table-schema: jingbo
# host = 'rm-2zehj3r1n60ttz9x5.mysql.rds.aliyuncs.com' # host = 'rm-2zehj3r1n60ttz9x5.mysql.rds.aliyuncs.com'
# port = 3306 # port = 3306
# dbusername ='jingbo' # dbusername ='jingbo'
@ -146,6 +142,8 @@ ClassifyId = 1214
# dbname = 'jingbo' # dbname = 'jingbo'
# table_name = 'v_tbl_crude_oil_warning' # table_name = 'v_tbl_crude_oil_warning'
# 预生产环境 # 预生产环境
# host = 'rm-2zehj3r1n60ttz9x5ko.mysql.rds.aliyuncs.com' # host = 'rm-2zehj3r1n60ttz9x5ko.mysql.rds.aliyuncs.com'
# port = 3306 # port = 3306

View File

@ -353,12 +353,33 @@ def model_losss(sqlitedb):
df_combined3[['min_within_quantile','max_within_quantile']] = names_df.apply(add_upper_lower_bound, axis=1) df_combined3[['min_within_quantile','max_within_quantile']] = names_df.apply(add_upper_lower_bound, axis=1)
def find_closest_values(row):
x = row.y
if x is None:
return pd.Series([None, None], index=['min_within_quantile','max_within_quantile'])
row = row.drop('ds')
row = row[:,0].values.tolist()
row = row.sort()
print(row)
# x 在row中的索引
index = row.index(x)
if index == 0:
return pd.Series([row[index+1], row[index+2]], index=['min_within_quantile','max_within_quantile'])
elif index == len(row)-1:
return pd.Series([row[index-2], row[index-1]], index=['min_within_quantile','max_within_quantile'])
else:
return pd.Series([row[index-1], row[index+1]], index=['min_within_quantile','max_within_quantile'])
# df_combined3[['min_within_quantile','max_within_quantile']] = df_combined3.apply(find_closest_values, axis=1)
def find_most_common_model(): def find_most_common_model():
# 最多频率的模型名称 # 最多频率的模型名称
min_model_max_frequency_model = df_combined3['min_model'].tail(60).value_counts().idxmax() min_model_max_frequency_model = df_combined3['min_model'].tail(60).value_counts().idxmax()
max_model_max_frequency_model = df_combined3['max_model'].tail(60).value_counts().idxmax() max_model_max_frequency_model = df_combined3['max_model'].tail(60).value_counts().idxmax()
if min_model_max_frequency_model == max_model_max_frequency_model: if min_model_max_frequency_model == max_model_max_frequency_model:
# 取20天第二多的模型 # 取60天第二多的模型
max_model_max_frequency_model = df_combined3['max_model'].tail(60).value_counts().nlargest(2).index[1] max_model_max_frequency_model = df_combined3['max_model'].tail(60).value_counts().nlargest(2).index[1]
df_predict['min_model'] = min_model_max_frequency_model df_predict['min_model'] = min_model_max_frequency_model
@ -369,26 +390,33 @@ def model_losss(sqlitedb):
# find_most_common_model() # find_most_common_model()
df_combined3['ds'] = pd.to_datetime(df_combined3['ds'])
df_combined3['ds'] = df_combined3['ds'].dt.strftime('%Y-%m-%d')
df_predict2 = df_combined3.tail(horizon) df_predict2 = df_combined3.tail(horizon)
df_predict2['ds'] = pd.to_datetime(df_predict2['ds'])
df_predict2['ds'] = df_predict2['ds'].dt.strftime('%Y-%m-%d')
# 保存到数据库 # 保存到数据库
if not sqlitedb.check_table_exists('accuracy'): # if not sqlitedb.check_table_exists('accuracy'):
sqlitedb.create_table('accuracy', columns="id int,PREDICT_DATE datetime,CREAT_DATE datetime, MIN_PRICE TEXT,MAX_PRICE TEXT,HIGH_PRICE TEXT,LOW_PRICE TEXT,RIGHT_ROTE ") # columns = ','.join(df_combined3.columns.to_list()+['id','CREAT_DATE'])
existing_data = sqlitedb.select_data(table_name = "accuracy") # sqlitedb.create_table('accuracy',columns=columns)
if not existing_data.empty: # existing_data = sqlitedb.select_data(table_name = "accuracy")
max_id = existing_data['id'].astype(int).max() # update_y = sqlitedb.select_data(table_name = "accuracy",where_condition='y is null')
df_predict2['id'] = range(max_id + 1, max_id + 1 + len(df_predict2)) # df_combined4 = df_combined3[(df_combined3['ds'].isin(update_y['ds'])) & (df_combined3['y'].notnull())]
else: # if len(df_combined4) > 0:
df_predict2['id'] = range(1, 1 + len(df_predict2)) # for index, row in df_combined4.iterrows():
# sqlitedb.update_data('accuracy',f"y = {row['y']}",f"ds = '{row['ds']}'")
# print(df_combined4)
# if not existing_data.empty:
# max_id = existing_data['id'].astype(int).max()
# df_predict2['id'] = range(max_id + 1, max_id + 1 + len(df_predict2))
# else:
# df_predict2['id'] = range(1, 1 + len(df_predict2))
df_predict2['CREAT_DATE'] = end_time # df_predict2['CREAT_DATE'] = now if end_time == '' else end_time
df_predict2['PREDICT_DATE'] = df_predict2['ds'] # df_predict2['PREDICT_DATE'] = df_predict2['ds']
df_predict2['MIN_PRICE'] = df_predict2['min_within_quantile'] # df_predict2['MIN_PRICE'] = df_predict2['min_within_quantile']
df_predict2['MAX_PRICE'] = df_predict2['max_within_quantile'] # df_predict2['MAX_PRICE'] = df_predict2['max_within_quantile']
df_predict2 = df_predict2[['id','PREDICT_DATE','CREAT_DATE','MIN_PRICE','MAX_PRICE']] # df_predict2 = df_predict2[['id','PREDICT_DATE','CREAT_DATE','MIN_PRICE','MAX_PRICE']]
df_predict2.to_sql("accuracy", con=sqlitedb.connection, if_exists='append', index=False) # df_predict2.to_sql("accuracy", con=sqlitedb.connection, if_exists='append', index=False)