Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl_ai_recommender
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
闫发泽
ydl_ai_recommender
Commits
0157477e
Commit
0157477e
authored
Dec 20, 2022
by
柴鹏飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试脚本优化
parent
523f5373
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
14 deletions
+33
-14
test.py
bin/test.py
+33
-14
No files found.
bin/test.py
View file @
0157477e
...
...
@@ -44,9 +44,16 @@ def load_test_data():
return
old_users
,
test_orders
def
_sd
(
n1
,
n2
):
if
n2
==
0
:
return
0
else
:
return
n1
/
n2
def
evaluation
(
result_detail
):
top_n_list
=
[
1
,
3
,
5
,
10
,
20
,
50
,
100
]
top_n_list
=
[
1
,
3
,
5
,
10
,
20
,
50
]
metrics
=
{
'all_test_cnt'
:
0
,
'all_recall_cnt'
:
0
,
...
...
@@ -97,28 +104,23 @@ def evaluation(result_detail):
if
rd
[
'is_recall'
]:
metrics
[
'new_user_recall_cnt'
]
+=
1
logger
.
info
(
'=='
*
20
+
' 测试结果 '
+
'=='
*
20
)
logger
.
info
(
''
)
logger
.
info
(
'相关参数配置: 相似用户数(k)
%
s ;每个相似用户召回咨询师数(top_n)
%
s'
,
args
.
k
,
args
.
top_n
)
logger
.
info
(
'--'
*
45
)
logger
.
info
(
''
)
logger
.
info
(
'{:<13}{:<7}{:<7}{:<7}'
.
format
(
''
,
'样本数'
,
'召回数'
,
'召回率'
))
logger
.
info
(
'{:<10}{:<10}{:<10}{:<10.2
%
}'
.
format
(
'整体
\u3000
'
,
metrics
[
'all_test_cnt'
],
metrics
[
'all_recall_cnt'
],
metrics
[
'all_recall_cnt'
]
/
metrics
[
'all_test_cnt'
]
))
logger
.
info
(
'{:<10}{:<10}{:<10}{:<10.2
%
}'
.
format
(
'老用户'
,
metrics
[
'old_user_test_cnt'
],
metrics
[
'old_user_recall_cnt'
],
metrics
[
'old_user_recall_cnt'
]
/
metrics
[
'old_user_test_cnt'
]
))
logger
.
info
(
'{:<10}{:<10}{:<10}{:<10.2
%
}'
.
format
(
'新用户'
,
metrics
[
'new_user_test_cnt'
],
metrics
[
'new_user_recall_cnt'
],
metrics
[
'new_user_recall_cnt'
]
/
metrics
[
'new_user_test_cnt'
]
))
logger
.
info
(
'{:<10}{:<10}{:<10}{:<10.2
%
}'
.
format
(
'整体
\u3000
'
,
metrics
[
'all_test_cnt'
],
metrics
[
'all_recall_cnt'
],
_sd
(
metrics
[
'all_recall_cnt'
],
metrics
[
'all_test_cnt'
])
))
logger
.
info
(
'{:<10}{:<10}{:<10}{:<10.2
%
}'
.
format
(
'老用户'
,
metrics
[
'old_user_test_cnt'
],
metrics
[
'old_user_recall_cnt'
],
_sd
(
metrics
[
'old_user_recall_cnt'
],
metrics
[
'old_user_test_cnt'
])
))
logger
.
info
(
'{:<10}{:<10}{:<10}{:<10.2
%
}'
.
format
(
'新用户'
,
metrics
[
'new_user_test_cnt'
],
metrics
[
'new_user_recall_cnt'
],
_sd
(
metrics
[
'new_user_recall_cnt'
],
metrics
[
'new_user_test_cnt'
])
))
logger
.
info
(
'--'
*
45
)
logger
.
info
(
''
)
logger
.
info
(
'用户自己召回数 {:<4} 占总召回比例 {:.2
%
}'
.
format
(
metrics
[
'same_user_recall_cnt'
],
metrics
[
'same_user_recall_cnt'
]
/
metrics
[
'all_recall_cnt'
]
))
logger
.
info
(
'相似用户召回数 {:<4} 占总召回比例 {:.2
%
}'
.
format
(
metrics
[
'similar_user_recall_cnt'
],
metrics
[
'similar_user_recall_cnt'
]
/
metrics
[
'all_recall_cnt'
]
))
logger
.
info
(
'兜底用户召回数 {:<4} 占总召回比例 {:.2
%
}'
.
format
(
metrics
[
'default_recall_cnt'
],
metrics
[
'default_recall_cnt'
]
/
metrics
[
'all_recall_cnt'
]
))
logger
.
info
(
'用户自己召回数 {:<4} 占总召回比例 {:.2
%
}'
.
format
(
metrics
[
'same_user_recall_cnt'
],
_sd
(
metrics
[
'same_user_recall_cnt'
],
metrics
[
'all_recall_cnt'
])
))
logger
.
info
(
'相似用户召回数 {:<4} 占总召回比例 {:.2
%
}'
.
format
(
metrics
[
'similar_user_recall_cnt'
],
_sd
(
metrics
[
'similar_user_recall_cnt'
],
metrics
[
'all_recall_cnt'
])
))
logger
.
info
(
'兜底用户召回数 {:<4} 占总召回比例 {:.2
%
}'
.
format
(
metrics
[
'default_recall_cnt'
],
_sd
(
metrics
[
'default_recall_cnt'
],
metrics
[
'all_recall_cnt'
])
))
logger
.
info
(
'--'
*
45
)
logger
.
info
(
''
)
for
i
,
n
in
enumerate
(
top_n_list
):
logger
.
info
(
'top {:<2} 的召回数 {:<4} 召回率 {:.2
%
}'
.
format
(
n
,
metrics
[
'top_n_recall_cnt'
][
i
],
metrics
[
'top_n_recall_cnt'
][
i
]
/
metrics
[
'all_test_cnt'
]
))
logger
.
info
(
'top {:<2} 的召回数 {:<4} 召回率 {:.2
%
}'
.
format
(
n
,
metrics
[
'top_n_recall_cnt'
][
i
],
_sd
(
metrics
[
'top_n_recall_cnt'
][
i
],
metrics
[
'all_test_cnt'
])
))
def
do_test
(
args
):
...
...
@@ -159,10 +161,23 @@ def do_test(args):
'recall_counselors'
:
recommend_result
,
'is_recall'
:
len
(
recall_resons
)
>
0
,
'recall_reason'
:
'|'
.
join
(
recall_resons
),
'update_time'
:
order_info
[
'update_time'
],
})
logger
.
info
(
'测试
结束
'
)
logger
.
info
(
'测试
数据推荐完成
'
)
# 测试结果统计
logger
.
info
(
'=='
*
20
+
' 测试结果 '
+
'=='
*
20
)
logger
.
info
(
''
)
logger
.
info
(
'相关参数配置: 相似用户数(k)
%
s ;每个相似用户召回咨询师数(top_n)
%
s'
,
args
.
k
,
args
.
top_n
)
if
args
.
show_result_by_day
:
days
=
set
(
map
(
lambda
x
:
x
[
'update_time'
],
result_detail
))
for
d
in
sorted
(
days
):
logger
.
info
(
''
)
logger
.
info
(
'**'
*
15
+
' 订单日期 '
+
d
+
'**'
*
15
)
evaluation
(
filter
(
lambda
x
:
x
[
'update_time'
]
==
d
,
result_detail
))
else
:
evaluation
(
result_detail
)
if
args
.
save_test_result
:
...
...
@@ -179,6 +194,9 @@ def update_test_data(args):
elif
re
.
match
(
r'-\d+'
,
args
.
start_date
):
now
=
datetime
.
now
()
start_date
=
(
now
-
timedelta
(
days
=
int
(
args
.
start_date
[
1
:])))
.
strftime
(
'
%
Y-
%
m-
%
d'
)
elif
args
.
start_date
==
'0'
:
now
=
datetime
.
now
()
start_date
=
now
.
strftime
(
'
%
Y-
%
m-
%
d'
)
else
:
logger
.
error
(
'args.start_date 参数格式错误,
%
s'
,
args
.
start_date
)
raise
...
...
@@ -207,6 +225,7 @@ if __name__ == '__main__':
parser
.
add_argument
(
'--top_n'
,
default
=
5
,
type
=
int
,
help
=
'每个相似用户召回的咨询师数量'
)
parser
.
add_argument
(
'--max_test'
,
default
=
0
,
type
=
int
,
help
=
'最多测试数据量'
)
parser
.
add_argument
(
'--save_test_result'
,
default
=
False
,
action
=
'store_true'
,
help
=
'保存测试详情结果'
)
parser
.
add_argument
(
'--show_result_by_day'
,
default
=
False
,
action
=
'store_true'
,
help
=
'测试结果是否按天展示'
)
parser
.
add_argument
(
'--do_update_test_data'
,
default
=
False
,
action
=
'store_true'
,
help
=
'是否更新测试数据'
)
parser
.
add_argument
(
'--start_date'
,
default
=
'-1'
,
type
=
str
,
help
=
'测试订单创建的开始时间,可以是"
%
Y-
%
m-
%
d"格式,也可以是 -3 表示前3天'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment