Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
c2303f6d
B
book
项目概览
PaddlePaddle
/
book
通知
16
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c2303f6d
编写于
4月 27, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update plot in recomm system
上级
59117048
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
94 deletion
+58
-94
08.recommender_system/README.en.md
08.recommender_system/README.en.md
+14
-24
08.recommender_system/README.md
08.recommender_system/README.md
+15
-23
08.recommender_system/index.en.html
08.recommender_system/index.en.html
+14
-24
08.recommender_system/index.html
08.recommender_system/index.html
+15
-23
未找到文件。
08.recommender_system/README.en.md
浏览文件 @
c2303f6d
...
...
@@ -171,12 +171,6 @@ After issuing a command `python train.py`, training will start immediately. The
First, we must import and initialize PaddlePaddle (enable/disable GPU, set the number of trainers, etc).
```
python
%
matplotlib
inline
import
matplotlib.pyplot
as
plt
from
IPython
import
display
import
cPickle
import
paddle.v2
as
paddle
paddle
.
init
(
use_gpu
=
False
)
```
...
...
@@ -326,34 +320,30 @@ def event_handler(event):
```
```
python
step
=
0
from
paddle.v2.plot
import
Ploter
train_costs
=
[],[]
test_costs
=
[],[]
train_title
=
"Train cost"
test_title
=
"Test cost"
cost_ploter
=
Ploter
(
train_title
,
test_title
)
step
=
0
def
event_handler_plot
(
event
):
global
step
global
train_costs
global
test_costs
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
need_plot
=
False
if
step
%
10
==
0
:
# every 10 batches, record a train cost
train_costs
[
0
].
append
(
step
)
train_costs
[
1
].
append
(
event
.
cost
)
cost_ploter
.
append
(
train_title
,
step
,
event
.
cost
)
if
step
%
1000
==
0
:
# every 1000 batches, record a test cost
result
=
trainer
.
test
(
reader
=
paddle
.
batch
(
paddle
.
dataset
.
movielens
.
test
(),
batch_size
=
256
))
test_costs
[
0
].
append
(
step
)
test_costs
[
1
].
append
(
result
.
cost
)
result
=
trainer
.
test
(
reader
=
paddle
.
batch
(
paddle
.
dataset
.
movielens
.
test
(),
batch_size
=
256
),
feeding
=
feeding
)
cost_ploter
.
append
(
test_title
,
step
,
result
.
cost
)
if
step
%
100
==
0
:
# every 100 batches, update cost plot
plt
.
plot
(
*
train_costs
)
plt
.
plot
(
*
test_costs
)
plt
.
legend
([
'Train Cost'
,
'Test Cost'
],
loc
=
'upper left'
)
display
.
clear_output
(
wait
=
True
)
display
.
display
(
plt
.
gcf
())
plt
.
gcf
().
clear
()
cost_ploter
.
plot
()
step
+=
1
```
...
...
08.recommender_system/README.md
浏览文件 @
c2303f6d
...
...
@@ -349,42 +349,34 @@ def event_handler(event):
```
```
python
%
matplotlib
inline
from
paddle.v2.plot
import
Ploter
import
matplotlib.pyplot
as
plt
from
IPython
import
display
import
cPickle
train_title
=
"Train cost"
test_title
=
"Test cost"
cost_ploter
=
Ploter
(
train_title
,
test_title
)
step
=
0
train_costs
=
[],[]
test_costs
=
[],[]
step
=
0
def
event_handler_plot
(
event
):
global
step
global
train_costs
global
test_costs
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
need_plot
=
False
if
step
%
10
==
0
:
# every 10 batches, record a train cost
train_costs
[
0
].
append
(
step
)
train_costs
[
1
].
append
(
event
.
cost
)
cost_ploter
.
append
(
train_title
,
step
,
event
.
cost
)
if
step
%
1000
==
0
:
# every 1000 batches, record a test cost
result
=
trainer
.
test
(
reader
=
paddle
.
batch
(
paddle
.
dataset
.
movielens
.
test
(),
batch_size
=
256
))
test_costs
[
0
].
append
(
step
)
test_costs
[
1
].
append
(
result
.
cost
)
result
=
trainer
.
test
(
reader
=
paddle
.
batch
(
paddle
.
dataset
.
movielens
.
test
(),
batch_size
=
256
),
feeding
=
feeding
)
cost_ploter
.
append
(
test_title
,
step
,
result
.
cost
)
if
step
%
100
==
0
:
# every 100 batches, update cost plot
plt
.
plot
(
*
train_costs
)
plt
.
plot
(
*
test_costs
)
plt
.
legend
([
'Train Cost'
,
'Test Cost'
],
loc
=
'upper left'
)
display
.
clear_output
(
wait
=
True
)
display
.
display
(
plt
.
gcf
())
plt
.
gcf
().
clear
()
cost_ploter
.
plot
()
step
+=
1
```
```
python
trainer
.
train
(
reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
...
...
08.recommender_system/index.en.html
浏览文件 @
c2303f6d
...
...
@@ -213,12 +213,6 @@ After issuing a command `python train.py`, training will start immediately. The
First, we must import and initialize PaddlePaddle (enable/disable GPU, set the number of trainers, etc).
```python
%matplotlib inline
import matplotlib.pyplot as plt
from IPython import display
import cPickle
import paddle.v2 as paddle
paddle.init(use_gpu=False)
```
...
...
@@ -368,34 +362,30 @@ def event_handler(event):
```
```python
step=0
from paddle.v2.plot import Ploter
train_costs=[],[]
test_costs=[],[]
train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
def event_handler_plot(event):
global step
global train_costs
global test_costs
if isinstance(event, paddle.event.EndIteration):
need_plot = False
if step % 10 == 0: # every 10 batches, record a train cost
train_costs[0].append(step)
train_costs[1].append(event.cost)
cost_ploter.append(train_title, step, event.cost)
if step % 1000 == 0: # every 1000 batches, record a test cost
result = trainer.test(reader=paddle.batch(
paddle.dataset.movielens.test(), batch_size=256))
test_costs[0].append(step)
test_costs[1].append(result.cost)
result = trainer.test(
reader=paddle.batch(
paddle.dataset.movielens.test(), batch_size=256),
feeding=feeding)
cost_ploter.append(test_title, step, result.cost)
if step % 100 == 0: # every 100 batches, update cost plot
plt.plot(*train_costs)
plt.plot(*test_costs)
plt.legend(['Train Cost', 'Test Cost'], loc='upper left')
display.clear_output(wait=True)
display.display(plt.gcf())
plt.gcf().clear()
cost_ploter.plot()
step += 1
```
...
...
08.recommender_system/index.html
浏览文件 @
c2303f6d
...
...
@@ -391,42 +391,34 @@ def event_handler(event):
```
```python
%matplotlib inline
from paddle.v2.plot import Ploter
import matplotlib.pyplot as plt
from IPython import display
import cPickle
train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step=0
train_costs=[],[]
test_costs=[],[]
step = 0
def event_handler_plot(event):
global step
global train_costs
global test_costs
if isinstance(event, paddle.event.EndIteration):
need_plot = False
if step % 10 == 0: # every 10 batches, record a train cost
train_costs[0].append(step)
train_costs[1].append(event.cost)
cost_ploter.append(train_title, step, event.cost)
if step % 1000 == 0: # every 1000 batches, record a test cost
result = trainer.test(reader=paddle.batch(
paddle.dataset.movielens.test(), batch_size=256))
test_costs[0].append(step)
test_costs[1].append(result.cost)
result = trainer.test(
reader=paddle.batch(
paddle.dataset.movielens.test(), batch_size=256),
feeding=feeding)
cost_ploter.append(test_title, step, result.cost)
if step % 100 == 0: # every 100 batches, update cost plot
plt.plot(*train_costs)
plt.plot(*test_costs)
plt.legend(['Train Cost', 'Test Cost'], loc='upper left')
display.clear_output(wait=True)
display.display(plt.gcf())
plt.gcf().clear()
cost_ploter.plot()
step += 1
```
```python
trainer.train(
reader=paddle.batch(
paddle.reader.shuffle(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录