图片报告样式调整
This commit is contained in:
		
							parent
							
								
									61ba82f177
								
							
						
					
					
						commit
						af31fa2587
					
				
							
								
								
									
										20
									
								
								lib/tools.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								lib/tools.py
									
									
									
									
									
								
							| @ -930,7 +930,7 @@ def find_best_models(date='', global_config=None): | |||||||
|             true_price_value = monthtrueprice |             true_price_value = monthtrueprice | ||||||
|         else: |         else: | ||||||
|             true_price_value = true_price[true_price['ds'] |             true_price_value = true_price[true_price['ds'] | ||||||
|                                           == date]['y'].values[0] |                                           == last_trading_day_str]['y'].values[0] | ||||||
| 
 | 
 | ||||||
|         if not price.empty: |         if not price.empty: | ||||||
|             price.loc[:, 'trueprice'] = true_price_value |             price.loc[:, 'trueprice'] = true_price_value | ||||||
| @ -963,7 +963,7 @@ def find_best_models(date='', global_config=None): | |||||||
|             price = df[['data_date', wd, 'model_id']] |             price = df[['data_date', wd, 'model_id']] | ||||||
|             price = price[(price['data_date'] == ciridate) |             price = price[(price['data_date'] == ciridate) | ||||||
|                           | (price['data_date'] == date)] |                           | (price['data_date'] == date)] | ||||||
|             trend = 1 if true_price[true_price['ds'] == date]['y'].values[0] - \ |             trend = 1 if true_price[true_price['ds'] == ciridate]['y'].values[0] - \ | ||||||
|                 true_price[true_price['ds'] == ciridate]['y'].values[0] > 0 else -1 |                 true_price[true_price['ds'] == ciridate]['y'].values[0] > 0 else -1 | ||||||
|             best_model_id, best_model_name = calculate_best_model(price, trend) |             best_model_id, best_model_name = calculate_best_model(price, trend) | ||||||
|             best_models[wd]['model_id'] = best_model_id |             best_models[wd]['model_id'] = best_model_id | ||||||
| @ -987,11 +987,11 @@ def find_best_models(date='', global_config=None): | |||||||
|                            pd.Timedelta(days=7)).strftime('%Y-%m-%d') |                            pd.Timedelta(days=7)).strftime('%Y-%m-%d') | ||||||
|             global_config['logger'].info(f'计算预测{last_trading_day}的五天前{benzhoudate}最佳模型') |             global_config['logger'].info(f'计算预测{last_trading_day}的五天前{benzhoudate}最佳模型') | ||||||
|             global_config['logger'].info( |             global_config['logger'].info( | ||||||
|                 f'{date}真实价格:{true_price[true_price["ds"] == date]["y"].values[0]}') |                 f'{date}真实价格:{true_price[true_price["ds"] == last_trading_day_str]["y"].values[0]}') | ||||||
|             price = df[['data_date', wd, 'model_id']] |             price = df[['data_date', wd, 'model_id']] | ||||||
|             price = price[(price['data_date'] == benzhoudate) |             price = price[(price['data_date'] == benzhoudate) | ||||||
|                           | (price['data_date'] == date)] |                           | (price['data_date'] == date)] | ||||||
|             trend = 1 if true_price[true_price['ds'] == date]['y'].values[0] - \ |             trend = 1 if true_price[true_price['ds'] == last_trading_day_str]['y'].values[0] - \ | ||||||
|                 true_price[true_price['ds'] == benzhoudate]['y'].values[0] > 0 else -1 |                 true_price[true_price['ds'] == benzhoudate]['y'].values[0] > 0 else -1 | ||||||
|             best_model_id, best_model_name = calculate_best_model(price, trend) |             best_model_id, best_model_name = calculate_best_model(price, trend) | ||||||
|             best_models[wd]['model_id'] = best_model_id |             best_models[wd]['model_id'] = best_model_id | ||||||
| @ -1113,18 +1113,26 @@ def plot_pp_predict_result(y_hat, global_config,wd='yuedu'): | |||||||
|     fig = plt.figure(figsize=(16, 22)) |     fig = plt.figure(figsize=(16, 22)) | ||||||
|     ax = fig.add_axes([0.05, 0.55, 0.9, 0.25])  # 16:9核心参数 |     ax = fig.add_axes([0.05, 0.55, 0.9, 0.25])  # 16:9核心参数 | ||||||
| 
 | 
 | ||||||
|  |     # 添加网格线 | ||||||
|  |     ax.grid(True, linestyle='--', alpha=0.7) | ||||||
|  | 
 | ||||||
|     # 对日期列进行排序,确保日期大的在右边 |     # 对日期列进行排序,确保日期大的在右边 | ||||||
|     y_y_hat = y_y_hat.sort_values(by='ds') |     y_y_hat = y_y_hat.sort_values(by='ds') | ||||||
|     y = y.sort_values(by='ds') |     y = y.sort_values(by='ds') | ||||||
| 
 | 
 | ||||||
|     # 绘制 y_hat 的折线图,颜色为橙色 |     # 绘制 y_hat 的折线图,颜色为橙色 | ||||||
|     sns.lineplot(x=y_y_hat['ds'], y=y_y_hat['predictresult'], |     sns.lineplot(x=y_y_hat['ds'], y=y_y_hat['predictresult'], | ||||||
|                  color='orange', label='预测值', ax=ax, linestyle='--') |                  color='orange', label='预测值', ax=ax, linestyle='--', linewidth=2) | ||||||
|  |     # 绘制散点图 | ||||||
|  |     sns.scatterplot(x=y_y_hat['ds'], y=y_y_hat['predictresult'], | ||||||
|  |                  color='orange', ax=ax, marker='o', s=100) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     # 绘制 y 的折线图,颜色为蓝色 |     # 绘制 y 的折线图,颜色为蓝色 | ||||||
|     sns.lineplot(x=y['ds'], y=y['y'], color='blue', label='真实值', ax=ax) |     sns.lineplot(x=y['ds'], y=y['y'], color='blue', label='真实值', ax=ax) | ||||||
| 
 | 
 | ||||||
|     # date_str = pd.Timestamp(y_hat["ds"].iloc[0]).strftime('%Y-%m-%d') |     # date_str = pd.Timestamp(y_hat["ds"].iloc[0]).strftime('%Y-%m-%d') | ||||||
|     ax.set_title(f'{global_config["end_time"]} PP期货八大维度 预测价格走势', fontsize=24) |     ax.set_title(f'{datetime.datetime.now().strftime("%Y-%m-%d")} PP期货十一大维度 预测价格走势', fontsize=24) | ||||||
|     ax.set_xlabel('日期') |     ax.set_xlabel('日期') | ||||||
|     ax.set_ylabel('预测结果') |     ax.set_ylabel('预测结果') | ||||||
|     ax.tick_params(axis='x', rotation=45) |     ax.tick_params(axis='x', rotation=45) | ||||||
|  | |||||||
| @ -3577,7 +3577,7 @@ def pp_bdwd_png(global_config): | |||||||
|     five_days_predict_price.rename( |     five_days_predict_price.rename( | ||||||
|         columns={week_price_modelname: 'predictresult'}, inplace=True) |         columns={week_price_modelname: 'predictresult'}, inplace=True) | ||||||
|     # 设置索引 次日 次二日 次三日 次四日  次五日 |     # 设置索引 次日 次二日 次三日 次四日  次五日 | ||||||
|     index_labels = ["次日", "次二日", "次三日", "次四日", "次五日"] |     index_labels = ["当日", "次日", "次二日", "次三日", "次四日"] | ||||||
|     five_days_predict_price.index = index_labels |     five_days_predict_price.index = index_labels | ||||||
|     y_hat_riduzhoudu = pd.concat( |     y_hat_riduzhoudu = pd.concat( | ||||||
|         [y_hat_zhoudu, five_days_predict_price], axis=0) |         [y_hat_zhoudu, five_days_predict_price], axis=0) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user