def TrainEM(train_scores,train_vad_ts,train_features_ts): # prepare data for training [input_matrix,target_matrix] = PrepareData(train_vad_ts,train_features_ts) n_in = input_matrix.shape[2] n_out = target_matrix.shape[2] n_hidden = 10 not_converged = True while not_converged: model = MetaRNN(n_in=n_in, n_hidden=n_hidden, n_out=n_out,\ learning_rate=0.001, learning_rate_decay=0.999,\ n_epochs=400, activation='tanh') model.fit(input_matrix, target_matrix, validation_frequency=1000)
n_hidden = 5 # M n_in = 3 # D n_out = 1 # K n_steps = 1 # the length of each sequence n_seq = len(food_sel_scaled_train) # the number of datapoints (i.e. sequences) #Creating input and output arrays for training RNN rating = np.array(food_sel_scaled_train[['rating','price.tier','stats.checkinsCount']]).reshape(n_seq,n_steps,n_in) score = np.array(food_sel_scaled_train['SCORE']).reshape(n_seq,n_steps,n_out) #Creating the model and feeding it with training data set model = MetaRNN(n_in=n_in, n_hidden=n_hidden, n_out=n_out, learning_rate=0.001, learning_rate_decay=0.999, n_epochs=50, activation='tanh') model.fit(rating, score, validation_frequency=5000) guess = model.predict(rating.reshape(len(rating), n_in)) scores_pred = pd.DataFrame(guess) scores_pred.columns = ['predictions'] scores_pred.predictions.plot(kind='hist', bins=20, figsize=(6,4), grid=True, title = "Histogram of predicted DOH normalized Scores (IS)", alpha=0.8) food_sel_scaled_train.SCORE.plot(kind='hist', bins=20, figsize=(6,4), grid=True, title = "Histogram of actual DOH normalized Scores (IS)", alpha=0.8) #Creating parameters for training RNN n_hidden = 5 # M n_in = 3 # D n_out = 1 # K n_steps = 1 # the length of each sequence
#Creating input and output arrays for training RNN rating = np.array(food_sel_scaled_train[[ 'rating', 'price.tier', 'stats.checkinsCount' ]]).reshape(n_seq, n_steps, n_in) score = np.array(food_sel_scaled_train['SCORE']).reshape(n_seq, n_steps, n_out) #Creating the model and feeding it with training data set model = MetaRNN(n_in=n_in, n_hidden=n_hidden, n_out=n_out, learning_rate=0.001, learning_rate_decay=0.999, n_epochs=50, activation='tanh') model.fit(rating, score, validation_frequency=5000) guess = model.predict(rating.reshape(len(rating), n_in)) scores_pred = pd.DataFrame(guess) scores_pred.columns = ['predictions'] scores_pred.predictions.plot( kind='hist', bins=20, figsize=(6, 4), grid=True, title="Histogram of predicted DOH normalized Scores (IS)", alpha=0.8) food_sel_scaled_train.SCORE.plot(
opt = hf_optimizer(p=model.rnn.params, inputs=[model.x, model.y], s=model.rnn.y_pred, costs=[model.rnn.loss(model.y)], h=model.rnn.h) opt.train(gradient_dataset, cg_dataset, num_updates=300)''' model = MetaRNN(n_in=n_in, n_mul=n_hidden, n_out=n_out, learning_rate=0.001, learning_rate_decay=0.999, n_epochs=n_epochs, L1_reg=0.005, activation='tanh', output_type='real', index=index) model.fit(seqs, targets, validation_frequency=1000) print "traning over" path = '/root/chentian/share/201605/ped2' # os.makedirs(path) path0 = path + '/predict.csv' f3 = file(path0, "a") for k in range(0, 3000): guess = model.predict(test_seqs[k]) np.savetxt(f3, guess, delimiter=',') f3.close() error1 = np.zeros([1800, 1200]) pre_f = file(path0, "r") pre = np.loadtxt(pre_f, delimiter=',') pre_f.close()