-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
43 lines (29 loc) · 904 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import numpy as np
import pandas as pd
import torch
from sklearn import metrics
def save_np(path, npfile):
if path is None:
return
dir, _ = os.path.split(path)
if not os.path.exists(dir):
os.makedirs(dir)
np.save(path, npfile)
def save_csv(filename, data, header=False, mode='w'):
if filename is None:
return
if data is None:
return
dir, _ = os.path.split(filename)
if not os.path.exists(dir):
os.makedirs(dir)
df = pd.DataFrame(data, index=[0])
# 写入csv文件,'a+'是追加模式
try:
df.to_csv(f'{filename}.csv', header=header, index=False, mode=mode, encoding='utf-8')
except UnicodeEncodeError:
print('error')
def cal_auc(label, predict):
# pred = torch.sigmoid(predict)
return metrics.roc_auc_score(label.detach().cpu().numpy(), predict.detach().cpu().numpy())