{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Time-series prediction with Keras `SimpleRNN` class\n", "### Dr. Tirthajyoti Sarkar, Fremont, CA 94536 ([LinkedIn](https://www.linkedin.com/in/tirthajyoti-sarkar-2127aa7/), [Github](https://tirthajyoti.github.io))\n", "\n", "For more tutorial-style notebooks on deep learning, **[here is my Github repo](https://github.com/tirthajyoti/Deep-learning-with-Python)**.\n", "\n", "For more tutorial-style notebooks on general machine learning, **[here is my Github repo](https://github.com/tirthajyoti/Machine-Learning-with-Python)**.\n", "\n", "---\n", "### What is this Notebook about?\n", "In this notebook, we show a building simple recurrent neural network (RNN) using Keras.\n", "\n", "We will generate some synthetic time-series data by multiplying two periodic/ sinusoidal signals and adding some stochasticity (Gaussian noise). Then, we will take a small fraction of the data and train a simple RNN model with it and try to predict the rest of the data and see how the predictions match up with the ground truth." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WARNING:tensorflow:From f:\\KTU\\Neuroninių tinklų metodai\\venv\\Lib\\site-packages\\keras\\src\\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.\n", "\n" ] } ], "source": [ "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "from keras.models import Sequential\n", "from keras.layers import Dense, SimpleRNN\n", "from keras.optimizers import RMSprop\n", "from keras.callbacks import Callback" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Data | \n", "
---|---|
0 | \n", "-0.561333 | \n", "
1 | \n", "0.203835 | \n", "
2 | \n", "-0.207246 | \n", "
3 | \n", "-0.486425 | \n", "
4 | \n", "0.239823 | \n", "