<jupyter_start><jupyter_text>Adapted from https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/<jupyter_code>import numpy as np
import pandas as pd
import tensorflow as tf

from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense,Conv2D,MaxPool2D,Flatten,Dropout,LSTM
from tensorflow.keras.utils import plot_model

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import confusion_matrix,mean_squared_error
from sklearn.preprocessing import MinMaxScaler

from matplotlib import pyplot as plt
%matplotlib inline
np.random.seed(11)
# load the dataset
path = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv'
df = pd.read_csv(path, header=0, index_col=0, squeeze=True)
df.head()
# convert an array of values into a dataset matrix
def create_dataset(dataset, look_back=1):
	dataX, dataY = [], []
	for i in range(len(dataset)-look_back-1):
		a = dataset[i:(i+look_back), 0]
		dataX.append(a)
		dataY.append(dataset[i + look_back, 0])
	return np.array(dataX), np.array(dataY)
# retrieve the values
values = df.values.astype('float32')
values[0:20]
# normalize the dataset
scaler = MinMaxScaler(feature_range=(0, 1))
values = scaler.fit_transform(values.reshape(-1,1))
# split into train and test sets
train_size = int(len(values) * 0.6)
test_size = len(values) - train_size
train, test = values[0:train_size,:], values[train_size:len(values),:]
# reshape into X=t and Y=t+1
look_back = 1
x_train, y_train = create_dataset(train, look_back)
x_test, y_test = create_dataset(test, look_back)
# reshape input to be [samples, time steps, features]
x_train = np.reshape(x_train, (x_train.shape[0], 1, x_train.shape[1]))
x_test = np.reshape(x_test, (x_test.shape[0], 1, x_test.shape[1]))
# create and fit the LSTM network
model = Sequential()
model.add(LSTM(4, input_shape=(1, look_back)))
model.add(Dense(1))

model.compile(loss='mean_squared_error', optimizer='adam')
model.summary()
history = model.fit(x_train, y_train, epochs=100, batch_size=1, verbose=0)
# make predictions
y_pred = model.predict(x_test)
plt.plot(y_pred)
plt.plot(y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12310437109723461, 'fraction_numerical': 0.01694915254237288, 'mean_word_length': 6.788194444444445, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '9274', 'license': 'MIT', 'n_tokens_mistral': 831, 'n_tokens_neox': 799, 'n_words': 180, 'path': 'RNN/.ipynb_checkpoints/RNN_passengers_number_v2-checkpoint.ipynb', 'repo_name': 'danhtaihoang/classification-tensorflow', 'size': '2242'}