Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Add plot and add more iterations to draw plot in jupyter for chapter 5 #546

Merged
merged 1 commit into from
Jun 18, 2018
Merged
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
10 changes: 9 additions & 1 deletion 05.recommender_system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,27 @@ For example, we can check the cost by `trainer.test` when `EndStepEvent` occurs
# Specify the directory path to save the parameters
params_dirname = "recommender_system.inference.model"

from paddle.v2.plot import Ploter
test_title = "Test cost"
plot_cost = Ploter(test_title)


def event_handler(event):
if isinstance(event, fluid.EndStepEvent):
avg_cost_set = trainer.test(
reader=test_reader, feed_order=feed_order)

# get avg cost
avg_cost = np.array(avg_cost_set).mean()

plot_cost.append(test_title, event.step, avg_cost_set[0])
plot_cost.plot()

print("avg_cost: %s" % avg_cost)
print('BatchID {0}, Test Loss {1:0.2}'.format(event.epoch + 1,
float(avg_cost)))

if float(avg_cost) < 4:
if event.step == 20: # Adjust this number for accuracy
trainer.save_params(params_dirname)
trainer.stop()

Expand Down