Commit 93f7a4b9 authored by 张彦钊's avatar 张彦钊

add test

parent 971a0d0e
......@@ -100,3 +100,6 @@ def sort_app():
if __name__ == "__main__":
sort_app()
......@@ -147,9 +147,13 @@ 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,cid_time.time,e.device_id " \
"u.device_type,u.manufacturer,u.channel,c.top,cid_time.time,e.device_id," \
"a.competitor,a.dianshang,a.kuajing_dianshang,a.zhibo,a.youxizhibo,a.short_video,a.meitu,a.tiyu," \
"a.read,a.finance,a.fashion_clothes,a.muying,a.fresh,a.bijia,a.travel,a.airplane," \
"a.love,a.stock,a.car,a.child,a.homework,a.work,a.job " \
"from esmm_train_data e left join user_feature_clean u on e.device_id = u.device_id " \
"left join cid_type_top c on e.device_id = c.device_id left join cid_time on e.cid_id = cid_time.cid_id " \
"left join app_list_sort a " \
"where e.stat_date >= '{}'".format(start)
df = con_sql(db, sql)
print(df.shape)
......@@ -158,24 +162,25 @@ def get_data():
print("esmm data ok")
print(df.head(2))
for i in range(12,36):
df[i] = df[i].astype("str")
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["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(0.0)
df = df.drop(["z","stat_date","device_id"], axis=1).fillna(0)
print(df.head(2))
features = 0
for i in ["ucity_id","clevel1_id","ccity_name","device_type","manufacturer","channel"]:
features = features + len(df[i].unique())
print("fields:{}".format(df.shape[1]-1))
print("features:{}".format(features))
print("features:{}".format(features+48))
ccity_name = list(set(df["ccity_name"].values.tolist()))
ucity_id = list(set(df["ucity_id"].values.tolist()))
manufacturer = list(set(df["manufacturer"].values.tolist()))
channel = list(set(df["channel"].values.tolist()))
return df,validate_date,ucity_id,ccity_name,manufacturer,channel
......@@ -291,7 +296,7 @@ if __name__ == "__main__":
a = time.time()
temp, validate_date, ucity_id,ccity_name,manufacturer,channel = get_data()
model = transform(temp, validate_date)
get_predict_set(ucity_id,model,ccity_name,manufacturer,channel)
# get_predict_set(ucity_id,model,ccity_name,manufacturer,channel)
b = time.time()
print("cost(分钟)")
print((b-a)/60)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment