Commit 00b54a0d authored by 张彦钊's avatar 张彦钊

add level2

parent 29fe0be8
......@@ -147,14 +147,15 @@ 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,df.level2_ids,e.device_id " \
"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 cid_time on e.cid_id = cid_time.cid_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 " \
"where e.stat_date >= '{}'".format(start)
df = con_sql(db, sql)
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:"time",11:"device_id"})
6:"device_type",7:"manufacturer",8:"channel",9:"top",10:"level2_ids",11:"device_id"})
print("esmm data ok")
# print(df.head(2)
......@@ -164,10 +165,10 @@ def get_data():
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","time"], axis=1).fillna("na")
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"]:
for i in ["ucity_id","clevel1_id","ccity_name","device_type","manufacturer","channel","level2_ids","top"]:
features = features + len(df[i].unique())
print("fields:{}".format(df.shape[1]-1))
print("features:{}".format(features))
......@@ -201,8 +202,8 @@ def transform(a,validate_date):
print("train shape")
print(train.shape)
# train.to_csv(path + "tr.csv", sep="\t", index=False)
# test.to_csv(path + "va.csv", sep="\t", index=False)
train.to_csv(path + "tr.csv", sep="\t", index=False)
test.to_csv(path + "va.csv", sep="\t", index=False)
return model
......@@ -210,13 +211,14 @@ def transform(a,validate_date):
def get_predict_set(ucity_id,model,ccity_name,manufacturer,channel):
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,cid_time.time,e.device_id,e.cid_id " \
"u.device_type,u.manufacturer,u.channel,c.top,df.level2_ids,e.device_id,e.cid_id " \
"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 cid_time on e.cid_id = cid_time.cid_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 " \
"where e.device_id = '358035085192742'"
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: "time",
6: "device_type", 7: "manufacturer", 8: "channel", 9: "top", 10: "level2_ids",
11:"device_id",12:"cid_id"})
print("before filter:")
......@@ -247,7 +249,7 @@ def get_predict_set(ucity_id,model,ccity_name,manufacturer,channel):
df["y"] = df["label"].str.cat(
[df["device_id"].values.tolist(), df["ucity_id"].values.tolist(), df["cid_id"].values.tolist(),
df["y"].values.tolist(), df["z"].values.tolist()], sep=",")
df = df.drop(["z","label","device_id","cid_id","time"], axis=1).fillna(0.0)
df = df.drop(["z","label","device_id","cid_id"], axis=1).fillna(0.0)
print("before transform")
print(df.shape)
temp_series = model.transform(df,n=160000, processes=22)
......@@ -273,8 +275,8 @@ def get_predict_set(ucity_id,model,ccity_name,manufacturer,channel):
print(native_pre.shape)
print(native_pre.loc[native_pre["device_id"] == "358035085192742"].shape)
native_pre.to_csv(path+"native.csv",sep="\t",index=False)
# print("native_pre shape")
# print(native_pre.shape)
print("native_pre shape")
print(native_pre.shape)
nearby_pre = df[df["label"] == "1"]
nearby_pre = nearby_pre.drop("label", axis=1)
......@@ -282,8 +284,8 @@ def get_predict_set(ucity_id,model,ccity_name,manufacturer,channel):
print(nearby_pre.shape)
print(nearby_pre.loc[nearby_pre["device_id"] == "358035085192742"].shape)
nearby_pre.to_csv(path + "nearby.csv", sep="\t", index=False)
# print("nearby_pre shape")
# print(nearby_pre.shape)
print("nearby_pre shape")
print(nearby_pre.shape)
......@@ -292,7 +294,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