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

Make confusion_matrix and roc generic #1285

Merged
merged 1 commit into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions components/local/confusion_matrix/src/confusion_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import argparse
import json
import os
import urlparse
import pandas as pd
from sklearn.metrics import confusion_matrix, accuracy_score
from tensorflow.python.lib.io import file_io
Expand All @@ -40,7 +41,8 @@ def main(argv=None):
'If not set, the input must include a "target" column.')
args = parser.parse_args()

on_cloud = args.output.startswith('gs://')
storage_service_scheme = urlparse.urlparse(args.output).scheme
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few cases are

  • minio://dir/file_path
  • gs://dir/file_path
  • s3://dir/file_path
  • local path "/dir/file_path"

scheme for local path is empty, all rest we consider they are on_cloud

on_cloud = True if storage_service_scheme else False
if not on_cloud and not os.path.exists(args.output):
os.makedirs(args.output)

Expand All @@ -52,7 +54,7 @@ def main(argv=None):
for file in files:
with file_io.FileIO(file, 'r') as f:
dfs.append(pd.read_csv(f, names=names))

df = pd.concat(dfs)
if args.target_lambda:
df['target'] = df.apply(eval(args.target_lambda), axis=1)
Expand All @@ -72,7 +74,6 @@ def main(argv=None):
metadata = {
'outputs' : [{
'type': 'confusion_matrix',
'storage': 'gcs',
'format': 'csv',
'schema': [
{'name': 'target', 'type': 'CATEGORY'},
Expand Down
9 changes: 5 additions & 4 deletions components/local/roc/src/roc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import argparse
import json
import os
import urlparse
import pandas as pd
from sklearn.metrics import roc_curve, roc_auc_score
from tensorflow.python.lib.io import file_io
Expand All @@ -45,7 +46,8 @@ def main(argv=None):
parser.add_argument('--output', type=str, help='GCS path of the output directory.')
args = parser.parse_args()

on_cloud = args.output.startswith('gs://')
storage_service_scheme = urlparse.urlparse(args.output).scheme
on_cloud = True if storage_service_scheme else False
if not on_cloud and not os.path.exists(args.output):
os.makedirs(args.output)

Expand All @@ -64,7 +66,7 @@ def main(argv=None):
for file in files:
with file_io.FileIO(file, 'r') as f:
dfs.append(pd.read_csv(f, names=names))

df = pd.concat(dfs)
if args.target_lambda:
df['target'] = df.apply(eval(args.target_lambda), axis=1)
Expand All @@ -76,11 +78,10 @@ def main(argv=None):
roc_file = os.path.join(args.output, 'roc.csv')
with file_io.FileIO(roc_file, 'w') as f:
df_roc.to_csv(f, columns=['fpr', 'tpr', 'thresholds'], header=False, index=False)

metadata = {
'outputs': [{
'type': 'roc',
'storage': 'gcs',
'format': 'csv',
'schema': [
{'name': 'fpr', 'type': 'NUMBER'},
Expand Down