Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
ffm-baseline
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ML
ffm-baseline
Commits
505920d7
Commit
505920d7
authored
Aug 17, 2018
by
高雅喆
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.wanmeizhensuo.com:ML/ffm-baseline
add a py
parents
8f74d01a
91605d0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
11 deletions
+21
-11
predictDiary.py
predictDiary.py
+20
-10
processData.py
processData.py
+1
-1
No files found.
predictDiary.py
View file @
505920d7
...
...
@@ -23,8 +23,6 @@ def feature_en(user_profile):
# 虽然预测y,但ffm转化需要y,并不影响预测结果
data
[
"y"
]
=
0
data
=
data
.
drop
(
"city_id"
,
axis
=
1
)
print
(
data
.
head
(
1
))
print
(
"特征工程处理结束"
)
return
data
...
...
@@ -89,6 +87,19 @@ def router(device_id):
predict
(
user_profile
)
# 多进程预测
def
multi_predict
(
predict_list
,
processes
=
12
):
pool
=
Pool
(
processes
)
for
device_id
in
predict_list
:
start
=
time
.
time
()
pool
.
apply_async
(
router
,
(
device_id
,))
end
=
time
.
time
()
print
(
"该用户{}预测耗时{}秒"
.
format
(
device_id
,
(
end
-
start
)))
pool
.
close
()
pool
.
join
()
if
__name__
==
"__main__"
:
# TODO 如果耗时小于一分钟,下一次取到的device_id和上一次相同
while
True
:
...
...
@@ -100,14 +111,13 @@ if __name__ == "__main__":
time
.
sleep
(
58
)
else
:
old_device_id_list
=
pd
.
read_csv
(
DIRECTORY_PATH
+
"data_set_device_id.csv"
)[
"device_id"
]
.
values
.
tolist
()
for
device_id
in
device_id_list
:
if
device_id
in
old_device_id_list
:
start
=
time
.
time
()
router
(
device_id
)
end
=
time
.
time
()
print
(
"该用户预测耗时{}秒"
.
format
(
end
-
start
))
else
:
print
(
"该用户不是老用户,不能预测"
)
# 求活跃用户和老用户的交集,也就是只预测老用户
predict_list
=
list
(
set
(
device_id_list
)
&
set
(
old_device_id_list
))
multi_predict
(
predict_list
)
...
...
processData.py
View file @
505920d7
...
...
@@ -75,7 +75,7 @@ def ffm_transform(data, test_number, validation_number):
print
(
"Start ffm transform"
)
start
=
time
.
time
()
ffm_train
=
multiFFMFormatPandas
()
data
=
ffm_train
.
fit_transform
(
data
,
y
=
'y'
,
n
=
200000
,
processes
=
8
)
data
=
ffm_train
.
fit_transform
(
data
,
y
=
'y'
,
n
=
100000
,
processes
=
6
)
with
open
(
DIRECTORY_PATH
+
"ffm.pkl"
,
"wb"
)
as
f
:
pickle
.
dump
(
ffm_train
,
f
)
...
...
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