RNN – Explanation with Practically - Machine Learning Tutorials, Courses and Certifications

RNN – Explanation with Practically - Machine Learning Tutorials, Courses and Certifications

Machine Learning September 30, 2024 Deep Learning , Recurrent Neural Network Comments Off on RNN – Explanation with Practically 2,103 Views

Recurrent Neural Network(RNN) are a type of Neural Network where the output from previous step are fed as input to the current step. In traditional neural networks, all the inputs and outputs are independent of each other, but in cases like when it is required to predict the next word of a sentence, the previous words are required and hence there is a need to remember the previous words. Thus RNN came into existence, which solved this issue with the help of a Hidden Layer. The main and most important feature of RNN is Hidden state, which remembers some information about a sequence.

The working of a RNN can be understood with the help of below example:

Suppose there is a deeper network with one input layer, three hidden layers and one output layer. Then like other neural networks, each hidden layer will have its own set of weights and biases, let’s say, for hidden layer 1 the weights and biases are (w1, b1), (w2, b2) for second hidden layer and (w3, b3) for third hidden layer. This means that each of these layers are independent of each other, i.e. they do not memorize the previous outputs.

In this step, we import three Libraries in Data Preprocessing part. Basically, Library is a tool that you can ua specific job. First of all, we import the numpy library used for multidimensional array then import the pandas library used to import the dataset and in last we import matplotlib library used for plotting the graph.

In this step, we import the dataset with pandas library using read_csv() function. After importing the dataset, we take only one attribute of Google stock price prediction which is open Google stock price which we want to predict.

1258 rows × 6 columns

Feature Scaling is the most important part of data preprocessing. If we see our dataset then some attribute contains information in Numeric value some value very high and some are very low. This will cause some issues in our machine Learning model, To solve that problem we set all values on the same scale there are two methods to solve that problem first one is Normalize and Second is Standard Scaler . Here we use Normalize Scalar because in Google Stock Price Prediction we build the LSTM model which has several sigmoid functions as a activation function (which is 0 or 1) that is why we choose Normalize Scalar here.

In this step, we create our input and output from training data. Here X_train is our input which is t and Y_train is our output which is t+1.

In next step, we reshape our input. Why I Reshape here Because our input shape have 2 dimension one dimension corresponds to observation and second correspond to feature which has only one feature here and we convert our input into three-dimension last 1 corresponds to a timestamp because our input is t and output is t+1. So t+1-t= 1 that’s why 1 here. So here 1257 is observation, 1 is time step, 1 is feature scaling.

In this step, we import the Library which will build our RNN model. We import Keras Library which will build a deep neural network based on Tensorflow because we use Tensorflow backend. Here we import the three modules from Keras. The first one is Sequential used for initializing our RNN model and second is Dense used for adding different layers of RNN and third is LSTM which we use in the RNN model.

Recommended articles