From 65bb5b387d315078c5d88d7cf47f38a13e841539 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Fri, 2 Apr 2021 18:40:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=AD=E7=BB=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.py | 12 ++++++------ predict_pay.py | 4 +++- train_pay.py | 6 ++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/data.py b/data.py index 71b4e89..fab802e 100644 --- a/data.py +++ b/data.py @@ -106,14 +106,14 @@ def load_pay_data(textNum = 80): lastday_v = collect_pay[0] for cur_v in collect_pay[1:]: - total_coin = 0 - users = 0 - last_total_coin = 0 + total_coin = 0.0 + users = 0.0 + last_total_coin = 0.0 for v2 in lastday_v: last_total_coin += v2[0] + v2[1] - count = 0 + count = 0.0 for v1, v2 in zip(cur_v,lastday_v): total_coin += v1[0] + v1[1] users += v1[2] @@ -125,10 +125,10 @@ def load_pay_data(textNum = 80): # print(compare) # 时刻. 前一个小时 时刻. 当前支付总币数. 当前支付总币数 昨天币数 - x_train.append([count ,total_coin / last_total_coin , total_coin]) + x_train.append([count, total_coin, last_total_coin ]) count+=1 - for i in range(count): + for i in range(int(count)): y_train.append(total_coin) lastday_v = cur_v diff --git a/predict_pay.py b/predict_pay.py index 0a82827..2dc9234 100644 --- a/predict_pay.py +++ b/predict_pay.py @@ -2,10 +2,12 @@ import numpy from keras.models import load_model from data import load_pay_data, load_gift_data +import matplotlib + import matplotlib.pyplot as plt -x_train, y_train, tx_train, ty_train, _ = load_pay_data(160) +x_train, y_train, tx_train, ty_train, _ = load_pay_data(320) model = load_model("./predict_pay") p_data = model.predict(tx_train) diff --git a/train_pay.py b/train_pay.py index 190fb59..5d06d9b 100644 --- a/train_pay.py +++ b/train_pay.py @@ -16,6 +16,8 @@ import numpy from data import load_pay_data def mean_squared_error(y_true, y_pred): + print(dir(y_true), y_true.consumers) + print(y_true, y_pred) return K.mean(K.square(y_pred - y_true), axis=-1) if __name__ == "__main__": @@ -31,9 +33,9 @@ if __name__ == "__main__": # model.add(Dropout(0.1)) model.add(Dense(1)) model.summary() - model.compile(loss = 'msle', optimizer = 'adam') + model.compile(loss = "mse", optimizer = 'adam') - model.fit(x_train, y_train, batch_size=96, epochs=600) + model.fit(x_train, y_train, batch_size=128, epochs=500) model.save("./predict_pay") p_data = model.predict(tx_train)