Spaces:
Running
Running
修复 1012 模型的股票和指数预测逻辑,优化数据提取方式,修正 impact_2_day 错误
Browse files- blkeras.py +37 -37
blkeras.py
CHANGED
|
@@ -218,40 +218,52 @@ def predict(text: str, stock_codes: list):
|
|
| 218 |
index_ndx_predictions = predictions[3].tolist()
|
| 219 |
stock_predictions = predictions[4].tolist()
|
| 220 |
|
| 221 |
-
print(f"Original predictions: {predictions}")
|
| 222 |
-
|
| 223 |
# 打印预测结果,便于调试
|
| 224 |
-
print("Index INX Predictions:", index_inx_predictions)
|
| 225 |
-
print("Index DJ Predictions:", index_dj_predictions)
|
| 226 |
-
print("Index IXIC Predictions:", index_ixic_predictions)
|
| 227 |
-
print("Index NDX Predictions:", index_ndx_predictions)
|
| 228 |
-
print("Stock Predictions:", stock_predictions)
|
|
|
|
| 229 |
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
|
| 233 |
# 获取 index_feature 中最后一天的第一个值
|
| 234 |
-
last_index_inx_value = previous_stock_inx_index_history[
|
| 235 |
-
last_index_dj_value = previous_stock_dj_index_history[
|
| 236 |
-
last_index_ixic_value = previous_stock_ixic_index_history[
|
| 237 |
-
last_index_ndx_value = previous_stock_ndx_index_history[
|
| 238 |
|
| 239 |
# 提取 Index Predictions 中每一天的第一个值
|
| 240 |
-
index_inx_day_1 = index_inx_predictions[0][0]
|
| 241 |
-
index_inx_day_2 = index_inx_predictions[
|
| 242 |
-
index_inx_day_3 = index_inx_predictions[
|
| 243 |
|
| 244 |
-
index_dj_day_1 = index_dj_predictions[0][0]
|
| 245 |
-
index_dj_day_2 = index_dj_predictions[
|
| 246 |
-
index_dj_day_3 = index_dj_predictions[
|
| 247 |
|
| 248 |
-
index_ixic_day_1 = index_ixic_predictions[0][0]
|
| 249 |
-
index_ixic_day_2 = index_ixic_predictions[
|
| 250 |
-
index_ixic_day_3 = index_ixic_predictions[
|
| 251 |
|
| 252 |
-
index_ndx_day_1 = index_ndx_predictions[0][0]
|
| 253 |
-
index_ndx_day_2 = index_ndx_predictions[
|
| 254 |
-
index_ndx_day_3 = index_ndx_predictions[
|
| 255 |
|
| 256 |
# 计算 impact_1_day, impact_2_day, impact_3_day
|
| 257 |
impact_inx_1_day = (index_inx_day_1 - last_index_inx_value) / last_index_inx_value
|
|
@@ -296,18 +308,6 @@ def predict(text: str, stock_codes: list):
|
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
-
# 针对 926 模型的修复
|
| 300 |
-
stock_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), stock_predictions[0], previous_stock_history[0][-1][0])
|
| 301 |
-
index_inx_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), index_inx_predictions[0], last_index_inx_value)
|
| 302 |
-
index_dj_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), index_dj_predictions[0], last_index_dj_value)
|
| 303 |
-
index_ixic_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), index_ixic_predictions[0], last_index_ixic_value)
|
| 304 |
-
index_ndx_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), index_ndx_predictions[0], last_index_ndx_value)
|
| 305 |
-
|
| 306 |
-
print("Stock Predictions after fix:", stock_predictions)
|
| 307 |
-
print("Index INX Predictions after fix:", index_inx_predictions)
|
| 308 |
-
print("Index DJ Predictions after fix:", index_dj_predictions)
|
| 309 |
-
print("Index IXIC Predictions after fix:", index_ixic_predictions)
|
| 310 |
-
print("Index NDX Predictions after fix:", index_ndx_predictions)
|
| 311 |
|
| 312 |
# 扩展股票预测数据到分钟级别
|
| 313 |
stock_predictions = extend_stock_days_to_mins(stock_predictions)
|
|
@@ -323,7 +323,7 @@ def predict(text: str, stock_codes: list):
|
|
| 323 |
"news_title": input_text,
|
| 324 |
"ai_prediction_score": float(X_sentiment[0][0]), # 假设第一个预测值是 AI 预测得分
|
| 325 |
"impact_inx_1_day": impact_inx_1_day_str, # 计算并格式化 impact_1_day
|
| 326 |
-
"
|
| 327 |
"impact_inx_3_day": impact_inx_3_day_str,
|
| 328 |
"impact_dj_1_day": impact_dj_1_day_str, # 计算并格式化 impact_1_day
|
| 329 |
"impact_dj_2_day": impact_dj_2_day_str, # 计算并格式化 impact_2_day
|
|
@@ -351,7 +351,7 @@ def predict(text: str, stock_codes: list):
|
|
| 351 |
if len(prediction_cache) > CACHE_MAX_SIZE:
|
| 352 |
prediction_cache.popitem(last=False)
|
| 353 |
|
| 354 |
-
print(f"predict() result: {result}")
|
| 355 |
|
| 356 |
# 返回预测结果
|
| 357 |
return result
|
|
|
|
| 218 |
index_ndx_predictions = predictions[3].tolist()
|
| 219 |
stock_predictions = predictions[4].tolist()
|
| 220 |
|
|
|
|
|
|
|
| 221 |
# 打印预测结果,便于调试
|
| 222 |
+
#print("Index INX Predictions:", index_inx_predictions)
|
| 223 |
+
#print("Index DJ Predictions:", index_dj_predictions)
|
| 224 |
+
#print("Index IXIC Predictions:", index_ixic_predictions)
|
| 225 |
+
#print("Index NDX Predictions:", index_ndx_predictions)
|
| 226 |
+
#print("Stock Predictions:", stock_predictions)
|
| 227 |
+
|
| 228 |
|
| 229 |
|
| 230 |
+
# 针对 1012 模型的修复
|
| 231 |
+
stock_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), stock_predictions[0], previous_stock_history[0][-1][0])
|
| 232 |
+
index_inx_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), index_inx_predictions[0], last_index_inx_value)
|
| 233 |
+
index_dj_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), index_dj_predictions[0], last_index_dj_value)
|
| 234 |
+
index_ixic_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), index_ixic_predictions[0], last_index_ixic_value)
|
| 235 |
+
index_ndx_predictions = stock_fix_for_1012_model(float(X_sentiment[0][0]), index_ndx_predictions[0], last_index_ndx_value)
|
| 236 |
+
|
| 237 |
+
#print("Stock Predictions after fix:", stock_predictions)
|
| 238 |
+
#print("Index INX Predictions after fix:", index_inx_predictions)
|
| 239 |
+
#print("Index DJ Predictions after fix:", index_dj_predictions)
|
| 240 |
+
#print("Index IXIC Predictions after fix:", index_ixic_predictions)
|
| 241 |
+
#print("Index NDX Predictions after fix:", index_ndx_predictions)
|
| 242 |
+
|
| 243 |
|
| 244 |
|
| 245 |
# 获取 index_feature 中最后一天的第一个值
|
| 246 |
+
last_index_inx_value = previous_stock_inx_index_history[-1][0]
|
| 247 |
+
last_index_dj_value = previous_stock_dj_index_history[-1][0]
|
| 248 |
+
last_index_ixic_value = previous_stock_ixic_index_history[-1][0]
|
| 249 |
+
last_index_ndx_value = previous_stock_ndx_index_history[-1][0]
|
| 250 |
|
| 251 |
# 提取 Index Predictions 中每一天的第一个值
|
| 252 |
+
index_inx_day_1 = index_inx_predictions[0][0]
|
| 253 |
+
index_inx_day_2 = index_inx_predictions[1][0]
|
| 254 |
+
index_inx_day_3 = index_inx_predictions[2][0]
|
| 255 |
|
| 256 |
+
index_dj_day_1 = index_dj_predictions[0][0]
|
| 257 |
+
index_dj_day_2 = index_dj_predictions[1][0]
|
| 258 |
+
index_dj_day_3 = index_dj_predictions[2][0]
|
| 259 |
|
| 260 |
+
index_ixic_day_1 = index_ixic_predictions[0][0]
|
| 261 |
+
index_ixic_day_2 = index_ixic_predictions[1][0]
|
| 262 |
+
index_ixic_day_3 = index_ixic_predictions[2][0]
|
| 263 |
|
| 264 |
+
index_ndx_day_1 = index_ndx_predictions[0][0]
|
| 265 |
+
index_ndx_day_2 = index_ndx_predictions[1][0]
|
| 266 |
+
index_ndx_day_3 = index_ndx_predictions[2][0]
|
| 267 |
|
| 268 |
# 计算 impact_1_day, impact_2_day, impact_3_day
|
| 269 |
impact_inx_1_day = (index_inx_day_1 - last_index_inx_value) / last_index_inx_value
|
|
|
|
| 308 |
|
| 309 |
|
| 310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
# 扩展股票预测数据到分钟级别
|
| 313 |
stock_predictions = extend_stock_days_to_mins(stock_predictions)
|
|
|
|
| 323 |
"news_title": input_text,
|
| 324 |
"ai_prediction_score": float(X_sentiment[0][0]), # 假设第一个预测值是 AI 预测得分
|
| 325 |
"impact_inx_1_day": impact_inx_1_day_str, # 计算并格式化 impact_1_day
|
| 326 |
+
"impact_inx_2_day": impact_inx_2_day_str, # 计算并格式化 impact_2_day
|
| 327 |
"impact_inx_3_day": impact_inx_3_day_str,
|
| 328 |
"impact_dj_1_day": impact_dj_1_day_str, # 计算并格式化 impact_1_day
|
| 329 |
"impact_dj_2_day": impact_dj_2_day_str, # 计算并格式化 impact_2_day
|
|
|
|
| 351 |
if len(prediction_cache) > CACHE_MAX_SIZE:
|
| 352 |
prediction_cache.popitem(last=False)
|
| 353 |
|
| 354 |
+
#print(f"predict() result: {result}")
|
| 355 |
|
| 356 |
# 返回预测结果
|
| 357 |
return result
|