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
f665c607
Commit
f665c607
authored
Jan 14, 2019
by
张彦钊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add cut time
parent
454179e8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
8 deletions
+16
-8
data2ffm.py
eda/esmm/Feature_pipline/data2ffm.py
+16
-8
No files found.
eda/esmm/Feature_pipline/data2ffm.py
View file @
f665c607
...
...
@@ -149,38 +149,44 @@ def get_data():
print
(
start
)
db
=
pymysql
.
connect
(
host
=
'10.66.157.22'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
sql
=
"select e.y,e.z,e.stat_date,e.ucity_id,e.clevel1_id,e.ccity_name,"
\
"u.device_type,u.manufacturer,u.channel,c.top,df.level2_ids,e.device_id "
\
"u.device_type,u.manufacturer,u.channel,c.top,df.level2_ids,e.device_id
,cut.time
"
\
"from esmm_train_data e left join user_feature u on e.device_id = u.device_id "
\
"left join cid_type_top c on e.device_id = c.device_id "
\
"left join diary_feat df on e.cid_id = df.diary_id "
\
"left join cid_time_cut cut on e.cid_id = cut.cid "
\
"where e.stat_date >= '{}'"
.
format
(
start
)
df
=
con_sql
(
db
,
sql
)
print
(
df
.
shape
)
#
print(df.shape)
df
=
df
.
rename
(
columns
=
{
0
:
"y"
,
1
:
"z"
,
2
:
"stat_date"
,
3
:
"ucity_id"
,
4
:
"clevel1_id"
,
5
:
"ccity_name"
,
6
:
"device_type"
,
7
:
"manufacturer"
,
8
:
"channel"
,
9
:
"top"
,
10
:
"level2_ids"
,
11
:
"device_id"
})
6
:
"device_type"
,
7
:
"manufacturer"
,
8
:
"channel"
,
9
:
"top"
,
10
:
"level2_ids"
,
11
:
"device_id"
,
12
:
"time"
})
print
(
"esmm data ok"
)
# print(df.head(2)
print
(
"before"
)
print
(
df
.
shape
)
print
(
"after"
)
df
=
df
.
drop_duplicates
()
df
=
df
.
drop_duplicates
([
"ucity_id"
,
"clevel1_id"
,
"ccity_name"
,
"device_type"
,
"manufacturer"
,
"channel"
,
"top"
,
"level2_ids"
,
"time"
])
print
(
df
.
shape
)
df
[
"clevel1_id"
]
=
df
[
"clevel1_id"
]
.
astype
(
"str"
)
df
[
"y"
]
=
df
[
"y"
]
.
astype
(
"str"
)
df
[
"z"
]
=
df
[
"z"
]
.
astype
(
"str"
)
df
[
"top"
]
=
df
[
"top"
]
.
astype
(
"str"
)
df
[
"time"
]
=
df
[
"time"
]
.
astype
(
"str"
)
df
[
"y"
]
=
df
[
"stat_date"
]
.
str
.
cat
([
df
[
"device_id"
]
.
values
.
tolist
(),
df
[
"y"
]
.
values
.
tolist
(),
df
[
"z"
]
.
values
.
tolist
()],
sep
=
","
)
df
=
df
.
drop
([
"z"
,
"stat_date"
,
"device_id"
],
axis
=
1
)
.
fillna
(
"na"
)
print
(
df
.
head
(
2
))
features
=
0
for
i
in
[
"ucity_id"
,
"clevel1_id"
,
"ccity_name"
,
"device_type"
,
"manufacturer"
,
"channel"
,
"level2_ids"
,
"top"
]:
l
=
[
"ucity_id"
,
"clevel1_id"
,
"ccity_name"
,
"device_type"
,
"manufacturer"
,
"channel"
,
"level2_ids"
,
"top"
,
"time"
]
for
i
in
l
:
features
=
features
+
len
(
df
[
i
]
.
unique
())
print
(
"fields:{}"
.
format
(
df
.
shape
[
1
]
-
1
))
print
(
"features:{}"
.
format
(
features
))
# filter_list 中没有device_type,这个类别只有安卓、ios两种类型,转化前能完全覆盖到这两种类型
filter_list
=
[
"ccity_name"
,
"ucity_id"
,
"manufacturer"
,
"channel"
,
"level2_ids"
,
"clevel1_id"
,
"top"
]
filter_list
=
[
"ccity_name"
,
"ucity_id"
,
"manufacturer"
,
"channel"
,
"level2_ids"
,
"clevel1_id"
,
"top"
,
"time"
]
column_map
=
dict
()
for
i
in
filter_list
:
column_map
[
i
]
=
list
(
set
(
df
[
i
]
.
values
.
tolist
()))
...
...
@@ -219,14 +225,15 @@ def transform(a,validate_date):
def
get_predict_set
(
model
,
columns
):
db
=
pymysql
.
connect
(
host
=
'10.66.157.22'
,
port
=
4000
,
user
=
'root'
,
passwd
=
'3SYz54LS9#^9sBvC'
,
db
=
'jerry_test'
)
sql
=
"select e.y,e.z,e.label,e.ucity_id,e.clevel1_id,e.ccity_name,"
\
"u.device_type,u.manufacturer,u.channel,c.top,df.level2_ids,e.device_id,e.cid_id "
\
"u.device_type,u.manufacturer,u.channel,c.top,df.level2_ids,e.device_id,e.cid_id
,cut.time
"
\
"from esmm_pre_data e left join user_feature u on e.device_id = u.device_id "
\
"left join cid_type_top c on e.device_id = c.device_id "
\
"left join diary_feat df on e.cid_id = df.diary_id"
"left join diary_feat df on e.cid_id = df.diary_id "
\
"left join cid_time_cut cut on e.cid_id = cut.cid"
df
=
con_sql
(
db
,
sql
)
df
=
df
.
rename
(
columns
=
{
0
:
"y"
,
1
:
"z"
,
2
:
"label"
,
3
:
"ucity_id"
,
4
:
"clevel1_id"
,
5
:
"ccity_name"
,
6
:
"device_type"
,
7
:
"manufacturer"
,
8
:
"channel"
,
9
:
"top"
,
10
:
"level2_ids"
,
11
:
"device_id"
,
12
:
"cid_id"
})
11
:
"device_id"
,
12
:
"cid_id"
,
13
:
"time"
})
print
(
df
.
shape
)
for
i
in
columns
.
keys
():
...
...
@@ -234,6 +241,7 @@ def get_predict_set(model,columns):
df
[
"cid_id"
]
=
df
[
"cid_id"
]
.
astype
(
"str"
)
df
[
"clevel1_id"
]
=
df
[
"clevel1_id"
]
.
astype
(
"str"
)
df
[
"top"
]
=
df
[
"top"
]
.
astype
(
"str"
)
df
[
"time"
]
=
df
[
"time"
]
.
astype
(
"str"
)
df
[
"y"
]
=
df
[
"y"
]
.
astype
(
"str"
)
df
[
"z"
]
=
df
[
"z"
]
.
astype
(
"str"
)
df
[
"label"
]
=
df
[
"label"
]
.
astype
(
"str"
)
...
...
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