Commit afe45bce authored by 吕先亚's avatar 吕先亚

ai 通用性改动

parent 95202e88
...@@ -16,7 +16,7 @@ from api import DataSync ...@@ -16,7 +16,7 @@ from api import DataSync
# 截止日期 # 截止日期
max_date = None max_date = None
toForecast = True # False means test, True means forecast toForecast = False # False means test, True means forecast
syncData = False # 开启会同步数据库指数及基金数据 syncData = False # 开启会同步数据库指数及基金数据
uploadData = False # 开启会上传预测结果 uploadData = False # 开启会上传预测结果
doReport = True # 开启会生成Excel报告 doReport = True # 开启会生成Excel报告
......
...@@ -4,7 +4,6 @@ import random ...@@ -4,7 +4,6 @@ import random
import pandas as pd import pandas as pd
import requests import requests
from py_jftech import format_date
from ai.config import LABEL_TAG, LABEL_RANGE from ai.config import LABEL_TAG, LABEL_RANGE
from ai.dao import robo_predict from ai.dao import robo_predict
...@@ -57,9 +56,13 @@ def do_reporter2(records=None, excel_name=None): ...@@ -57,9 +56,13 @@ def do_reporter2(records=None, excel_name=None):
'result': result 'result': result
} }
datas.append(data) datas.append(data)
RMSE = get_RMSE(datas)
RefRMSE = get_RefRMSE(datas)
symbol_index_dict = {symbol: index for index, symbol in enumerate(symbols)} symbol_index_dict = {symbol: index for index, symbol in enumerate(symbols)}
sorted_data = sorted(datas, key=lambda x: symbol_index_dict[x['Ticker'].split(' ')[0]]) sorted_data = sorted(datas, key=lambda x: symbol_index_dict[x['Ticker'].split(' ')[0]])
pf = pd.DataFrame(sorted_data) pf = pd.DataFrame(sorted_data)
pf['RMSE'] = RMSE
pf['RefRMSE'] = RefRMSE
pf.to_excel(excel_name if excel_name else "Forcast_Report_chu.xlsx", index=False) pf.to_excel(excel_name if excel_name else "Forcast_Report_chu.xlsx", index=False)
...@@ -69,6 +72,32 @@ def map_to_label(ret): ...@@ -69,6 +72,32 @@ def map_to_label(ret):
return label return label
def get_RMSE(datas):
"""
Root Mean Square Error (RMSE)
@param data: 预测值
@return:
"""
datas = [data for data in datas if data.get('real outcome label') is not None]
tags = {v: k for k, v in LABEL_TAG.items()}
return (sum(
[(tags.get(data['real outcome label']) - tags.get(data['In 21 business days'])) ** 2 for data in datas]) / len(
datas)) ** 0.5
def get_RefRMSE(datas):
"""
Root Mean Square Error (Reference RMSE)
@param data: 预测值
@return:
"""
datas = [data for data in datas if data.get('real outcome label') is not None]
tags = {v: k for k, v in LABEL_TAG.items()}
return (sum(
[(tags.get(data['real outcome label']) - tags.get(data['random variable label'])) ** 2 for data in
datas]) / len(datas)) ** 0.5
def is_right(id, type, start, predict): def is_right(id, type, start, predict):
predict_term = 21 predict_term = 21
navs = [] navs = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment