Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sample] Add back visualization in XGBoost sample #2384

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2d071e6
init.
Sep 19, 2019
962526a
add delete op
Sep 19, 2019
68eb22d
Add new transform and analyze op
Sep 19, 2019
6816f9b
Save.
Sep 20, 2019
ddd1888
Partial work
Sep 23, 2019
383d2f8
partial work
Sep 23, 2019
775335f
WIP
Sep 24, 2019
1bc0664
Clean up code.
Sep 24, 2019
991daf1
Disable xgboost cm check for now.
Sep 24, 2019
d7dc3d1
Merge branch 'master' of https://github.com/kubeflow/pipelines into r…
Sep 24, 2019
fbc06d6
Update commit SHA
Sep 24, 2019
402ce97
Update kw arg
Sep 24, 2019
2c76650
Correct the url format.
Sep 24, 2019
f4ab88e
Merge branch 'master' of https://github.com/kubeflow/pipelines into r…
Sep 30, 2019
72b25d8
Switch to gcp component for create cluster.
Sep 30, 2019
76858d9
add secret
Sep 30, 2019
849b9dd
Merge branch 'master' of https://github.com/kubeflow/pipelines into r…
Oct 10, 2019
57c3906
Merge branch 'master' of https://github.com/kubeflow/pipelines into r…
Oct 11, 2019
a796833
fix create cluster op
Oct 11, 2019
78bdb00
fix path problem
Oct 11, 2019
24fb5b2
Move display name
Oct 11, 2019
8abb149
no op
Oct 11, 2019
e41184b
Improve
Oct 11, 2019
d2a56dc
doc
Oct 11, 2019
ce3adab
Solve
Oct 14, 2019
e1492e6
add back visualization
Oct 14, 2019
dc2c312
fix
Oct 14, 2019
3e89e04
Fix naming
Oct 14, 2019
e25d734
add back check for cm
Oct 14, 2019
e4186a9
remove todo
Oct 14, 2019
d50f6e1
Merge branch 'master' of https://github.com/kubeflow/pipelines into a…
Oct 15, 2019
631f3fb
Update readme
Oct 16, 2019
17fd7c4
fix naming
Oct 16, 2019
81ba446
fix flakiness
Oct 16, 2019
9fcef4c
Revert "fix flakiness"
Oct 16, 2019
612ca9b
Merge branch 'master' of https://github.com/kubeflow/pipelines into a…
Oct 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion samples/core/xgboost_training_cm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
The `xgboost_training_cm.py` pipeline creates XGBoost models on structured data in CSV format. Both classification and regression are supported.

The pipeline starts by creating an Google DataProc cluster, and then running analysis, transformation, distributed training and
prediction in the created cluster. Finally, a delete cluster operation runs to destroy the cluster it creates
prediction in the created cluster.
Then a single node confusion-matrix and ROC aggregator is used (for classification case) to
provide the confusion matrix data, and ROC data to the front end, respectively.
Finally, a delete cluster operation runs to destroy the cluster it creates
in the beginning. The delete cluster operation is used as an exit handler, meaning it will run regardless of whether the pipeline fails
or not.

Expand Down Expand Up @@ -45,3 +48,11 @@ Delete Cluster:

The container file is located [here](https://github.com/kubeflow/pipelines/tree/master/components/gcp/container)

For visualization, we use confusion matrix and ROC.
Confusion Matrix:
[source code](https://github.com/kubeflow/pipelines/tree/master/components/local/confusion_matrix/src),
[container](https://github.com/kubeflow/pipelines/tree/master/components/local/confusion_matrix)
and ROC:
[source code](https://github.com/kubeflow/pipelines/tree/master/components/local/roc/src),
[container](https://github.com/kubeflow/pipelines/tree/master/components/local/roc)

35 changes: 25 additions & 10 deletions samples/core/xgboost_training_cm/xgboost_training_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import os
import subprocess

# TODO(numerology): add ROC and CM back once UI metadata is enabled in this sample.
confusion_matrix_op = components.load_component_from_url('https://raw.githubusercontent.com/kubeflow/pipelines/e598176c02f45371336ccaa819409e8ec83743df/components/local/confusion_matrix/component.yaml')

roc_op = components.load_component_from_url('https://raw.githubusercontent.com/kubeflow/pipelines/e598176c02f45371336ccaa819409e8ec83743df/components/local/roc/component.yaml')

dataproc_create_cluster_op = components.load_component_from_url(
'https://raw.githubusercontent.com/kubeflow/pipelines/677fbaa281125fd604b81eab2488513efee7b600/components/gcp/dataproc/create_cluster/component.yaml')
Expand Down Expand Up @@ -211,6 +213,7 @@ def xgb_train_pipeline(
target='resolution',
rounds=200,
workers=2,
true_label='ACTION',
):
output_template = str(output) + '/' + dsl.RUN_ID_PLACEHOLDER + '/data'

Expand All @@ -227,7 +230,7 @@ def xgb_train_pipeline(
region=region,
name=cluster_name
)):
create_cluster_op = dataproc_create_cluster_op(
_create_cluster_op = dataproc_create_cluster_op(
project_id=project,
region=region,
name=cluster_name,
Expand All @@ -238,16 +241,16 @@ def xgb_train_pipeline(
image_version='1.2'
)

analyze_op = dataproc_analyze_op(
_analyze_op = dataproc_analyze_op(
project=project,
region=region,
cluster_name=cluster_name,
schema=schema,
train_data=train_data,
output=output_template
).after(create_cluster_op).set_display_name('Analyzer')
).after(_create_cluster_op).set_display_name('Analyzer')

transform_op = dataproc_transform_op(
_transform_op = dataproc_transform_op(
project=project,
region=region,
cluster_name=cluster_name,
Expand All @@ -256,9 +259,9 @@ def xgb_train_pipeline(
target=target,
analysis=analyze_output,
output=output_template
).after(analyze_op).set_display_name('Transformer')
).after(_analyze_op).set_display_name('Transformer')

train_op = dataproc_train_op(
_train_op = dataproc_train_op(
project=project,
region=region,
cluster_name=cluster_name,
Expand All @@ -269,9 +272,9 @@ def xgb_train_pipeline(
workers=workers,
rounds=rounds,
output=train_output
).after(transform_op).set_display_name('Trainer')
).after(_transform_op).set_display_name('Trainer')

predict_op = dataproc_predict_op(
_predict_op = dataproc_predict_op(
project=project,
region=region,
cluster_name=cluster_name,
Expand All @@ -280,7 +283,19 @@ def xgb_train_pipeline(
target=target,
analysis=analyze_output,
output=predict_output
).after(train_op).set_display_name('Predictor')
).after(_train_op).set_display_name('Predictor')

_cm_op = confusion_matrix_op(
predictions=os.path.join(predict_output, 'part-*.csv'),
output_dir=output_template
).after(_predict_op)

_roc_op = roc_op(
predictions_dir=os.path.join(predict_output, 'part-*.csv'),
true_class=true_label,
true_score_column=true_label,
output_dir=output_template
).after(_predict_op)

dsl.get_pipeline_conf().add_op_transformer(
gcp.use_gcp_secret('user-gcp-sa'))
Expand Down
29 changes: 14 additions & 15 deletions test/sample-test/run_sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,20 @@ def check(self):
exit(1)

###### Validate the results for specific test cases ######
#TODO: Add result check for tfx-cab-classification after launch.
# if self._testname == 'xgboost_training_cm':
# # For xgboost sample, check its confusion matrix.
# cm_tar_path = './confusion_matrix.tar.gz'
# utils.get_artifact_in_minio(workflow_json, 'confusion-matrix', cm_tar_path,
# 'mlpipeline-ui-metadata')
# with tarfile.open(cm_tar_path) as tar_handle:
# file_handles = tar_handle.getmembers()
# assert len(file_handles) == 1
#
# with tar_handle.extractfile(file_handles[0]) as f:
# cm_data = f.read()
# utils.add_junit_test(self._test_cases, 'confusion matrix format',
# (len(cm_data) > 0),
# 'the confusion matrix file is empty')
if self._testname == 'xgboost_training_cm':
# For xgboost sample, check its confusion matrix.
cm_tar_path = './confusion_matrix.tar.gz'
utils.get_artifact_in_minio(workflow_json, 'confusion-matrix', cm_tar_path,
'mlpipeline-ui-metadata')
with tarfile.open(cm_tar_path) as tar_handle:
file_handles = tar_handle.getmembers()
assert len(file_handles) == 1

with tar_handle.extractfile(file_handles[0]) as f:
cm_data = f.read()
utils.add_junit_test(self._test_cases, 'confusion matrix format',
(len(cm_data) > 0),
'the confusion matrix file is empty')

###### Delete Job ######
#TODO: add deletion when the backend API offers the interface.
Expand Down