|
14 | 14 | "3. Model training with **TF Estimator**.\n", |
15 | 15 | "4. Model evaluation with **TF Model Analysis**.\n", |
16 | 16 | "\n", |
17 | | - "<a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/training-data-analyst/blob/master/courses/machine_learning/sme_academy/02_tfx_end_to_end.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" |
| 17 | + "<a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/tf-estimator-tutorials/blob/master/00_Miscellaneous/tfx/02_tfx_end_to_end.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" |
18 | 18 | ] |
19 | 19 | }, |
20 | 20 | { |
|
469 | 469 | " for feature in raw_schema.feature:\n", |
470 | 470 | " feature_name = feature.name\n", |
471 | 471 | " \n", |
472 | | - " if feature_name in ['income_bracket', 'fnlwgt']:\n", |
| 472 | + " # Pass the target feature as is.\n", |
| 473 | + " if feature_name == TARGET_FEATURE_NAME:\n", |
473 | 474 | " processed_features[feature_name] = input_features[feature_name]\n", |
474 | 475 | " continue\n", |
475 | 476 | "\n", |
|
480 | 481 | " # normalize numeric features.\n", |
481 | 482 | " processed_features[feature_name+\"_scaled\"] = tft.scale_to_z_score(input_features[feature_name])\n", |
482 | 483 | "\n", |
| 484 | + " # Pass the weight column\n", |
| 485 | + " processed_features[WEIGHT_COLUMN_NAME] = input_features[WEIGHT_COLUMN_NAME]\n", |
| 486 | + "\n", |
483 | 487 | " # Bucketize age using quantiles. \n", |
484 | 488 | " quantiles = tft.quantiles(input_features[\"age\"], num_buckets=5, epsilon=0.01)\n", |
485 | 489 | " processed_features[\"age_bucketized\"] = tft.apply_buckets(\n", |
|
536 | 540 | " # Load TFDV schema and create tft schema from it.\n", |
537 | 541 | " source_raw_schema = tfdv.load_schema_text(raw_schema_location)\n", |
538 | 542 | " raw_feature_spec = schema_utils.schema_as_feature_spec(source_raw_schema).feature_spec\n", |
| 543 | + " # Since the raw_feature_spec doesn't include the weight column, we need ot add it. \n", |
| 544 | + " raw_feature_spec[WEIGHT_COLUMN_NAME] = tf.FixedLenFeature(\n", |
| 545 | + " shape=[1], dtype=tf.int64, default_value=None)\n", |
539 | 546 | " raw_metadata = dataset_metadata.DatasetMetadata(\n", |
540 | 547 | " dataset_schema.from_feature_spec(raw_feature_spec))\n", |
541 | 548 | "\n", |
|
1096 | 1103 | " source_raw_schema = tfdv.load_schema_text(RAW_SCHEMA_LOCATION)\n", |
1097 | 1104 | " raw_feature_spec = schema_utils.schema_as_feature_spec(source_raw_schema).feature_spec\n", |
1098 | 1105 | " raw_feature_spec.pop(TARGET_FEATURE_NAME)\n", |
1099 | | - " raw_feature_spec.pop(WEIGHT_COLUMN_NAME)\n", |
1100 | 1106 | "\n", |
1101 | 1107 | " # Create the interface for the serving function with the raw features\n", |
1102 | 1108 | " raw_features = tf.estimator.export.build_parsing_serving_input_receiver_fn(raw_feature_spec)().features\n", |
|
1137 | 1143 | " \n", |
1138 | 1144 | "estimator.export_savedmodel(\n", |
1139 | 1145 | " export_dir_base=export_dir,\n", |
1140 | | - " serving_input_receiver_fn=input_receiver_fn\n", |
| 1146 | + " serving_input_receiver_fn=serving_input_receiver_fn\n", |
1141 | 1147 | ")" |
1142 | 1148 | ] |
1143 | 1149 | }, |
|
0 commit comments