Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Pytorch Widedeep
提交
f1926c6b
P
Pytorch Widedeep
项目概览
Greenplum
/
Pytorch Widedeep
11 个月 前同步成功
通知
9
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Pytorch Widedeep
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f1926c6b
编写于
11月 30, 2021
作者:
P
Pavol Mulinka
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
changed multiregression to multilabel for future use of multilabel task
上级
34ad5576
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
25 addition
and
16 deletion
+25
-16
pytorch_widedeep/losses.py
pytorch_widedeep/losses.py
+2
-1
pytorch_widedeep/training/_loss_and_obj_aliases.py
pytorch_widedeep/training/_loss_and_obj_aliases.py
+1
-1
pytorch_widedeep/training/trainer.py
pytorch_widedeep/training/trainer.py
+18
-10
tests/test_losses/test_losses.py
tests/test_losses/test_losses.py
+4
-4
未找到文件。
pytorch_widedeep/losses.py
浏览文件 @
f1926c6b
...
@@ -57,6 +57,7 @@ class QuantileLoss(nn.Module):
...
@@ -57,6 +57,7 @@ class QuantileLoss(nn.Module):
assert
input
.
shape
==
torch
.
Size
(
assert
input
.
shape
==
torch
.
Size
(
[
target
.
shape
[
0
],
len
(
self
.
quantiles
)]
[
target
.
shape
[
0
],
len
(
self
.
quantiles
)]
),
f
"Wrong shape of input, pred_dim of the model that is using QuantileLoss must be equal to number of quantiles, i.e.
{
len
(
self
.
quantiles
)
}
."
),
f
"Wrong shape of input, pred_dim of the model that is using QuantileLoss must be equal to number of quantiles, i.e.
{
len
(
self
.
quantiles
)
}
."
target
=
target
.
view
(
-
1
,
1
).
float
()
losses
=
[]
losses
=
[]
for
i
,
q
in
enumerate
(
self
.
quantiles
):
for
i
,
q
in
enumerate
(
self
.
quantiles
):
errors
=
target
-
input
[...,
i
]
errors
=
target
-
input
[...,
i
]
...
@@ -80,7 +81,7 @@ class ZILNLoss(nn.Module):
...
@@ -80,7 +81,7 @@ class ZILNLoss(nn.Module):
Parameters
Parameters
----------
----------
input: Tensor
input: Tensor
input tensor with predictions (not probabilities)
input tensor with predictions (not probabilities)
with spape (N,3), where N is the batch size
target: Tensor
target: Tensor
target tensor with the actual classes
target tensor with the actual classes
...
...
pytorch_widedeep/training/_loss_and_obj_aliases.py
浏览文件 @
f1926c6b
...
@@ -75,7 +75,7 @@ class _ObjectiveToMethod:
...
@@ -75,7 +75,7 @@ class _ObjectiveToMethod:
"zero_inflated_lognormal"
:
"regression"
,
"zero_inflated_lognormal"
:
"regression"
,
"ziln"
:
"regression"
,
"ziln"
:
"regression"
,
"tweedie"
:
"regression"
,
"tweedie"
:
"regression"
,
"quantile"
:
"multi
regression
"
,
"quantile"
:
"multi
label
"
,
}
}
@
classproperty
@
classproperty
...
...
pytorch_widedeep/training/trainer.py
浏览文件 @
f1926c6b
...
@@ -97,7 +97,7 @@ class Trainer:
...
@@ -97,7 +97,7 @@ class Trainer:
folder in the repo.
folder in the repo.
.. note:: If ``custom_loss_function`` is not None, ``objective`` must be
.. note:: If ``custom_loss_function`` is not None, ``objective`` must be
'binary', 'multiclass', 'multi
regression
' or 'regression', consistent with the loss
'binary', 'multiclass', 'multi
label
' or 'regression', consistent with the loss
function
function
optimizers: ``Optimzer`` or dict, optional, default= None
optimizers: ``Optimzer`` or dict, optional, default= None
...
@@ -265,11 +265,11 @@ class Trainer:
...
@@ -265,11 +265,11 @@ class Trainer:
"binary"
,
"binary"
,
"multiclass"
,
"multiclass"
,
"regression"
,
"regression"
,
"multi
regression
"
,
"multi
label
"
,
]:
]:
raise
ValueError
(
raise
ValueError
(
"If 'custom_loss_function' is not None, 'objective' must be 'binary' "
"If 'custom_loss_function' is not None, 'objective' must be 'binary' "
"'multiclass', 'regression' or 'multi
regression
', consistent with the loss function"
"'multiclass', 'regression' or 'multi
label
', consistent with the loss function"
)
)
self
.
reducelronplateau
=
False
self
.
reducelronplateau
=
False
...
@@ -705,7 +705,7 @@ class Trainer:
...
@@ -705,7 +705,7 @@ class Trainer:
if
self
.
method
==
"binary"
:
if
self
.
method
==
"binary"
:
preds
=
np
.
vstack
(
preds_l
).
squeeze
(
1
)
preds
=
np
.
vstack
(
preds_l
).
squeeze
(
1
)
return
(
preds
>
0.5
).
astype
(
"int"
)
return
(
preds
>
0.5
).
astype
(
"int"
)
if
self
.
method
==
"multi
regression
"
:
if
self
.
method
==
"multi
label
"
:
return
np
.
vstack
(
preds_l
)
return
np
.
vstack
(
preds_l
)
if
self
.
method
==
"multiclass"
:
if
self
.
method
==
"multiclass"
:
preds
=
np
.
vstack
(
preds_l
)
preds
=
np
.
vstack
(
preds_l
)
...
@@ -802,9 +802,9 @@ class Trainer:
...
@@ -802,9 +802,9 @@ class Trainer:
preds
.
std
(
axis
=
0
),
preds
.
std
(
axis
=
0
),
)
)
).
T
).
T
if
self
.
method
==
"multi
regression
"
:
if
self
.
method
==
"multi
label
"
:
raise
ValueError
(
raise
ValueError
(
"Currently predict_uncertainty is not supported for multi
regression
method"
"Currently predict_uncertainty is not supported for multi
label
method"
)
)
if
self
.
method
==
"binary"
:
if
self
.
method
==
"binary"
:
preds
=
preds
.
squeeze
(
1
)
preds
=
preds
.
squeeze
(
1
)
...
@@ -1154,7 +1154,11 @@ class Trainer:
...
@@ -1154,7 +1154,11 @@ class Trainer:
def
_train_step
(
self
,
data
:
Dict
[
str
,
Tensor
],
target
:
Tensor
,
batch_idx
:
int
):
def
_train_step
(
self
,
data
:
Dict
[
str
,
Tensor
],
target
:
Tensor
,
batch_idx
:
int
):
self
.
model
.
train
()
self
.
model
.
train
()
X
=
{
k
:
v
.
cuda
()
for
k
,
v
in
data
.
items
()}
if
use_cuda
else
data
X
=
{
k
:
v
.
cuda
()
for
k
,
v
in
data
.
items
()}
if
use_cuda
else
data
y
=
target
.
view
(
-
1
,
1
).
float
()
if
self
.
method
!=
"multiclass"
else
target
y
=
(
target
.
view
(
-
1
,
1
).
float
()
if
self
.
method
not
in
[
"multiclass"
,
"multilabel"
]
else
target
)
y
=
y
.
to
(
device
)
y
=
y
.
to
(
device
)
self
.
optimizer
.
zero_grad
()
self
.
optimizer
.
zero_grad
()
...
@@ -1179,7 +1183,11 @@ class Trainer:
...
@@ -1179,7 +1183,11 @@ class Trainer:
self
.
model
.
eval
()
self
.
model
.
eval
()
with
torch
.
no_grad
():
with
torch
.
no_grad
():
X
=
{
k
:
v
.
cuda
()
for
k
,
v
in
data
.
items
()}
if
use_cuda
else
data
X
=
{
k
:
v
.
cuda
()
for
k
,
v
in
data
.
items
()}
if
use_cuda
else
data
y
=
target
.
view
(
-
1
,
1
).
float
()
if
self
.
method
!=
"multiclass"
else
target
y
=
(
target
.
view
(
-
1
,
1
).
float
()
if
self
.
method
not
in
[
"multiclass"
,
"multilabel"
]
else
target
)
y
=
y
.
to
(
device
)
y
=
y
.
to
(
device
)
y_pred
=
self
.
model
(
X
)
y_pred
=
self
.
model
(
X
)
...
@@ -1201,7 +1209,7 @@ class Trainer:
...
@@ -1201,7 +1209,7 @@ class Trainer:
score
=
self
.
metric
(
y_pred
,
y
)
score
=
self
.
metric
(
y_pred
,
y
)
if
self
.
method
==
"binary"
:
if
self
.
method
==
"binary"
:
score
=
self
.
metric
(
torch
.
sigmoid
(
y_pred
),
y
)
score
=
self
.
metric
(
torch
.
sigmoid
(
y_pred
),
y
)
if
self
.
method
==
"multi
regression
"
:
if
self
.
method
==
"multi
label
"
:
score
=
self
.
metric
(
y_pred
,
y
)
score
=
self
.
metric
(
y_pred
,
y
)
if
self
.
method
==
"multiclass"
:
if
self
.
method
==
"multiclass"
:
score
=
self
.
metric
(
F
.
softmax
(
y_pred
,
dim
=
1
),
y
)
score
=
self
.
metric
(
F
.
softmax
(
y_pred
,
dim
=
1
),
y
)
...
@@ -1318,7 +1326,7 @@ class Trainer:
...
@@ -1318,7 +1326,7 @@ class Trainer:
if
custom_loss_function
is
not
None
:
if
custom_loss_function
is
not
None
:
return
custom_loss_function
return
custom_loss_function
elif
(
elif
(
self
.
method
not
in
[
"regression"
,
"multi
regression
"
]
self
.
method
not
in
[
"regression"
,
"multi
label
"
]
and
"focal_loss"
not
in
objective
and
"focal_loss"
not
in
objective
):
):
return
alias_to_loss
(
objective
,
weight
=
class_weight
)
return
alias_to_loss
(
objective
,
weight
=
class_weight
)
...
...
tests/test_losses/test_losses.py
浏览文件 @
f1926c6b
...
@@ -161,7 +161,7 @@ method_to_objec = {
...
@@ -161,7 +161,7 @@ method_to_objec = {
"ziln"
,
"ziln"
,
"tweedie"
,
"tweedie"
,
],
],
"multi
regression
"
:
[
"multi
label
"
:
[
"quantile"
,
"quantile"
,
],
],
}
}
...
@@ -230,7 +230,7 @@ method_to_objec = {
...
@@ -230,7 +230,7 @@ method_to_objec = {
False
,
False
,
),
),
(
X_wide
,
X_tab
,
target_regres
,
"regression"
,
"ziln"
,
3
,
1
,
False
),
(
X_wide
,
X_tab
,
target_regres
,
"regression"
,
"ziln"
,
3
,
1
,
False
),
(
X_wide
,
X_tab
,
target_regres
,
"multi
regression
"
,
"quantile"
,
7
,
7
,
False
),
(
X_wide
,
X_tab
,
target_regres
,
"multi
label
"
,
"quantile"
,
7
,
7
,
False
),
(
X_wide
,
X_tab
,
target_regres
,
"regression"
,
"tweedie"
,
1
,
1
,
True
),
(
X_wide
,
X_tab
,
target_regres
,
"regression"
,
"tweedie"
,
1
,
1
,
True
),
(
X_wide
,
X_tab
,
target_binary
,
"binary"
,
"binary"
,
1
,
2
,
False
),
(
X_wide
,
X_tab
,
target_binary
,
"binary"
,
"binary"
,
1
,
2
,
False
),
(
X_wide
,
X_tab
,
target_binary
,
"binary"
,
"logistic"
,
1
,
2
,
False
),
(
X_wide
,
X_tab
,
target_binary
,
"binary"
,
"logistic"
,
1
,
2
,
False
),
...
@@ -292,7 +292,7 @@ def test_all_possible_objectives(
...
@@ -292,7 +292,7 @@ def test_all_possible_objectives(
if
method
==
"regression"
:
if
method
==
"regression"
:
preds
=
trainer
.
predict
(
X_wide
=
X_wide
,
X_tab
=
X_tab
)
preds
=
trainer
.
predict
(
X_wide
=
X_wide
,
X_tab
=
X_tab
)
out
.
append
(
preds
.
ndim
==
probs_dim
)
out
.
append
(
preds
.
ndim
==
probs_dim
)
elif
method
==
"multi
regression
"
:
elif
method
==
"multi
label
"
:
preds
=
trainer
.
predict
(
X_wide
=
X_wide
,
X_tab
=
X_tab
)
preds
=
trainer
.
predict
(
X_wide
=
X_wide
,
X_tab
=
X_tab
)
out
.
append
(
preds
.
shape
[
1
]
==
probs_dim
)
out
.
append
(
preds
.
shape
[
1
]
==
probs_dim
)
else
:
else
:
...
@@ -323,6 +323,6 @@ def test_inverse_maps():
...
@@ -323,6 +323,6 @@ def test_inverse_maps():
out
.
append
(
out
.
append
(
"zero_inflated_lognormal"
in
_ObjectiveToMethod
.
method_to_objecive
[
"regression"
]
"zero_inflated_lognormal"
in
_ObjectiveToMethod
.
method_to_objecive
[
"regression"
]
)
)
out
.
append
(
"quantile"
in
_ObjectiveToMethod
.
method_to_objecive
[
"multi
regression
"
])
out
.
append
(
"quantile"
in
_ObjectiveToMethod
.
method_to_objecive
[
"multi
label
"
])
out
.
append
(
"tweedie"
in
_ObjectiveToMethod
.
method_to_objecive
[
"regression"
])
out
.
append
(
"tweedie"
in
_ObjectiveToMethod
.
method_to_objecive
[
"regression"
])
assert
all
(
out
)
assert
all
(
out
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录