AI-challenger-stock Predict 代碼
模型2:Predict代碼 模型2解讀
返回 代碼解讀系列
"""n如何用keras預測ai-challenger-stock的數據及上傳結果n**Author**: `https://github.com/EmbraceLife/shendusuipian`n"""nnimport numpy as npnimport pandas as pdnfrom keras.models import load_modelnimport bcolznimport matplotlib.pyplot as pltnnn########################### 2-d 數據 ###########################################n# train_dev_test_features_group_norm_path = "/Users/Natsume/Documents/AI-challenger-stocks/prepared_dataset/features_group_norm/"n# train_feature_group_norm_array, dev_feature_group_norm_array, test_feature_group_norm_array = bcolz.open(train_dev_test_features_group_norm_path)n#n# train_dev_test_stad_group_norm_path = "/Users/Natsume/Documents/AI-challenger-stocks/prepared_dataset/features_stad_group_stad/"n# train_feature_stad_group_norm_array, dev_feature_stad_group_norm_array, test_feature_stad_group_norm_array = bcolz.open(train_dev_test_stad_group_norm_path)nntrain_dev_test_sequence_path = "/Users/Natsume/Documents/AI-challenger-stocks/prepared_dataset/train_dev_test_sequence.npz"nnnpzfiles = np.load(train_dev_test_sequence_path)ntrain_feature_stad_group_norm_array = npzfiles[train_sequence]ndev_feature_stad_group_norm_array = npzfiles[dev_sequence]ntest_feature_stad_group_norm_array = npzfiles[test_sequence]n#################################################################################nnn############################## 直接將 2-d 數據用於 sequence #######################n# test_feature_group_norm_array = test_feature_group_norm_array.reshape((-1, 1, 89))n# test_feature_stad_group_norm_array = test_feature_stad_group_norm_array.reshape((-1, 1, 89))n#################################################################################nnnn####################### for 3-d sequence dataset ################################n# 周期是5天nn# train_dev_test_sequence_path = "/Users/Natsume/Documents/AI-challenger-stocks/prepared_dataset/features_stad_group_stad/"n# train_feature_stad_group_norm_array, dev_feature_stad_group_norm_array, test_feature_stad_group_norm_array = bcolz.open(train_dev_test_sequence_path)n#n# train_dev_target_weight_sequence_path = "/Users/Natsume/Documents/AI-challenger-stocks/prepared_dataset/target_weight_norm/"n# train_target_array, dev_target_array, train_weight_array, dev_weight_array = bcolz.open(train_dev_target_weight_sequence_path)n##########################################################################################nnnn# load modeln# model_path="/Users/Natsume/Documents/AI-challenger-stocks/model_output/last.h5"nmodel_path="/Users/Natsume/Documents/AI-challenger-stocks/model_output/best.76-3.1335.hdf5"nmodel = load_model(model_path)nn# model predictn# pred = model.predict(test_feature_group_norm_array)npred = model.predict(test_feature_stad_group_norm_array) #nnn############################## prepare output for submission ##############################n# get test idntest_index = np.load("/Users/Natsume/Documents/AI-challenger-stocks/prepared_dataset/test_index.npy")nout = pd.concat([pd.DataFrame(test_index), pd.DataFrame(pred)], axis=1)nout.columns = [id, proba]nout_id_index = out.set_index(id)nout_id_index.to_csv("/Users/Natsume/Documents/AI-challenger-stocks/model_output/rnn_lstm.csv")nn# check prediction distributionnmean = out_id_index.describe().loc[mean,proba]nstd = out_id_index.describe().loc[std,proba]nplt.hist(out_id_index.values, bins=100)nplt.title("mean: "+str(mean)+", std: "+str(std))nplt.show()n
推薦閱讀:
TAG:Keras |