diff --git a/7-TimeSeries/3-SVR/solution/notebook.ipynb b/7-TimeSeries/3-SVR/solution/notebook.ipynb index bbdd7e5e..e6f8150f 100644 --- a/7-TimeSeries/3-SVR/solution/notebook.ipynb +++ b/7-TimeSeries/3-SVR/solution/notebook.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 1, "metadata": { "id": "M687KNlQFp0-" }, @@ -30,20 +30,11 @@ "import numpy as np\n", "import pandas as pd\n", "import datetime as dt\n", + "import math\n", "\n", - "from common.utils import load_data, mape" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": { - "id": "FvR0MjVlLf_S" - }, - "outputs": [], - "source": [ + "from sklearn.svm import SVR\n", "from sklearn.preprocessing import MinMaxScaler\n", - "from sklearn.svm import SVR" + "from common.utils import load_data, mape" ] }, { @@ -66,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": 136, + "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -121,26 +112,6 @@ " 2012-01-01 04:00:00\n", " 2403.0\n", " \n", - " \n", - " 2012-01-01 05:00:00\n", - " 2453.0\n", - " \n", - " \n", - " 2012-01-01 06:00:00\n", - " 2560.0\n", - " \n", - " \n", - " 2012-01-01 07:00:00\n", - " 2719.0\n", - " \n", - " \n", - " 2012-01-01 08:00:00\n", - " 2916.0\n", - " \n", - " \n", - " 2012-01-01 09:00:00\n", - " 3105.0\n", - " \n", " \n", "\n", "" @@ -151,22 +122,17 @@ "2012-01-01 01:00:00 2558.0\n", "2012-01-01 02:00:00 2444.0\n", "2012-01-01 03:00:00 2402.0\n", - "2012-01-01 04:00:00 2403.0\n", - "2012-01-01 05:00:00 2453.0\n", - "2012-01-01 06:00:00 2560.0\n", - "2012-01-01 07:00:00 2719.0\n", - "2012-01-01 08:00:00 2916.0\n", - "2012-01-01 09:00:00 3105.0" + "2012-01-01 04:00:00 2403.0" ] }, - "execution_count": 136, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "energy = load_data('./data')[['load']]\n", - "energy.head(10)" + "energy.head(5)" ] }, { @@ -180,7 +146,7 @@ }, { "cell_type": "code", - "execution_count": 137, + "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -221,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 138, + "execution_count": 6, "metadata": { "id": "ysvsNyONGt0Q" }, @@ -233,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": 139, + "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -283,7 +249,7 @@ }, { "cell_type": "code", - "execution_count": 140, + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -318,7 +284,7 @@ }, { "cell_type": "code", - "execution_count": 141, + "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -386,7 +352,7 @@ "2014-11-01 04:00:00 0.059087" ] }, - "execution_count": 141, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -399,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": 142, + "execution_count": 10, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -467,7 +433,7 @@ "2014-12-30 04:00:00 0.302596" ] }, - "execution_count": 142, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -497,7 +463,7 @@ }, { "cell_type": "code", - "execution_count": 143, + "execution_count": 12, "metadata": { "id": "Rpju-Sc2HFm0" }, @@ -511,7 +477,7 @@ }, { "cell_type": "code", - "execution_count": 144, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -522,7 +488,7 @@ }, { "cell_type": "code", - "execution_count": 145, + "execution_count": 14, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -537,7 +503,7 @@ "(1412, 5)" ] }, - "execution_count": 145, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -551,7 +517,7 @@ }, { "cell_type": "code", - "execution_count": 146, + "execution_count": 16, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -566,7 +532,7 @@ "(44, 5)" ] }, - "execution_count": 146, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -580,7 +546,7 @@ }, { "cell_type": "code", - "execution_count": 147, + "execution_count": 17, "metadata": { "id": "2u0R2sIsLuq5" }, @@ -595,8 +561,6 @@ } ], "source": [ - "# Selecting inputs and outputs from training and testing data\n", - "\n", "x_train, y_train = train_data_timesteps[:,:timesteps-1],train_data_timesteps[:,[timesteps-1]]\n", "x_test, y_test = test_data_timesteps[:,:timesteps-1],test_data_timesteps[:,[timesteps-1]]\n", "\n", @@ -615,18 +579,20 @@ }, { "cell_type": "code", - "execution_count": 148, + "execution_count": 18, "metadata": { "id": "EhA403BEPEiD" }, "outputs": [], "source": [ + "# Create model using RBF kernel\n", + "\n", "model = SVR(kernel='rbf',gamma=0.5, C=10, epsilon = 0.05)" ] }, { "cell_type": "code", - "execution_count": 149, + "execution_count": 19, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -642,12 +608,14 @@ " kernel='rbf', max_iter=-1, shrinking=True, tol=0.001, verbose=False)" ] }, - "execution_count": 149, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "# Fit model on training data\n", + "\n", "model.fit(x_train, y_train[:,0])" ] }, @@ -662,7 +630,7 @@ }, { "cell_type": "code", - "execution_count": 150, + "execution_count": 20, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -681,6 +649,7 @@ ], "source": [ "# Making predictions\n", + "\n", "y_train_pred = model.predict(x_train).reshape(-1,1)\n", "y_test_pred = model.predict(x_test).reshape(-1,1)\n", "\n", @@ -698,7 +667,7 @@ }, { "cell_type": "code", - "execution_count": 151, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -710,8 +679,8 @@ } ], "source": [ - "\n", "# Scaling the predictions\n", + "\n", "y_train_pred = scaler.inverse_transform(y_train_pred)\n", "y_test_pred = scaler.inverse_transform(y_test_pred)\n", "\n", @@ -720,7 +689,7 @@ }, { "cell_type": "code", - "execution_count": 152, + "execution_count": 22, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -739,6 +708,7 @@ ], "source": [ "# Scaling the original values\n", + "\n", "y_train = scaler.inverse_transform(y_train)\n", "y_test = scaler.inverse_transform(y_test)\n", "\n", @@ -747,7 +717,7 @@ }, { "cell_type": "code", - "execution_count": 153, + "execution_count": 23, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -775,7 +745,7 @@ }, { "cell_type": "code", - "execution_count": 176, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -803,7 +773,7 @@ }, { "cell_type": "code", - "execution_count": 167, + "execution_count": 25, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -826,7 +796,7 @@ }, { "cell_type": "code", - "execution_count": 168, + "execution_count": 26, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -860,7 +830,7 @@ }, { "cell_type": "code", - "execution_count": 170, + "execution_count": 27, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -892,7 +862,7 @@ }, { "cell_type": "code", - "execution_count": 171, + "execution_count": 25, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -929,7 +899,7 @@ }, { "cell_type": "code", - "execution_count": 172, + "execution_count": 26, "metadata": { "id": "ESSAdQgwexIi" }, @@ -945,7 +915,7 @@ }, { "cell_type": "code", - "execution_count": 182, + "execution_count": 27, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -979,7 +949,7 @@ }, { "cell_type": "code", - "execution_count": 174, + "execution_count": 28, "metadata": { "colab": { "base_uri": "https://localhost:8080/"