def preprocessing_fn(self, inputs: Dict): """ Standard preprocessing function. Args: inputs: Dict mapping features to their respective data. Returns: output: Dict mapping transformed features to their respective transformed data. """ schema = infer_schema(inputs) output = {} for key, value in inputs.items(): if key not in self.f_dict: self.f_dict[key] = self.f_d_dict[schema[key]] value = self.apply_filling(value, self.f_dict[key]) if key in self.features or key in self.labels: if key not in self.t_dict: self.t_dict[key] = self.t_d_dict[schema[key]] result = self.apply_transform(key, value, self.t_dict[key]) result = tf.cast(result, dtype=tf.float32) if key in self.features: output[naming_utils.transformed_feature_name(key)] = result if key in self.labels: output[naming_utils.transformed_label_name(key)] = result output[key] = value return output
}] } })) training_pipeline.add_trainer( TFFeedForwardTrainer(loss='binary_crossentropy', last_activation='sigmoid', output_units=1, metrics=['accuracy'], epochs=20)) # Add an evaluator training_pipeline.add_evaluator( TFMAEvaluator(slices=[['has_diabetes']], metrics={ transformed_label_name('has_diabetes'): ['binary_crossentropy', 'binary_accuracy'] })) # Add the deployer training_pipeline.add_deployment( GCAIPDeployer( project_id=GCP_PROJECT, model_name=MODEL_NAME, )) # Run the pipeline training_pipeline.run() # Another way to do is is to create a DeploymentPipeline. # Uncomment to create the model via this pipeline
], labels=['has_diabetes'], overwrite={ 'has_diabetes': { 'transform': [{ 'method': 'no_transform', 'parameters': {} }] } })) # Add a trainer training_pipeline.add_trainer(MyScikitTrainer( C=0.8, kernel='rbf', )) # Add an evaluator label_name = naming_utils.transformed_label_name('has_diabetes') training_pipeline.add_evaluator( AgnosticEvaluator(prediction_key=naming_utils.output_name(label_name), label_key=label_name, slices=[['has_diabetes']], metrics=['mean_squared_error'])) # Run the pipeline locally training_pipeline.run() # Evaluate training_pipeline.evaluate()
} })) # Add a trainer training_pipeline.add_trainer( TFFeedForwardTrainer(loss='binary_crossentropy', last_activation='sigmoid', output_units=1, metrics=['accuracy'], epochs=20)) # Add an evaluator training_pipeline.add_evaluator( TFMAEvaluator(slices=[['has_diabetes']], metrics={ transformed_label_name('has_diabetes'): ['binary_crossentropy', 'binary_accuracy'] })) # Run the pipeline locally training_pipeline.run() # Run inference model_uri = training_pipeline.get_model_uri() infer_pipeline = BatchInferencePipeline(model_uri=model_uri, ) infer_pipeline.add_datasource(ds) infer_pipeline.add_infer_step( TensorflowInferrer(labels=[transformed_label_name('has_diabetes')])) infer_pipeline.run() df = infer_pipeline.get_predictions() print(df.head())