Skip to content

Update python tests #160

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

Merged
merged 2 commits into from
Jun 12, 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
18 changes: 12 additions & 6 deletions examples/insurance/implementations/models/dnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@


def create_estimator(run_config, model_config):
aggregates = model_config["input"]["aggregates"]

feature_columns = [
tf.feature_column.indicator_column(
tf.feature_column.categorical_column_with_vocabulary_list("sex", ["female", "male"])
tf.feature_column.categorical_column_with_vocabulary_list(
"sex", aggregates["sex_vocab"]
)
),
tf.feature_column.indicator_column(
tf.feature_column.categorical_column_with_vocabulary_list("smoker", ["yes", "no"])
tf.feature_column.categorical_column_with_vocabulary_list(
"smoker", aggregates["smoker_vocab"]
)
),
tf.feature_column.indicator_column(
tf.feature_column.categorical_column_with_vocabulary_list(
"region", ["northwest", "northeast", "southwest", "southeast"]
"region", aggregates["region_vocab"]
)
),
tf.feature_column.bucketized_column(
tf.feature_column.numeric_column("age"), [15, 20, 25, 35, 40, 45, 50, 55, 60, 65]
tf.feature_column.numeric_column("age"), aggregates["age_buckets"]
),
tf.feature_column.bucketized_column(
tf.feature_column.numeric_column("bmi"), [15, 20, 25, 35, 40, 45, 50, 55]
tf.feature_column.numeric_column("bmi"), aggregates["bmi_buckets"]
),
tf.feature_column.indicator_column(
tf.feature_column.categorical_column_with_vocabulary_list(
"children", model_config["aggregates"]["children_set"]
"children", aggregates["children_set"]
)
),
]
Expand Down
2 changes: 1 addition & 1 deletion examples/insurance/resources/apis.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- kind: api
name: cost
model_name: dnn
model: @dnn
compute:
replicas: 1
9 changes: 1 addition & 8 deletions examples/insurance/resources/environments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,4 @@
data:
type: csv
path: s3a://cortex-examples/insurance.csv
schema:
- age
- sex
- bmi
- children
- smoker
- region
- charges
schema: [@age, @sex, @bmi, @children, @smoker, @region, @charges]
22 changes: 7 additions & 15 deletions examples/insurance/resources/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,22 @@
- kind: aggregate
name: charges_mean
aggregator: cortex.mean
inputs:
columns:
col: charges
input: @charges

- kind: aggregate
name: charges_stddev
aggregator: cortex.stddev
inputs:
columns:
col: charges
input: @charges

- kind: aggregate
name: children_set
aggregator: cortex.collect_set_int
inputs:
columns:
col: children
input: @children

- kind: transformed_column
name: charges_normalized
transformer: cortex.normalize
inputs:
columns:
num: charges
args:
mean: charges_mean
stddev: charges_stddev
input:
col: @charges
mean: @charges_mean
stddev: @charges_stddev
22 changes: 11 additions & 11 deletions examples/insurance/resources/models.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
- kind: model
name: dnn
type: regression
target_column: charges_normalized
feature_columns:
- age
- sex
- bmi
- children
- smoker
- region
estimator_path: implementations/models/dnn.py
target_column: @charges_normalized
input:
features: [@age, @sex, @bmi, @children, @smoker, @region, @charges]
aggregates:
children_set: @children_set
region_vocab: ["northwest", "northeast", "southwest", "southeast"]
age_buckets: [15, 20, 25, 35, 40, 45, 50, 55, 60, 65]
bmi_buckets: [15, 20, 25, 35, 40, 45, 50, 55]
smoker_vocab: ["yes", "no"]
sex_vocab: ["female", "male"]
hparams:
hidden_units: [100, 100, 100]
data_partition_ratio:
training: 0.8
evaluation: 0.2
training:
num_steps: 10000
aggregates:
- children_set
4 changes: 2 additions & 2 deletions pkg/workloads/lib/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,8 @@ def _deserialize_raw_ctx(raw_ctx):
# input should already have non-column arguments replaced, and all types validated
def create_transformer_inputs_from_map(input, col_value_map):
if util.is_str(input):
res_name = util.get_resource_ref(input)
if res_name is not None and res_name in col_value_map:
if util.is_resource_ref(input):
res_name = util.get_resource_ref(input)
return col_value_map[res_name]
return input

Expand Down
9 changes: 4 additions & 5 deletions pkg/workloads/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,19 +879,18 @@ def is_resource_ref(obj):

def get_resource_ref(obj):
if not is_str(obj):
return None
raise ValueError("expected input of type string but received " + str(type(obj)))
if obj.startswith(resource_escape_seq):
return obj[len(resource_escape_seq) :]
elif obj.startswith(resource_escape_seq_raw):
return obj[len(resource_escape_seq_raw) :]
return None
raise ValueError("expected a resource reference but got " + obj)


def extract_resource_refs(input):
if is_str(input):
res = get_resource_ref(input)
if res is not None:
return {res}
if is_resource_ref(input):
return {get_resource_ref(input)}
return set()

if is_list(input):
Expand Down
Loading