1 Star 0 Fork 10

yuhu521mx/双色球预测

forked from Fu_Yanbo/双色球预测 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tools.py 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
Fu_Yanbo 提交于 2022-08-07 13:00 . Default Changelist
from datetime import datetime
import yaml
def ReadConfigs(yaml_path="./configs.yaml"):
with open(yaml_path, 'r') as file:
configs = yaml.load(file, Loader=yaml.FullLoader)
return configs
def WriteArray(my_array, file_name):
with open(file_name, 'w') as f:
for i in my_array:
for j in i:
f.write(str(j))
f.write(' ')
f.write('\n')
f.close()
def ReadIntArray(file_name):
file = open(file_name, mode='r', encoding='UTF-8')
my_array = []
contents = file.readlines()
for msg in contents:
msg = msg.strip('\n')
msg = msg.strip()
adm = msg.split(' ')
adm = [int(x) for x in adm]
my_array.append(adm)
file.close()
return my_array
def ReadFloatArray(file_name):
file = open(file_name, mode='r', encoding='UTF-8')
my_array = []
contents = file.readlines()
for msg in contents:
msg = msg.strip('\n')
msg = msg.strip()
adm = msg.split(' ')
adm = [float(x) for x in adm]
my_array.append(adm)
file.close()
return my_array
def afterList(index):
my_list = []
for i in range(1, 34):
if i in index:
my_list.append(1)
else:
my_list.append(0)
return my_list
def OneHotData(data):
data1 = []
length = len(data)
for i in range(length):
a = afterList(data[i])
data1.append(a)
return data1
def GetConfusionMatrix(list1, list2):
TP = 0
FP = 0
TN = 0
FN = 0
for i in range(list1.numel()):
if (list1[i] == list2[i]) and (list2[i] == 0):
TP += 1
elif (list1[i] == list2[i]) and (list2[i] == 1):
TN += 1
elif (list1[i] != list2[i]) and (list2[i] == 0):
FP += 1
elif (list1[i] != list2[i]) and (list2[i] == 1):
FN += 1
return TP, FP, TN, FN
def PrintLog(message):
t = datetime.now().strftime("%d/%m/%y - %H:%M:%S")
print(f"({t}): {message}")
# unfinished.
def GetParamList():
param_lists = []
for index in range(1, 34):
param_name = 'param/param_' + str(index) + '.txt'
tmp_list1 = ReadFloatArray(param_name)
[list1] = tmp_list1
param_lists.append(list1)
return param_lists
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yuhu_521_mx/ssq.git
git@gitee.com:yuhu_521_mx/ssq.git
yuhu_521_mx
ssq
双色球预测
master

搜索帮助