Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
64dda6c5
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看板
未验证
提交
64dda6c5
编写于
6月 06, 2018
作者:
N
Nicky Chan
提交者:
GitHub
6月 06, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #536 from nickyfantasy/update_recommendation_system
[High-Level-API]Compare predict and actual data result for chapter 5
上级
e20e6517
ac96a250
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
8 deletion
+18
-8
05.recommender_system/README.md
05.recommender_system/README.md
+9
-4
05.recommender_system/index.html
05.recommender_system/index.html
+9
-4
未找到文件。
05.recommender_system/README.md
浏览文件 @
64dda6c5
...
@@ -452,15 +452,18 @@ Use create_lod_tensor(data, lod, place) API to generate LoD Tensor, where `data`
...
@@ -452,15 +452,18 @@ Use create_lod_tensor(data, lod, place) API to generate LoD Tensor, where `data`
For example, data = [[10, 2, 3], [2, 3]] means that it contains two sequences of indices, of length 3 and 2, respectively.
For example, data = [[10, 2, 3], [2, 3]] means that it contains two sequences of indices, of length 3 and 2, respectively.
Correspondingly, lod = [[3, 2]] contains one level of detail info, indicating that
`data`
consists of two sequences of length 3 and 2.
Correspondingly, lod = [[3, 2]] contains one level of detail info, indicating that
`data`
consists of two sequences of length 3 and 2.
In this infer example, we try to predict rating of movie 'Hunchback of Notre Dame' from the info of user id 1.
```
python
```
python
infer_movie_id
=
783
infer_movie_name
=
paddle
.
dataset
.
movielens
.
movie_info
()[
infer_movie_id
].
title
user_id
=
fluid
.
create_lod_tensor
([[
1
]],
[[
1
]],
place
)
user_id
=
fluid
.
create_lod_tensor
([[
1
]],
[[
1
]],
place
)
gender_id
=
fluid
.
create_lod_tensor
([[
1
]],
[[
1
]],
place
)
gender_id
=
fluid
.
create_lod_tensor
([[
1
]],
[[
1
]],
place
)
age_id
=
fluid
.
create_lod_tensor
([[
0
]],
[[
1
]],
place
)
age_id
=
fluid
.
create_lod_tensor
([[
0
]],
[[
1
]],
place
)
job_id
=
fluid
.
create_lod_tensor
([[
10
]],
[[
1
]],
place
)
job_id
=
fluid
.
create_lod_tensor
([[
10
]],
[[
1
]],
place
)
movie_id
=
fluid
.
create_lod_tensor
([[
783
]],
[[
1
]],
place
)
movie_id
=
fluid
.
create_lod_tensor
([[
783
]],
[[
1
]],
place
)
# Hunchback of Notre Dame
category_id
=
fluid
.
create_lod_tensor
([[
10
,
8
,
9
]],
[[
3
]],
place
)
category_id
=
fluid
.
create_lod_tensor
([[
10
,
8
,
9
]],
[[
3
]],
place
)
# Animation, Children's, Musical
movie_title
=
fluid
.
create_lod_tensor
([[
1069
,
4140
,
2923
,
710
,
988
]],
[[
5
]],
movie_title
=
fluid
.
create_lod_tensor
([[
1069
,
4140
,
2923
,
710
,
988
]],
[[
5
]],
place
)
place
)
# 'hunchback','of','notre','dame','the'
```
```
### Infer
### Infer
...
@@ -480,7 +483,9 @@ results = inferencer.infer(
...
@@ -480,7 +483,9 @@ results = inferencer.infer(
},
},
return_numpy
=
False
)
return_numpy
=
False
)
print
(
"infer results: "
,
np
.
array
(
results
[
0
]))
predict_rating
=
np
.
array
(
results
[
0
])
print
(
"Predict Rating of user id 1 on movie
\"
"
+
infer_movie_name
+
"
\"
is "
+
str
(
predict_rating
[
0
][
0
]))
print
(
"Actual Rating of user id 1 on movie
\"
"
+
infer_movie_name
+
"
\"
is 4."
)
```
```
...
...
05.recommender_system/index.html
浏览文件 @
64dda6c5
...
@@ -494,15 +494,18 @@ Use create_lod_tensor(data, lod, place) API to generate LoD Tensor, where `data`
...
@@ -494,15 +494,18 @@ Use create_lod_tensor(data, lod, place) API to generate LoD Tensor, where `data`
For
example
,
data =
[[10,
2,
3],
[2,
3]]
means
that
it
contains
two
sequences
of
indices
,
of
length
3
and
2,
respectively.
For
example
,
data =
[[10,
2,
3],
[2,
3]]
means
that
it
contains
two
sequences
of
indices
,
of
length
3
and
2,
respectively.
Correspondingly
,
lod =
[[3,
2]]
contains
one
level
of
detail
info
,
indicating
that
`
data
`
consists
of
two
sequences
of
length
3
and
2.
Correspondingly
,
lod =
[[3,
2]]
contains
one
level
of
detail
info
,
indicating
that
`
data
`
consists
of
two
sequences
of
length
3
and
2.
In
this
infer
example
,
we
try
to
predict
rating
of
movie
'
Hunchback
of
Notre
Dame
'
from
the
info
of
user
id
1.
```
python
```
python
infer_movie_id =
783
infer_movie_name =
paddle.dataset.movielens.movie_info()[infer_movie_id].title
user_id =
fluid.create_lod_tensor([[1]],
[[1]],
place
)
user_id =
fluid.create_lod_tensor([[1]],
[[1]],
place
)
gender_id =
fluid.create_lod_tensor([[1]],
[[1]],
place
)
gender_id =
fluid.create_lod_tensor([[1]],
[[1]],
place
)
age_id =
fluid.create_lod_tensor([[0]],
[[1]],
place
)
age_id =
fluid.create_lod_tensor([[0]],
[[1]],
place
)
job_id =
fluid.create_lod_tensor([[10]],
[[1]],
place
)
job_id =
fluid.create_lod_tensor([[10]],
[[1]],
place
)
movie_id =
fluid.create_lod_tensor([[783]],
[[1]],
place
)
movie_id =
fluid.create_lod_tensor([[783]],
[[1]],
place
)
#
Hunchback
of
Notre
Dame
category_id =
fluid.create_lod_tensor([[10,
8,
9]],
[[3]],
place
)
category_id =
fluid.create_lod_tensor([[10,
8,
9]],
[[3]],
place
)
#
Animation
,
Children
'
s
,
Musical
movie_title =
fluid.create_lod_tensor([[1069,
4140,
2923,
710,
988]],
[[5]],
movie_title =
fluid.create_lod_tensor([[1069,
4140,
2923,
710,
988]],
[[5]],
place
)
place
)
#
'
hunchback
','
of
','
notre
','
dame
','
the
'
```
```
###
Infer
###
Infer
...
@@ -522,7 +525,9 @@ results = inferencer.infer(
...
@@ -522,7 +525,9 @@ results = inferencer.infer(
},
},
return_numpy=
False)
return_numpy=
False)
print
("
infer
results:
",
np.array
(
results
[0]))
predict_rating =
np.array(results[0])
print
("
Predict
Rating
of
user
id
1
on
movie
\""
+
infer_movie_name
+
"\"
is
"
+
str
(
predict_rating
[0][0]))
print
("
Actual
Rating
of
user
id
1
on
movie
\""
+
infer_movie_name
+
"\"
is
4.")
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录