Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
gm_strategy_cvr
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
gm_strategy_cvr
Commits
1f041d8e
Commit
1f041d8e
authored
Jul 24, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add prediction
parent
202e830c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
42 deletions
+46
-42
model.py
src/models/esmm/model.py
+46
-42
No files found.
src/models/esmm/model.py
View file @
1f041d8e
...
...
@@ -95,45 +95,49 @@ def _bytes_feature(value):
def
model_predict_diary
(
device_id
,
diary_ids
,
device_dict
,
diary_dict
,
predict_fn
):
time_1
=
timeit
.
default_timer
()
device_info
,
diary_lst
,
diary_ids_res
=
device_diary_fe
(
device_id
,
diary_ids
,
device_dict
,
diary_dict
)
print
(
"predict check: "
+
str
(
len
(
diary_lst
))
+
" "
+
str
(
len
(
diary_ids_res
)))
int_columns
=
[
"active_type"
,
"active_days"
,
"card_id"
,
"is_pure_author"
,
"is_have_reply"
,
"is_have_pure_reply"
,
"content_level"
,
"topic_num"
,
"favor_num"
,
"vote_num"
]
float_columns
=
[
"one_ctr"
,
"three_ctr"
,
"seven_ctr"
,
"fifteen_ctr"
]
str_columns
=
[
"device_id"
,
"past_consume_ability_history"
,
"potential_consume_ability_history"
,
"price_sensitive_history"
,
"device_fd"
,
"device_sd"
,
"device_fs"
,
"device_ss"
,
"device_fp"
,
"device_sp"
,
"device_p"
,
"content_fd"
,
"content_sd"
,
"content_fs"
,
"content_ss"
,
"content_fp"
,
"content_sp"
,
"content_p"
,
"fd1"
,
"fd2"
,
"fd3"
,
"sd1"
,
"sd2"
,
"sd3"
,
"fs1"
,
"fs2"
,
"fs3"
,
"ss1"
,
"ss2"
,
"ss3"
,
"fp1"
,
"fp2"
,
"fp3"
,
"sp1"
,
"sp2"
,
"sp3"
,
"p1"
,
"p2"
,
"p3"
]
examples
=
[]
for
diary_info
in
diary_lst
:
tmp
=
{}
tmp
.
update
(
device_info
)
tmp
.
update
(
diary_info
)
features
=
{}
for
col
in
int_columns
:
features
[
col
]
=
_int64_feature
(
int
(
tmp
[
col
]))
for
col
in
float_columns
:
features
[
col
]
=
_float_feature
(
float
(
tmp
[
col
]))
for
col
in
str_columns
:
features
[
col
]
=
_bytes_feature
(
str
(
tmp
[
col
])
.
encode
(
encoding
=
"utf-8"
))
example
=
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
features
))
examples
.
append
(
example
.
SerializeToString
())
total_1
=
(
timeit
.
default_timer
()
-
time_1
)
print
(
"make example cost {:.5f}s"
.
format
(
total_1
))
time_1
=
timeit
.
default_timer
()
predictions
=
predict_fn
({
"examples"
:
examples
})
res_tuple
=
sorted
(
zip
(
diary_ids_res
,
predictions
[
"output"
]
.
tolist
()),
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
res
=
[]
for
(
id
,
_
)
in
res_tuple
:
res
.
append
(
int
(
id
))
# print(res)
total_1
=
(
timeit
.
default_timer
()
-
time_1
)
print
(
"prediction cost {:.5f}s"
.
format
(
total_1
))
return
res
try
:
time_1
=
timeit
.
default_timer
()
device_info
,
diary_lst
,
diary_ids_res
=
device_diary_fe
(
device_id
,
diary_ids
,
device_dict
,
diary_dict
)
print
(
"predict check: "
+
str
(
len
(
diary_lst
))
+
" "
+
str
(
len
(
diary_ids_res
)))
int_columns
=
[
"active_type"
,
"active_days"
,
"card_id"
,
"is_pure_author"
,
"is_have_reply"
,
"is_have_pure_reply"
,
"content_level"
,
"topic_num"
,
"favor_num"
,
"vote_num"
]
float_columns
=
[
"one_ctr"
,
"three_ctr"
,
"seven_ctr"
,
"fifteen_ctr"
]
str_columns
=
[
"device_id"
,
"past_consume_ability_history"
,
"potential_consume_ability_history"
,
"price_sensitive_history"
,
"device_fd"
,
"device_sd"
,
"device_fs"
,
"device_ss"
,
"device_fp"
,
"device_sp"
,
"device_p"
,
"content_fd"
,
"content_sd"
,
"content_fs"
,
"content_ss"
,
"content_fp"
,
"content_sp"
,
"content_p"
,
"fd1"
,
"fd2"
,
"fd3"
,
"sd1"
,
"sd2"
,
"sd3"
,
"fs1"
,
"fs2"
,
"fs3"
,
"ss1"
,
"ss2"
,
"ss3"
,
"fp1"
,
"fp2"
,
"fp3"
,
"sp1"
,
"sp2"
,
"sp3"
,
"p1"
,
"p2"
,
"p3"
]
examples
=
[]
for
diary_info
in
diary_lst
:
tmp
=
{}
tmp
.
update
(
device_info
)
tmp
.
update
(
diary_info
)
features
=
{}
for
col
in
int_columns
:
features
[
col
]
=
_int64_feature
(
int
(
tmp
[
col
]))
for
col
in
float_columns
:
features
[
col
]
=
_float_feature
(
float
(
tmp
[
col
]))
for
col
in
str_columns
:
features
[
col
]
=
_bytes_feature
(
str
(
tmp
[
col
])
.
encode
(
encoding
=
"utf-8"
))
example
=
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
features
))
examples
.
append
(
example
.
SerializeToString
())
total_1
=
(
timeit
.
default_timer
()
-
time_1
)
print
(
"make example cost {:.5f}s"
.
format
(
total_1
))
time_1
=
timeit
.
default_timer
()
predictions
=
predict_fn
({
"examples"
:
examples
})
res_tuple
=
sorted
(
zip
(
diary_ids_res
,
predictions
[
"output"
]
.
tolist
()),
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
res
=
[]
for
(
id
,
_
)
in
res_tuple
:
res
.
append
(
int
(
id
))
# print(res)
total_1
=
(
timeit
.
default_timer
()
-
time_1
)
print
(
"prediction cost {:.5f}s"
.
format
(
total_1
))
return
res
except
Exception
as
e
:
print
(
e
)
return
[]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment