`paddle.dataset.movielens.train` will yield records during each pass, after shuffling, a batch input is generated for training.
```python
%matplotlibinline
reader=paddle.reader.batch(
paddle.reader.shuffle(
paddle.dataset.movielens.trai(),buf_size=8192),
batch_size=256)
```
importmatplotlib.pyplotasplt
fromIPythonimportdisplay
importcPickle
`feeding` is devoted to specify the correspondence between each yield record and `paddle.layer.data`. For instance, the first column of data generated by `movielens.train` corresponds to `user_id` feature.
```python
feeding={
'user_id':0,
'gender_id':1,
...
...
@@ -312,12 +310,11 @@ feeding = {
'movie_title':6,
'score':7
}
```
step=0
train_costs=[],[]
test_costs=[],[]
Callback function `event_handler` is used to track training and testing process that might be triggered once the action to which it is attached is executed.
```python
defevent_handler(event):
globalstep
globaltrain_costs
...
...
@@ -342,15 +339,27 @@ def event_handler(event):
display.display(plt.gcf())
plt.gcf().clear()
step+=1
```
Finally, we can invoke `trainer.train` to start training: