def build_and_test_estimator(self, model_type): """Ensure that model trains and minimizes loss.""" model = wide_deep.build_estimator(self.temp_dir, model_type) # Train for 1 step to initialize model and evaluate initial loss model.train(input_fn=wide_deep.input_fn(TEST_TRAINING_CSV, num_epochs=1, shuffle=True, batch_size=1), steps=1) initial_results = model.evaluate(input_fn=wide_deep.input_fn( TEST_TRAINING_CSV, num_epochs=1, shuffle=False, batch_size=1)) # Train for 40 steps at batch size 2 and evaluate final loss model.train(input_fn=wide_deep.input_fn(TEST_TRAINING_CSV, num_epochs=None, shuffle=True, batch_size=2), steps=40) final_results = model.evaluate(input_fn=wide_deep.input_fn( TEST_TRAINING_CSV, num_epochs=1, shuffle=False, batch_size=1)) print('%s initial results:' % model_type, initial_results) print('%s final results:' % model_type, final_results) self.assertLess(final_results['loss'], initial_results['loss'])
def build_and_test_estimator(self, model_type): """Ensure that model trains and minimizes loss.""" model = wide_deep.build_estimator(self.temp_dir, model_type) # Train for 1 step to initialize model and evaluate initial loss model.train( input_fn=lambda: wide_deep.input_fn( TEST_CSV, num_epochs=1, shuffle=True, batch_size=1), steps=1) initial_results = model.evaluate( input_fn=lambda: wide_deep.input_fn( TEST_CSV, num_epochs=1, shuffle=False, batch_size=1)) # Train for 100 epochs at batch size 3 and evaluate final loss model.train( input_fn=lambda: wide_deep.input_fn( TEST_CSV, num_epochs=100, shuffle=True, batch_size=3)) final_results = model.evaluate( input_fn=lambda: wide_deep.input_fn( TEST_CSV, num_epochs=1, shuffle=False, batch_size=1)) print('%s initial results:' % model_type, initial_results) print('%s final results:' % model_type, final_results) # Ensure loss has decreased, while accuracy and both AUCs have increased. self.assertLess(final_results['loss'], initial_results['loss']) self.assertGreater(final_results['auc'], initial_results['auc']) self.assertGreater(final_results['auc_precision_recall'], initial_results['auc_precision_recall']) self.assertGreater(final_results['accuracy'], initial_results['accuracy'])