Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
serviceRec
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
郭羽
serviceRec
Commits
e795d73a
Commit
e795d73a
authored
Dec 31, 2021
by
宋柯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
模型上线
parent
00a38405
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
featureEngSk.py
spark/featureEngSk.py
+13
-7
No files found.
spark/featureEngSk.py
View file @
e795d73a
...
@@ -51,6 +51,13 @@ def getRedisConn():
...
@@ -51,6 +51,13 @@ def getRedisConn():
# conn = redis.Redis(host="172.18.51.10", port=6379,db=0) #test
# conn = redis.Redis(host="172.18.51.10", port=6379,db=0) #test
return
conn
return
conn
def
getRedisConn1
():
pool
=
redis
.
ConnectionPool
(
host
=
"172.16.40.133"
,
password
=
"ReDis!GmTx*0aN6"
,
port
=
6379
,
db
=
0
)
conn
=
redis
.
Redis
(
connection_pool
=
pool
)
# conn = redis.Redis(host="172.16.50.145", port=6379, password="XfkMCCdWDIU%ls$h",db=0)
# conn = redis.Redis(host="172.18.51.10", port=6379,db=0) #test
return
conn
def
parseTags
(
tags
,
i
):
def
parseTags
(
tags
,
i
):
tags_arr
=
tags
.
split
(
","
)
tags_arr
=
tags
.
split
(
","
)
if
len
(
tags_arr
)
>=
i
:
if
len
(
tags_arr
)
>=
i
:
...
@@ -1038,7 +1045,7 @@ def get_and_save_card_feature(itemEsFeatureDF, predictClickStaticFeatures, predi
...
@@ -1038,7 +1045,7 @@ def get_and_save_card_feature(itemEsFeatureDF, predictClickStaticFeatures, predi
itemFeature
=
itemFeature
.
na
.
fill
(
fields_na_value_dict
)
itemFeature
=
itemFeature
.
na
.
fill
(
fields_na_value_dict
)
itemFeatureDF
=
itemFeature
.
toPandas
()
itemFeatureDF
=
itemFeature
.
toPandas
()
conn
=
getRedisConn
()
conn
=
getRedisConn
1
()
BATCH
=
5000
BATCH
=
5000
Key_TMP
=
'strategy:model:rank:widedeep:service:feature:tmp'
Key_TMP
=
'strategy:model:rank:widedeep:service:feature:tmp'
def
concat_service_feature
(
row
):
def
concat_service_feature
(
row
):
...
@@ -1103,7 +1110,7 @@ def get_and_save_device_feature(spark, fields_na_value_dict, days = 180):
...
@@ -1103,7 +1110,7 @@ def get_and_save_device_feature(spark, fields_na_value_dict, days = 180):
device_feature_df
=
device_feature_df
.
na
.
fill
({
'os'
:
'-1'
})
device_feature_df
=
device_feature_df
.
na
.
fill
({
'os'
:
'-1'
})
device_feature_df
.
printSchema
()
device_feature_df
.
printSchema
()
device_feature_df
=
device_feature_df
.
toPandas
()
device_feature_df
=
device_feature_df
.
toPandas
()
conn
=
getRedisConn
()
conn
=
getRedisConn
1
()
BATCH
=
5000
BATCH
=
5000
Key_TMP
=
'strategy:model:rank:widedeep:device:feature:tmp'
Key_TMP
=
'strategy:model:rank:widedeep:device:feature:tmp'
conn
.
delete
(
Key_TMP
)
conn
.
delete
(
Key_TMP
)
...
@@ -1180,10 +1187,6 @@ if __name__ == '__main__':
...
@@ -1180,10 +1187,6 @@ if __name__ == '__main__':
#计算 item 统计特征
#计算 item 统计特征
clickStaticFeatures
,
expStaticFeatures
=
getItemStaticFeatures
(
itemStatisticStartDays
+
trainDays
+
1
,
startDay
,
endDay
)
clickStaticFeatures
,
expStaticFeatures
=
getItemStaticFeatures
(
itemStatisticStartDays
+
trainDays
+
1
,
startDay
,
endDay
)
#计算线上推理 item 统计特征
predictClickStaticFeatures
,
predictExpStaticFeatures
=
getPredictItemStaticFeatures
(
itemStatisticStartDays
)
#user Profile Feature
#user Profile Feature
userProfileFeatureDF
=
getUserProfileFeature
(
spark
,
addDays
(
-
trainDays
-
1
,
format
=
"
%
Y-
%
m-
%
d"
),
addDays
(
-
1
,
format
=
"
%
Y-
%
m-
%
d"
))
userProfileFeatureDF
=
getUserProfileFeature
(
spark
,
addDays
(
-
trainDays
-
1
,
format
=
"
%
Y-
%
m-
%
d"
),
addDays
(
-
1
,
format
=
"
%
Y-
%
m-
%
d"
))
...
@@ -1341,7 +1344,10 @@ if __name__ == '__main__':
...
@@ -1341,7 +1344,10 @@ if __name__ == '__main__':
#存device_id -> USER_CATEGORY_os,
#存device_id -> USER_CATEGORY_os,
get_and_save_device_feature
(
spark
,
fields_na_value_dict
)
get_and_save_device_feature
(
spark
,
fields_na_value_dict
)
#存card_id -> ITEM*
#计算线上推理 item 统计特征
predictClickStaticFeatures
,
predictExpStaticFeatures
=
getPredictItemStaticFeatures
(
itemStatisticStartDays
)
# 存card_id -> ITEM*
get_and_save_card_feature
(
itemEsFeatureDF
,
predictClickStaticFeatures
,
predictExpStaticFeatures
,
fields_na_value_dict
)
get_and_save_card_feature
(
itemEsFeatureDF
,
predictClickStaticFeatures
,
predictExpStaticFeatures
,
fields_na_value_dict
)
print
(
"总耗时:{} mins"
.
format
((
time
.
time
()
-
start
)
/
60
))
print
(
"总耗时:{} mins"
.
format
((
time
.
time
()
-
start
)
/
60
))
...
...
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