Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl_ai_recommender
Overview
Overview
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
闫发泽
ydl_ai_recommender
Commits
321b7e4c
Commit
321b7e4c
authored
May 17, 2023
by
王金柱
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新xgboost模型
parent
aaa313b4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
20 deletions
+19
-20
recommender.py
src/core/recommender.py
+15
-17
recommend_service.py
src/service/recommend_service.py
+4
-3
No files found.
src/core/recommender.py
View file @
321b7e4c
...
...
@@ -270,24 +270,22 @@ class RecommendByXgboost(Recommender):
s_u_profile_time
=
time
.
time
()
user_profile
=
self
.
get_user_profile
(
user_id
)
logger
.
info
(
's_u_profile_time: {} '
.
format
(
time
.
time
()
-
s_u_profile_time
))
if
not
user_profile
:
return
self
.
_recommend_top
(
size
)
recall_start
=
time
.
time
()
# recommend_result = self.recommender.recommend(user_id, size=size, is_merge=True)
recommend_result
=
None
logger
.
info
(
'recall call time:{}
'
.
format
(
time
.
time
()
-
recall_start
))
logger
.
info
(
'recall call time:{}
ms'
.
format
(
int
((
time
.
time
()
-
recall_start
)
*
1000
)
))
data_time
=
time
.
time
()
predit_data
=
self
.
trans_feature_data
(
user_id
,
recommend_result
)
logger
.
info
(
'data_time: {}
'
.
format
(
time
.
time
()
-
data_time
))
logger
.
info
(
'data_time: {}
ms'
.
format
(
int
((
time
.
time
()
-
data_time
)
*
1000
)
))
doctor_ids
=
predit_data
.
pop
(
'doctor_id'
)
doctor_ids
=
doctor_ids
.
to_numpy
()
pre_time
=
time
.
time
()
predit_result
=
self
.
model
.
predict_proba
(
predit_data
)[:,
1
]
logger
.
info
(
'predit_time:{}
'
.
format
(
time
.
time
()
-
pre_time
))
logger
.
info
(
'predit_time:{}
ms'
.
format
(
int
((
time
.
time
()
-
pre_time
)
*
1000
)
))
result_dict
=
dict
(
zip
(
doctor_ids
,
predit_result
))
result_dict
=
sorted
(
result_dict
.
items
(),
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
recommend_data
=
[{
...
...
@@ -349,7 +347,7 @@ class RecommendByXgboost(Recommender):
try
:
get_profile_time
=
time
.
time
()
response
=
requests
.
request
(
'POST'
,
self
.
dmp_url
,
headers
=
headers
,
json
=
payload
)
self
.
logger
.
info
(
' get user profile cost {} ms'
.
format
((
time
.
time
()
-
get_profile_time
)
*
1000
))
logger
.
info
(
'get user profile cost: {}ms'
.
format
(
int
((
time
.
time
()
-
get_profile_time
)
*
1000
)
))
resp
=
response
.
json
()
return
resp
[
'data'
][
'objects'
][
0
]
except
Exception
as
e
:
...
...
@@ -391,20 +389,20 @@ class RecommendByXgboost(Recommender):
if
__name__
==
'__main__'
:
s_time
=
time
.
time
()
recommender1
=
UserCFRecommender
()
recommender1
.
recommend
(
'30004410'
)
print
(
'all cost time: {}'
.
format
(
time
.
time
()
-
s_time
),
recommender1
.
recommend
(
'12047'
))
#
s_time = time.time()
#
recommender1 = UserCFRecommender()
#
recommender1.recommend('30004410')
#
print('all cost time: {}'.format(time.time() - s_time), recommender1.recommend('12047'))
print
()
print
()
s_time
=
time
.
time
()
recommender
=
RecommendByXgboost
()
recommender
.
recommend
(
'
30004410
'
)
recommender
.
recommend
(
'
12047
'
)
print
(
'all cost time: '
.
format
(
time
.
time
()
-
s_time
),
recommender
.
recommend
(
'12047'
))
print
()
print
()
s_time
=
time
.
time
()
recommender
.
recommend
(
'30004410'
)
print
(
'all cost time: '
.
format
(
time
.
time
()
-
s_time
),
recommender
.
recommend
(
'12047'
))
\ No newline at end of file
# print()
# print()
# s_time = time.time()
# recommender.recommend('30004410')
# print('all cost time: '.format(time.time() - s_time), recommender.recommend('12047'))
\ No newline at end of file
src/service/recommend_service.py
View file @
321b7e4c
...
...
@@ -13,11 +13,12 @@ from tornado.concurrent import run_on_executor
from
ydl_ai_recommender.src.utils.log
import
create_logger
from
ydl_ai_recommender.src.core.recommender
import
UserCFRecommender
from
ydl_ai_recommender.src.core.recommender
import
RecommendByXgboost
logger
=
create_logger
(
__name__
,
'service.log'
,
is_rotating
=
True
)
recommender
=
UserCFRecommender
(
top_n
=
2
,
k
=
50
,
u2c
=
'order'
)
recommenderByXgb
=
RecommendByXgboost
()
class
RecommendHandler
(
tornado
.
web
.
RequestHandler
):
executor
=
ThreadPoolExecutor
(
1
)
...
...
@@ -112,7 +113,7 @@ class RecommendXgbHandler(tornado.web.RequestHandler):
logger
.
info
(
'request@@uid=
%
s@@size=
%
s'
,
uid
,
size
)
try
:
start_time
=
time
.
time
()
recommend_result
=
recommender
.
recommend
(
uid
,
size
=
size
,
is_merge
=
True
)
recommend_result
=
recommender
ByXgb
.
recommend
(
uid
,
size
=
size
,
is_merge
=
True
)
logger
.
info
(
'request@@uid=
%
s@@size=
%
s, cost
%
s ms'
,
uid
,
size
,
(
time
.
time
()
-
start_time
)
*
1000
)
ret
=
{
'status'
:
'success'
,
...
...
@@ -139,7 +140,7 @@ if __name__ == '__main__':
tornado
.
options
.
parse_command_line
()
app
=
tornado
.
web
.
Application
(
handlers
=
[(
r'/ai_counselor_recommend'
,
RecommendHandler
),
(
r'/ai_counselor_recommend/xgb/v1'
,
RecommendXgbHandler
)]
,
autoreload
=
Fals
e
,
debug
=
False
)
,
autoreload
=
Tru
e
,
debug
=
False
)
http_server
=
tornado
.
httpserver
.
HTTPServer
(
app
)
http_server
.
listen
(
tornado
.
options
.
options
.
port
)
tornado
.
ioloop
.
IOLoop
.
instance
()
.
start
()
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