Skip to content

Commit 753c2c4

Browse files
committed
TimeSeriesW1W2!
1 parent 860eb8d commit 753c2c4

16 files changed

+5
-0
lines changed

Time_SeriesW1/General_W1_Lesson.ipynb

+1
Large diffs are not rendered by default.

Time_SeriesW1/Q1W1.png

43.9 KB
Loading

Time_SeriesW1/Q2W1.png

40.2 KB
Loading

Time_SeriesW1/Q3W1.png

35.3 KB
Loading

Time_SeriesW1/Q4W1.png

35.5 KB
Loading

Time_SeriesW1/Q5W1.png

36.3 KB
Loading

Time_SeriesW1/Time_SeriesW1_Answer.ipynb

+1
Large diffs are not rendered by default.

Time_SeriesW2/Deep_NN_TimeSeries.ipynb

+1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Features_Labels_TimeSeries.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"accelerator":"GPU"},"cells":[{"cell_type":"code","metadata":{"id":"xwtLW_CkV73A","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":593},"outputId":"fe1ac551-7945-4d2f-a3a6-dfa22954d103","executionInfo":{"status":"ok","timestamp":1574498480001,"user_tz":-540,"elapsed":34034,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["!pip3 install tensorflow==2.0.0-rc1\n"],"execution_count":1,"outputs":[{"output_type":"stream","text":["Collecting tensorflow==2.0.0-rc1\n","\u001b[?25l Downloading https://files.pythonhosted.org/packages/40/d0/7359227ccfb6e2ae2a8fe345db1d513f010282022a7a6a899530cc63c41f/tensorflow-2.0.0rc1-cp36-cp36m-manylinux2010_x86_64.whl (86.3MB)\n","\u001b[K |████████████████████████████████| 86.3MB 122kB/s \n","\u001b[?25hRequirement already satisfied: google-pasta>=0.1.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (0.1.8)\n","Requirement already satisfied: keras-preprocessing>=1.0.5 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (1.1.0)\n","Requirement already satisfied: keras-applications>=1.0.8 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (1.0.8)\n","Requirement already satisfied: astor>=0.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (0.8.0)\n","Requirement already satisfied: absl-py>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (0.8.1)\n","Requirement already satisfied: wrapt>=1.11.1 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (1.11.2)\n","Collecting tb-nightly<1.15.0a20190807,>=1.15.0a20190806\n","\u001b[?25l Downloading https://files.pythonhosted.org/packages/bc/88/24b5fb7280e74c7cf65bde47c171547fd02afb3840cff41bcbe9270650f5/tb_nightly-1.15.0a20190806-py3-none-any.whl (4.3MB)\n","\u001b[K |████████████████████████████████| 4.3MB 42.5MB/s \n","\u001b[?25hRequirement already satisfied: numpy<2.0,>=1.16.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (1.17.4)\n","Requirement already satisfied: wheel>=0.26 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (0.33.6)\n","Collecting tf-estimator-nightly<1.14.0.dev2019080602,>=1.14.0.dev2019080601\n","\u001b[?25l Downloading https://files.pythonhosted.org/packages/21/28/f2a27a62943d5f041e4a6fd404b2d21cb7c59b2242a4e73b03d9ba166552/tf_estimator_nightly-1.14.0.dev2019080601-py2.py3-none-any.whl (501kB)\n","\u001b[K |████████████████████████████████| 501kB 51.0MB/s \n","\u001b[?25hRequirement already satisfied: grpcio>=1.8.6 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (1.15.0)\n","Requirement already satisfied: opt-einsum>=2.3.2 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (3.1.0)\n","Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (1.1.0)\n","Requirement already satisfied: gast>=0.2.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (0.2.2)\n","Requirement already satisfied: protobuf>=3.6.1 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (3.10.0)\n","Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.0.0-rc1) (1.12.0)\n","Requirement already satisfied: h5py in /usr/local/lib/python3.6/dist-packages (from keras-applications>=1.0.8->tensorflow==2.0.0-rc1) (2.8.0)\n","Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.6/dist-packages (from tb-nightly<1.15.0a20190807,>=1.15.0a20190806->tensorflow==2.0.0-rc1) (0.16.0)\n","Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.6/dist-packages (from tb-nightly<1.15.0a20190807,>=1.15.0a20190806->tensorflow==2.0.0-rc1) (3.1.1)\n","Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.6/dist-packages (from tb-nightly<1.15.0a20190807,>=1.15.0a20190806->tensorflow==2.0.0-rc1) (41.6.0)\n","Installing collected packages: tb-nightly, tf-estimator-nightly, tensorflow\n"," Found existing installation: tensorflow 1.15.0\n"," Uninstalling tensorflow-1.15.0:\n"," Successfully uninstalled tensorflow-1.15.0\n","Successfully installed tb-nightly-1.15.0a20190806 tensorflow-2.0.0rc1 tf-estimator-nightly-1.14.0.dev2019080601\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"0pvmMWXaavcS","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"outputId":"6ba9b491-2c7b-41e2-e80c-ee1a4fc4a217","executionInfo":{"status":"ok","timestamp":1574498482438,"user_tz":-540,"elapsed":2425,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["import tensorflow as tf\n","print (\"check tensorflow version: \", tf.__version__)"],"execution_count":2,"outputs":[{"output_type":"stream","text":["check tensorflow version: 2.0.0-rc1\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"TFhkNTYbbCbO","colab_type":"text"},"source":["This notebook is a basic tutorial for setting features and labels for time series analysis. Feature is effectively a number of values in the series,\n","with label being the next value. We'll call that number of values that will treat as our feature, the window size, where we're taking a window of the data and training an ML model to predict the next value. So for example, if we take our time series data, say, 30 days at a time, we'll use 30 values as the feature and the next value is the label. Then over time, we'll train a neural network to match the 30 features to the single label. "]},{"cell_type":"code","metadata":{"id":"bU7k6Me3dUwB","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":260},"outputId":"48e3becf-de80-41e8-fe31-3526ddc91ae1","executionInfo":{"status":"ok","timestamp":1574499124239,"user_tz":-540,"elapsed":901,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["dataset = tf.data.Dataset.range(14)\n","for val in dataset:\n"," print(val.numpy()) # because tensroflow 2 supports eager execution, so no need to start session"],"execution_count":3,"outputs":[{"output_type":"stream","text":["0\n","1\n","2\n","3\n","4\n","5\n","6\n","7\n","8\n","9\n","10\n","11\n","12\n","13\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"DUdFWVeHdf_j","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":139},"outputId":"154619bb-f37b-488e-f778-77ee78876261","executionInfo":{"status":"ok","timestamp":1574499220829,"user_tz":-540,"elapsed":613,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["dataset = tf.data.Dataset.range(14)\n","dataset = dataset.window(5, shift=2) # now select a window of 5, where our idea is that last value will be label, first 4 being the features.\n","for window_dataset in dataset:\n"," for val in window_dataset:\n"," print(val.numpy(), end=\" \")\n"," print()"],"execution_count":5,"outputs":[{"output_type":"stream","text":["0 1 2 3 4 \n","2 3 4 5 6 \n","4 5 6 7 8 \n","6 7 8 9 10 \n","8 9 10 11 12 \n","10 11 12 13 \n","12 13 \n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"j2lW6_Rdd06r","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":191},"outputId":"08093906-3e15-4517-e3c1-58b5888dac66","executionInfo":{"status":"ok","timestamp":1574499278219,"user_tz":-540,"elapsed":540,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["dataset = tf.data.Dataset.range(14)\n","dataset = dataset.window(5, shift=1, drop_remainder=True) # choose only the entries that contain 5 elements\n","for window_dataset in dataset:\n"," for val in window_dataset:\n"," print(val.numpy(), end=\" \")\n"," print()"],"execution_count":6,"outputs":[{"output_type":"stream","text":["0 1 2 3 4 \n","1 2 3 4 5 \n","2 3 4 5 6 \n","3 4 5 6 7 \n","4 5 6 7 8 \n","5 6 7 8 9 \n","6 7 8 9 10 \n","7 8 9 10 11 \n","8 9 10 11 12 \n","9 10 11 12 13 \n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"5h1s_77leFrR","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":191},"outputId":"b14a0a90-0dfb-4935-e8f8-4acd268335be","executionInfo":{"status":"ok","timestamp":1574500177597,"user_tz":-540,"elapsed":915,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["dataset = tf.data.Dataset.range(14)\n","dataset = dataset.window(5, shift=1, drop_remainder=True)\n","dataset = dataset.flat_map(lambda window: window.batch(5))\n","for window in dataset:\n"," print(window.numpy())"],"execution_count":7,"outputs":[{"output_type":"stream","text":["[0 1 2 3 4]\n","[1 2 3 4 5]\n","[2 3 4 5 6]\n","[3 4 5 6 7]\n","[4 5 6 7 8]\n","[5 6 7 8 9]\n","[ 6 7 8 9 10]\n","[ 7 8 9 10 11]\n","[ 8 9 10 11 12]\n","[ 9 10 11 12 13]\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"H-FEX_6qhhJ9","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":121},"outputId":"06aa2c49-6cc9-410b-e8e9-f51916c95c3f","executionInfo":{"status":"ok","timestamp":1574500417046,"user_tz":-540,"elapsed":1029,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["dataset = tf.data.Dataset.range(10)\n","dataset = dataset.window(5, shift=1, drop_remainder=True)\n","dataset = dataset.flat_map(lambda window: window.batch(5))\n","dataset = dataset.map(lambda window: (window[:-1], window[-1:]))# last but all the elements are features \n","for x,y in dataset:\n"," print(x.numpy(), y.numpy())"],"execution_count":8,"outputs":[{"output_type":"stream","text":["[0 1 2 3] [4]\n","[1 2 3 4] [5]\n","[2 3 4 5] [6]\n","[3 4 5 6] [7]\n","[4 5 6 7] [8]\n","[5 6 7 8] [9]\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"OVyjVEO-ibZL","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":191},"outputId":"e19300a4-cf40-4f74-e02b-0d0b023a1cab","executionInfo":{"status":"ok","timestamp":1574500711295,"user_tz":-540,"elapsed":967,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["dataset = tf.data.Dataset.range(14)\n","dataset = dataset.window(5, shift=1, drop_remainder=True)\n","dataset = dataset.flat_map(lambda window: window.batch(5))\n","dataset = dataset.map(lambda window: (window[:-1], window[-1:]))\n","dataset = dataset.shuffle(buffer_size=14) # shuffle the data-set, buffer size = dataset size\n","for x,y in dataset:\n"," print(x.numpy(), y.numpy())"],"execution_count":10,"outputs":[{"output_type":"stream","text":["[2 3 4 5] [6]\n","[ 8 9 10 11] [12]\n","[0 1 2 3] [4]\n","[6 7 8 9] [10]\n","[ 9 10 11 12] [13]\n","[1 2 3 4] [5]\n","[5 6 7 8] [9]\n","[ 7 8 9 10] [11]\n","[3 4 5 6] [7]\n","[4 5 6 7] [8]\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"hxLBBALQi1GC","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":364},"outputId":"d046594f-870e-4013-9591-929e3800ffc4","executionInfo":{"status":"ok","timestamp":1574500796944,"user_tz":-540,"elapsed":960,"user":{"displayName":"Swap vi","photoUrl":"","userId":"01936573407644251994"}}},"source":["dataset = tf.data.Dataset.range(14)\n","dataset = dataset.window(5, shift=1, drop_remainder=True)\n","dataset = dataset.flat_map(lambda window: window.batch(5))\n","dataset = dataset.map(lambda window: (window[:-1], window[-1:]))\n","dataset = dataset.shuffle(buffer_size=14)\n","dataset = dataset.batch(3).prefetch(1) # a batch of 3 inputs \n","for x,y in dataset:\n"," print(\"x = \", x.numpy())\n"," print(\"y = \", y.numpy())"],"execution_count":12,"outputs":[{"output_type":"stream","text":["x = [[3 4 5 6]\n"," [6 7 8 9]\n"," [4 5 6 7]]\n","y = [[ 7]\n"," [10]\n"," [ 8]]\n","x = [[ 2 3 4 5]\n"," [ 9 10 11 12]\n"," [ 8 9 10 11]]\n","y = [[ 6]\n"," [13]\n"," [12]]\n","x = [[ 7 8 9 10]\n"," [ 1 2 3 4]\n"," [ 5 6 7 8]]\n","y = [[11]\n"," [ 5]\n"," [ 9]]\n","x = [[0 1 2 3]]\n","y = [[4]]\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"kX6h9o8hjvO7","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]}

Time_SeriesW2/Q1W2.png

46.8 KB
Loading

Time_SeriesW2/Q2W2.png

48.6 KB
Loading

Time_SeriesW2/Q3W2.png

36.4 KB
Loading

Time_SeriesW2/Q4W2.png

39.3 KB
Loading

Time_SeriesW2/Q5W2.png

41.1 KB
Loading

Time_SeriesW2/Q6W2.png

33.5 KB
Loading

Time_SeriesW2/Single_Layer_Network_TimeSeries.ipynb

+1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)