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
dbc3d28f
Commit
dbc3d28f
authored
3 years ago
by
郭羽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
service model 优化
parent
f370c36e
master
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
featureEng2.py
spark/featureEng2.py
+4
-4
No files found.
spark/featureEng2.py
View file @
dbc3d28f
...
...
@@ -78,8 +78,8 @@ def priceToBucket(num):
return
str
(
res
)
numberToBucketUdf
=
F
.
udf
(
numberToBucket
,
Float
Type
())
priceToBucketUdf
=
F
.
udf
(
priceToBucket
,
Float
Type
())
numberToBucketUdf
=
F
.
udf
(
numberToBucket
,
String
Type
())
priceToBucketUdf
=
F
.
udf
(
priceToBucket
,
String
Type
())
def
addStaticsFeatures
(
samples
,
dataVocab
):
print
(
"user统计特征处理..."
)
...
...
@@ -108,7 +108,7 @@ def addStaticsFeatures(samples,dataVocab):
bucket_suffix
=
"_Bucket"
for
col
in
[
"userRatingCount"
,
"userRatingAvg"
,
"userClickCount"
,
"userExpCount"
,
"itemRatingCount"
,
"itemRatingAvg"
,
"itemClickCount"
,
"itemExpCount"
]:
new_col
=
col
+
bucket_suffix
samples
=
samples
.
withColumn
(
new_col
,
numberToBucketUdf
(
F
.
col
(
col
))
.
cast
(
"int"
)
.
cast
(
"string"
)
)
\
samples
=
samples
.
withColumn
(
new_col
,
numberToBucketUdf
(
F
.
col
(
col
)))
\
.
drop
(
col
)
\
.
withColumn
(
new_col
,
F
.
when
(
F
.
col
(
new_col
)
.
isNull
(),
"0"
)
.
otherwise
(
F
.
col
(
new_col
)))
dataVocab
[
new_col
]
=
bucket_vocab
...
...
@@ -334,7 +334,7 @@ def itemFeaturesToRedis(samples,itemDF,columns,redisKey):
resDatas
.
show
(
10
,
truncate
=
False
)
resDatas
=
resDatas
.
select
(
*
columns
)
.
distinct
()
print
(
"item size:"
,
len
(
resDatas
))
print
(
"item size:"
,
resDatas
.
count
(
))
resDatas
.
repartition
(
8
)
.
foreachPartition
(
toRedis
)
"""
...
...
This diff is collapsed.
Click to expand it.
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