コード例 #1
0
	plt.plot(list(range(num_train)), train_x, color='b', label='training data')
	plt.plot(list(range(num_train + len(valid), num_train + len(valid) + len(test))), test, color='y', label='predicted')
	plt.plot(list(range(num_train, num_train + len(valid))), valid, color='g', label='test data')
	plt.plot(list(range(num_train + len(valid), num_train + len(valid) + len(predictions))), predictions, color='r', label='predicted')
	plt.legend()
	#if filename is not None:
	#	plt.savefig(filename)
	#else:
	plt.show()


if __name__ == '__main__':
	seq_size = 20
	##Performing all the data operations	
	predictor = SeriesPredictor(input_dim = 1, seq_size = seq_size, hidden_dim = 100)
	data = data_loader.load_series('datanew.csv')
	train_data, valid_data, test_data = data_loader.split_data(data)

	'''
	print("How Train data looks like")
	for i in range(10):
		print(train_data[i])
	'''
	

	##Here we are making the data s.t the output at every time step is the value for the next time-step
	train_x, train_y = [], []
	for i in range(len(train_data) - seq_size - 1):
		##Expand_dims is used since we have to feed the network with an input that has first dimension as batch_size, second dimension as seq_length and third
		##dimension as input_dim
		##The first dimension is fulfilled by appending many lists to train_x, third dimension is fulfilled by using expand_dims		
コード例 #2
0
ファイル: rnn_ts.py プロジェクト: MrCat9/TensorFlow_Note
             label='predicted')
    plt.plot(list(range(num_train, num_train + len(actual))),
             actual,
             color='g',
             label='test data')
    plt.legend()  # 图例
    if filename is not None:
        plt.savefig(filename)
    else:
        plt.show()


if __name__ == '__main__':
    seq_size = 5
    predictor = SeriesPredictor(input_dim=1, seq_size=seq_size, hidden_dim=100)
    data = data_loader.load_series('international-airline-passengers.csv')
    train_data, actual_vals = data_loader.split_data(data)

    train_x, train_y = [], []
    # for i in range(len(train_data) - seq_size - 1):  # num - window_size + 1
    for i in range(len(train_data) - seq_size):
        train_x.append(
            np.expand_dims(
                train_data[i:i + seq_size],
                axis=1).tolist())  # shape=(batch, seq_size, input_dim)
        train_y.append(train_data[i + 1:i + seq_size + 1])

    test_x, test_y = [], []
    # for i in range(len(actual_vals) - seq_size - 1):
    for i in range(len(actual_vals) - seq_size):
        # temp = np.expand_dims(actual_vals[i:i + seq_size], axis=1)  # shape=(5, 1)
コード例 #3
0
    plt.figure()
    num_train = len(train_x)
    plt.plot(list(range(num_train)), train_x, color='b', label='training data')
    plt.plot(list(range(num_train, num_train + len(predictions))), predictions, color='r', label='predicted')
    plt.plot(list(range(num_train, num_train + len(actual))), actual, color='g', label='test data')
    plt.legend()
    if filename is not None:
        plt.savefig(filename)
    else:
        plt.show()


if __name__ == '__main__':
    seq_size = 5
    predictor = SeriesPredictor(input_dim=1, seq_size=seq_size, hidden_dim=5)
    data = data_loader.load_series('international-airline-passengers.csv')
    train_data, actual_vals = data_loader.split_data(data)

    train_x, train_y = [], []
    for i in range(len(train_data) - seq_size - 1):
        train_x.append(np.expand_dims(train_data[i:i+seq_size], axis=1).tolist())
        train_y.append(train_data[i+1:i+seq_size+1])

    test_x, test_y = [], []
    for i in range(len(actual_vals) - seq_size - 1):
        test_x.append(np.expand_dims(actual_vals[i:i+seq_size], axis=1).tolist())
        test_y.append(actual_vals[i+1:i+seq_size+1])

    predictor.train(train_x, train_y, test_x, test_y)

    with tf.Session() as sess:
コード例 #4
0
             color='r',
             label='predicted')
    plt.plot(list(range(num_train, num_train + len(actual))),
             actual,
             color='g',
             label='test data')
    plt.legend()
    plt.show()


if __name__ == '__main__':
    mode = 2  #0训练 1继续训练 2看结果

    seq_size = 60
    predictor = SeriesPredictor(input_dim=5, seq_size=seq_size, hidden_dim=50)
    data = data_loader.load_series('data_test.txt')
    train_data, actual_vals, sample = data_loader.split_data(data, seq_size)
    # print(train_data)
    # print(np.shape(train_data))
    train_x, train_y = [], []
    for i in range(len(train_data) - seq_size - 1):
        train_x.append(train_data[i:i + seq_size])
        train_y.append(train_data[i + seq_size + 1])
    # print(np.shape(train_x),np.shape(train_y))
    # print(train_y)
    # print(np.shape(train_y))
    test_x, test_y = [], []
    for i in range(len(actual_vals) - seq_size - 1):
        test_x.append(actual_vals[i:i + seq_size])
        test_y.append(actual_vals[i + seq_size + 1])
コード例 #5
0
    # Idk why its changing file_increment_num in gz_unzip, it shouldnt, and even though i put a placeholder it still does

    channel_converted_value, channel_last_timestamp = create_lists_ccv_clt(
        file_increment_num, 27)

    channel_last_datetime = unix_timestamp_to_datetime(channel_last_timestamp)
    """
    f = open('clt_ccv.csv', 'w')
    for x,y in zip(channel_last_timestamp,channel_converted_value):
        f.write(str(x) + "," + str(y) +'\n')
    f.close()
    """
    seq_size = 5
    predictor = SeriesPredictor(input_dim=1, seq_size=seq_size, hidden_dim=100)

    data = data_loader.load_series('2_ccv_clt.csv')
    train_data, actual_vals = data_loader.split_data(data)

    reconditioned_data = data_loader.recondition_data(data)
    train_data_reconditioned, actual_vals_reconditioned = data_loader.split_data(
        reconditioned_data)

    train_data, actual_vals = data_loader.split_data(data)
    train_x, train_y = [], []
    for i in range(len(train_data) - seq_size - 1):
        train_x.append(
            np.expand_dims(train_data[i:i + seq_size], axis=1).tolist())
        train_y.append(train_data[i + 1:i + seq_size + 1])

    test_x, test_y = [], []
    for i in range(len(actual_vals) - seq_size - 1):