Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
71fd9646
P
PaddleRec
项目概览
PaddlePaddle
/
PaddleRec
通知
68
Star
12
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
27
列表
看板
标记
里程碑
合并请求
10
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleRec
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
27
Issue
27
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
71fd9646
编写于
3月 05, 2020
作者:
X
xiexionghang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
commit kagle for paddle
上级
ead2a1a9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
59 addition
and
8 deletion
+59
-8
kagle/kagle_metric.py
kagle/kagle_metric.py
+59
-8
未找到文件。
kagle/kagle_metric.py
浏览文件 @
71fd9646
"""
Do metric jobs. calculate AUC, MSE, COCP ...
"""
import
math
import
math
import
time
import
time
import
numpy
as
np
import
numpy
as
np
import
kagle_util
import
kagle_util
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
abc
import
ABCMeta
,
abstractmethod
from
paddle.fluid.incubate.fleet.parameter_server.pslib
import
fleet
from
paddle.fluid.incubate.fleet.parameter_server.pslib
import
fleet
class
Metric
(
object
):
class
Metric
(
object
):
__metaclass__
=
ABCMeta
""" """
__metaclass__
=
abc
.
ABCMeta
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
""" """
pass
pass
@
abstractmethod
@
ab
c
.
ab
stractmethod
def
clear
(
self
,
scope
,
params
):
def
clear
(
self
,
scope
,
params
):
"""
clear current value
Args:
scope: value container
params: extend varilable for clear
"""
pass
pass
@
abstractmethod
@
ab
c
.
ab
stractmethod
def
calculate
(
self
,
scope
,
params
):
def
calculate
(
self
,
scope
,
params
):
"""
calculate result
Args:
scope: value container
params: extend varilable for clear
"""
pass
pass
@
abstractmethod
@
ab
c
.
ab
stractmethod
def
get_result
(
self
):
def
get_result
(
self
):
"""
Return:
result(dict) : calculate result
"""
pass
pass
@
abstractmethod
@
ab
c
.
ab
stractmethod
def
get_result_to_string
(
self
):
def
get_result_to_string
(
self
):
"""
Return:
result(string) : calculate result with string format, for output
"""
pass
pass
class
PaddleAUCMetric
(
Metric
):
class
PaddleAUCMetric
(
Metric
):
"""
Metric For Paddle Model
"""
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
""" """
pass
pass
def
clear
(
self
,
scope
,
params
):
def
clear
(
self
,
scope
,
params
):
"""
Clear current metric value, usually set to zero
Args:
scope : paddle runtime var container
params(dict) :
label : a group name for metric
metric_dict : current metric_items in group
Return:
None
"""
self
.
_label
=
params
[
'label'
]
self
.
_label
=
params
[
'label'
]
self
.
_metric_dict
=
params
[
'metric_dict'
]
self
.
_metric_dict
=
params
[
'metric_dict'
]
self
.
_result
=
{}
self
.
_result
=
{}
...
@@ -47,10 +85,13 @@ class PaddleAUCMetric(Metric):
...
@@ -47,10 +85,13 @@ class PaddleAUCMetric(Metric):
data_type
=
metric_config
[
'data_type'
]
data_type
=
metric_config
[
'data_type'
]
data_array
=
np
.
zeros
(
metric_var
.
_get_dims
()).
astype
(
data_type
)
data_array
=
np
.
zeros
(
metric_var
.
_get_dims
()).
astype
(
data_type
)
metric_var
.
set
(
data_array
,
place
)
metric_var
.
set
(
data_array
,
place
)
pass
def
get_metric
(
self
,
scope
,
metric_name
):
def
get_metric
(
self
,
scope
,
metric_name
):
"""
reduce metric named metric_name from all worker
Return:
metric reduce result
"""
metric
=
np
.
array
(
scope
.
find_var
(
metric_name
).
get_tensor
())
metric
=
np
.
array
(
scope
.
find_var
(
metric_name
).
get_tensor
())
old_metric_shape
=
np
.
array
(
metric
.
shape
)
old_metric_shape
=
np
.
array
(
metric
.
shape
)
metric
=
metric
.
reshape
(
-
1
)
metric
=
metric
.
reshape
(
-
1
)
...
@@ -60,6 +101,11 @@ class PaddleAUCMetric(Metric):
...
@@ -60,6 +101,11 @@ class PaddleAUCMetric(Metric):
return
global_metric
[
0
]
return
global_metric
[
0
]
def
get_global_metrics
(
self
,
scope
,
metric_dict
):
def
get_global_metrics
(
self
,
scope
,
metric_dict
):
"""
reduce all metric in metric_dict from all worker
Return:
dict : {matric_name : metric_result}
"""
fleet
.
_role_maker
.
_barrier_worker
()
fleet
.
_role_maker
.
_barrier_worker
()
result
=
{}
result
=
{}
for
metric_name
in
metric_dict
:
for
metric_name
in
metric_dict
:
...
@@ -71,6 +117,7 @@ class PaddleAUCMetric(Metric):
...
@@ -71,6 +117,7 @@ class PaddleAUCMetric(Metric):
return
result
return
result
def
calculate_auc
(
self
,
global_pos
,
global_neg
):
def
calculate_auc
(
self
,
global_pos
,
global_neg
):
""" """
num_bucket
=
len
(
global_pos
)
num_bucket
=
len
(
global_pos
)
area
=
0.0
area
=
0.0
pos
=
0.0
pos
=
0.0
...
@@ -95,6 +142,7 @@ class PaddleAUCMetric(Metric):
...
@@ -95,6 +142,7 @@ class PaddleAUCMetric(Metric):
return
auc_value
return
auc_value
def
calculate_bucket_error
(
self
,
global_pos
,
global_neg
):
def
calculate_bucket_error
(
self
,
global_pos
,
global_neg
):
""" """
num_bucket
=
len
(
global_pos
)
num_bucket
=
len
(
global_pos
)
last_ctr
=
-
1.0
last_ctr
=
-
1.0
impression_sum
=
0.0
impression_sum
=
0.0
...
@@ -141,6 +189,7 @@ class PaddleAUCMetric(Metric):
...
@@ -141,6 +189,7 @@ class PaddleAUCMetric(Metric):
return
bucket_error
return
bucket_error
def
calculate
(
self
,
scope
,
params
):
def
calculate
(
self
,
scope
,
params
):
""" """
self
.
_label
=
params
[
'label'
]
self
.
_label
=
params
[
'label'
]
self
.
_metric_dict
=
params
[
'metric_dict'
]
self
.
_metric_dict
=
params
[
'metric_dict'
]
fleet
.
_role_maker
.
_barrier_worker
()
fleet
.
_role_maker
.
_barrier_worker
()
...
@@ -165,9 +214,11 @@ class PaddleAUCMetric(Metric):
...
@@ -165,9 +214,11 @@ class PaddleAUCMetric(Metric):
return
result
return
result
def
get_result
(
self
):
def
get_result
(
self
):
""" """
return
self
.
_result
return
self
.
_result
def
get_result_to_string
(
self
):
def
get_result_to_string
(
self
):
""" """
result
=
self
.
get_result
()
result
=
self
.
get_result
()
result_str
=
"%s AUC=%.6f BUCKET_ERROR=%.6f MAE=%.6f RMSE=%.6f "
\
result_str
=
"%s AUC=%.6f BUCKET_ERROR=%.6f MAE=%.6f RMSE=%.6f "
\
"Actural_CTR=%.6f Predicted_CTR=%.6f COPC=%.6f MEAN Q_VALUE=%.6f Ins number=%s"
%
\
"Actural_CTR=%.6f Predicted_CTR=%.6f COPC=%.6f MEAN Q_VALUE=%.6f Ins number=%s"
%
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录