Example of training survival model with Dask on CPU
DaskDMatrix
def
main
(
client
:
Client
)
->
:
CURRENT_DIR
=
(
__file__
)
df
=
(
(
CURRENT_DIR
,
,
"data"
,
"veterans_lung_cancer.csv"
)
)
y_lower_bound
=
df
[
"Survival_label_lower_bound"
]
y_upper_bound
=
df
[
"Survival_label_upper_bound"
]
X
=
df
.
drop
([
"Survival_label_lower_bound"
,
"Survival_label_upper_bound"
],
axis
=
1
)
dtrain
=
DaskDMatrix
(
client
,
X
,
label_lower_bound
=
y_lower_bound
,
label_upper_bound
=
y_upper_bound
)
params
=
{
"verbosity"
:
1
,
"objective"
:
"survival:aft"
,
"eval_metric"
:
"aft-nloglik"
,
"learning_rate"
:
0.05
,
"aft_loss_distribution_scale"
:
1.20
,
"aft_loss_distribution"
:
"normal"
,
"max_depth"
:
6
,
"lambda"
:
0.01
,
"alpha"
:
0.02
,
}
output
=
dxgb
.
train
(
client
,
params
,
dtrain
,
num_boost_round
=
100
,
evals
=
[(
dtrain
,
"train"
)]
)
bst
=
output
[
"booster"
]
history
=
output
[
"history"
]
prediction
=
dxgb
.
predict
(
client
,
bst
,
dtrain
)
print
(
"Evaluation history: "
,
history
)
return
prediction
if
__name__
==
"__main__"
:
with
LocalCluster
(
n_workers
=
7
,
threads_per_worker
=
4
)
as
cluster
:
with
Client
(
cluster
)
as
client
:
main
(
client
)