diff --git a/models/BitcoinPricePrediction/Bitcoin Price Prediction LSTM-checkpoint.ipynb b/models/BitcoinPricePrediction/Bitcoin Price Prediction LSTM-checkpoint.ipynb new file mode 100644 index 00000000..864a471d --- /dev/null +++ b/models/BitcoinPricePrediction/Bitcoin Price Prediction LSTM-checkpoint.ipynb @@ -0,0 +1,816 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "5c848f3c", + "metadata": {}, + "source": [ + "# Implementation of LSTM on Bitcoin Dataset " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "02a26815", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from sklearn.preprocessing import MinMaxScaler\n", + "from keras.models import Sequential\n", + "from keras.layers import Dense, LSTM, Dropout\n", + "from sklearn.metrics import mean_squared_error, mean_absolute_error, median_absolute_error,r2_score\n", + "import warnings\n", + "import seaborn as sns\n", + "import tensorflow as tf" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "414d0275", + "metadata": {}, + "outputs": [], + "source": [ + "warnings.filterwarnings(\"ignore\")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "0ca0fe1f", + "metadata": {}, + "outputs": [], + "source": [ + "# Load the data\n", + "BTC = pd.read_csv(\"BTC-USD.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "485c0c74", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Index(['Date', 'Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume'], dtype='object')\n" + ] + } + ], + "source": [ + "print(BTC.columns)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "bb6dd29f", + "metadata": {}, + "outputs": [], + "source": [ + "# Convert the 'Date' column to datetime and set it as the index\n", + "BTC['Date'] = pd.to_datetime(BTC['Date'])\n", + "BTC.set_index('Date', inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "917dccb2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + " | Open | \n", + "High | \n", + "Low | \n", + "Close | \n", + "Adj Close | \n", + "Volume | \n", + "
---|---|---|---|---|---|---|
Date | \n", + "\n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " |
2014-09-17 | \n", + "465.864014 | \n", + "468.174011 | \n", + "452.421997 | \n", + "457.334015 | \n", + "457.334015 | \n", + "21056800 | \n", + "
2014-09-18 | \n", + "456.859985 | \n", + "456.859985 | \n", + "413.104004 | \n", + "424.440002 | \n", + "424.440002 | \n", + "34483200 | \n", + "
2014-09-19 | \n", + "424.102997 | \n", + "427.834991 | \n", + "384.532013 | \n", + "394.795990 | \n", + "394.795990 | \n", + "37919700 | \n", + "
2014-09-20 | \n", + "394.673004 | \n", + "423.295990 | \n", + "389.882996 | \n", + "408.903992 | \n", + "408.903992 | \n", + "36863600 | \n", + "
2014-09-21 | \n", + "408.084991 | \n", + "412.425995 | \n", + "393.181000 | \n", + "398.821014 | \n", + "398.821014 | \n", + "26580100 | \n", + "
\n", + " | Open | \n", + "High | \n", + "Low | \n", + "Close | \n", + "Adj Close | \n", + "Volume | \n", + "
---|---|---|---|---|---|---|
Date | \n", + "\n", + " | \n", + " | \n", + " | \n", + " | \n", + " | \n", + " |
2014-09-17 | \n", + "465.864014 | \n", + "468.174011 | \n", + "452.421997 | \n", + "457.334015 | \n", + "457.334015 | \n", + "21056800 | \n", + "
2014-09-18 | \n", + "456.859985 | \n", + "456.859985 | \n", + "413.104004 | \n", + "424.440002 | \n", + "424.440002 | \n", + "34483200 | \n", + "
2014-09-19 | \n", + "424.102997 | \n", + "427.834991 | \n", + "384.532013 | \n", + "394.795990 | \n", + "394.795990 | \n", + "37919700 | \n", + "
2014-09-20 | \n", + "394.673004 | \n", + "423.295990 | \n", + "389.882996 | \n", + "408.903992 | \n", + "408.903992 | \n", + "36863600 | \n", + "
2014-09-21 | \n", + "408.084991 | \n", + "412.425995 | \n", + "393.181000 | \n", + "398.821014 | \n", + "398.821014 | \n", + "26580100 | \n", + "
\n"," | name | \n","company | \n","year | \n","Price | \n","kms_driven | \n","fuel_type | \n","
---|---|---|---|---|---|---|
0 | \n","Hyundai Santro Xing XO eRLX Euro III | \n","Hyundai | \n","2007 | \n","80,000 | \n","45,000 kms | \n","Petrol | \n","
1 | \n","Mahindra Jeep CL550 MDI | \n","Mahindra | \n","2006 | \n","4,25,000 | \n","40 kms | \n","Diesel | \n","
2 | \n","Maruti Suzuki Alto 800 Vxi | \n","Maruti | \n","2018 | \n","Ask For Price | \n","22,000 kms | \n","Petrol | \n","
3 | \n","Hyundai Grand i10 Magna 1.2 Kappa VTVT | \n","Hyundai | \n","2014 | \n","3,25,000 | \n","28,000 kms | \n","Petrol | \n","
4 | \n","Ford EcoSport Titanium 1.5L TDCi | \n","Ford | \n","2014 | \n","5,75,000 | \n","36,000 kms | \n","Diesel | \n","
\n"," | name | \n","company | \n","year | \n","Price | \n","kms_driven | \n","fuel_type | \n","
---|---|---|---|---|---|---|
0 | \n","Hyundai Santro Xing | \n","Hyundai | \n","2007 | \n","80000 | \n","45000 | \n","Petrol | \n","
1 | \n","Mahindra Jeep CL550 | \n","Mahindra | \n","2006 | \n","425000 | \n","40 | \n","Diesel | \n","
2 | \n","Hyundai Grand i10 | \n","Hyundai | \n","2014 | \n","325000 | \n","28000 | \n","Petrol | \n","
3 | \n","Ford EcoSport Titanium | \n","Ford | \n","2014 | \n","575000 | \n","36000 | \n","Diesel | \n","
4 | \n","Ford Figo | \n","Ford | \n","2012 | \n","175000 | \n","41000 | \n","Diesel | \n","
... | \n","... | \n","... | \n","... | \n","... | \n","... | \n","... | \n","
811 | \n","Maruti Suzuki Ritz | \n","Maruti | \n","2011 | \n","270000 | \n","50000 | \n","Petrol | \n","
812 | \n","Tata Indica V2 | \n","Tata | \n","2009 | \n","110000 | \n","30000 | \n","Diesel | \n","
813 | \n","Toyota Corolla Altis | \n","Toyota | \n","2009 | \n","300000 | \n","132000 | \n","Petrol | \n","
814 | \n","Tata Zest XM | \n","Tata | \n","2018 | \n","260000 | \n","27000 | \n","Diesel | \n","
815 | \n","Mahindra Quanto C8 | \n","Mahindra | \n","2013 | \n","390000 | \n","40000 | \n","Diesel | \n","
816 rows × 6 columns
\n","\n"," | name | \n","company | \n","year | \n","Price | \n","kms_driven | \n","fuel_type | \n","
---|---|---|---|---|---|---|
count | \n","816 | \n","816 | \n","816.000000 | \n","8.160000e+02 | \n","816.000000 | \n","816 | \n","
unique | \n","254 | \n","25 | \n","NaN | \n","NaN | \n","NaN | \n","3 | \n","
top | \n","Maruti Suzuki Swift | \n","Maruti | \n","NaN | \n","NaN | \n","NaN | \n","Petrol | \n","
freq | \n","51 | \n","221 | \n","NaN | \n","NaN | \n","NaN | \n","428 | \n","
mean | \n","NaN | \n","NaN | \n","2012.444853 | \n","4.117176e+05 | \n","46275.531863 | \n","NaN | \n","
std | \n","NaN | \n","NaN | \n","4.002992 | \n","4.751844e+05 | \n","34297.428044 | \n","NaN | \n","
min | \n","NaN | \n","NaN | \n","1995.000000 | \n","3.000000e+04 | \n","0.000000 | \n","NaN | \n","
25% | \n","NaN | \n","NaN | \n","2010.000000 | \n","1.750000e+05 | \n","27000.000000 | \n","NaN | \n","
50% | \n","NaN | \n","NaN | \n","2013.000000 | \n","2.999990e+05 | \n","41000.000000 | \n","NaN | \n","
75% | \n","NaN | \n","NaN | \n","2015.000000 | \n","4.912500e+05 | \n","56818.500000 | \n","NaN | \n","
max | \n","NaN | \n","NaN | \n","2019.000000 | \n","8.500003e+06 | \n","400000.000000 | \n","NaN | \n","
\n"," | name | \n","company | \n","year | \n","kms_driven | \n","fuel_type | \n","
---|---|---|---|---|---|
0 | \n","Hyundai Santro Xing | \n","Hyundai | \n","2007 | \n","45000 | \n","Petrol | \n","
1 | \n","Mahindra Jeep CL550 | \n","Mahindra | \n","2006 | \n","40 | \n","Diesel | \n","
2 | \n","Hyundai Grand i10 | \n","Hyundai | \n","2014 | \n","28000 | \n","Petrol | \n","
3 | \n","Ford EcoSport Titanium | \n","Ford | \n","2014 | \n","36000 | \n","Diesel | \n","
4 | \n","Ford Figo | \n","Ford | \n","2012 | \n","41000 | \n","Diesel | \n","
... | \n","... | \n","... | \n","... | \n","... | \n","... | \n","
811 | \n","Maruti Suzuki Ritz | \n","Maruti | \n","2011 | \n","50000 | \n","Petrol | \n","
812 | \n","Tata Indica V2 | \n","Tata | \n","2009 | \n","30000 | \n","Diesel | \n","
813 | \n","Toyota Corolla Altis | \n","Toyota | \n","2009 | \n","132000 | \n","Petrol | \n","
814 | \n","Tata Zest XM | \n","Tata | \n","2018 | \n","27000 | \n","Diesel | \n","
815 | \n","Mahindra Quanto C8 | \n","Mahindra | \n","2013 | \n","40000 | \n","Diesel | \n","
816 rows × 5 columns
\n","OneHotEncoder()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
OneHotEncoder()
Pipeline(steps=[('columntransformer',\n"," ColumnTransformer(remainder='passthrough',\n"," transformers=[('onehotencoder',\n"," OneHotEncoder(categories=[array(['Audi A3 Cabriolet', 'Audi A4 1.8', 'Audi A4 2.0', 'Audi A6 2.0',\n"," 'Audi A8', 'Audi Q3 2.0', 'Audi Q5 2.0', 'Audi Q7', 'BMW 3 Series',\n"," 'BMW 5 Series', 'BMW 7 Series', 'BMW X1', 'BMW X1 sDrive20d',\n"," 'BMW X1 xDrive20d', 'Chevrolet Beat', 'Chevrolet Beat...\n"," array(['Audi', 'BMW', 'Chevrolet', 'Datsun', 'Fiat', 'Force', 'Ford',\n"," 'Hindustan', 'Honda', 'Hyundai', 'Jaguar', 'Jeep', 'Land',\n"," 'Mahindra', 'Maruti', 'Mercedes', 'Mini', 'Mitsubishi', 'Nissan',\n"," 'Renault', 'Skoda', 'Tata', 'Toyota', 'Volkswagen', 'Volvo'],\n"," dtype=object),\n"," array(['Diesel', 'LPG', 'Petrol'], dtype=object)]),\n"," ['name', 'company',\n"," 'fuel_type'])])),\n"," ('linearregression', LinearRegression())])In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Pipeline(steps=[('columntransformer',\n"," ColumnTransformer(remainder='passthrough',\n"," transformers=[('onehotencoder',\n"," OneHotEncoder(categories=[array(['Audi A3 Cabriolet', 'Audi A4 1.8', 'Audi A4 2.0', 'Audi A6 2.0',\n"," 'Audi A8', 'Audi Q3 2.0', 'Audi Q5 2.0', 'Audi Q7', 'BMW 3 Series',\n"," 'BMW 5 Series', 'BMW 7 Series', 'BMW X1', 'BMW X1 sDrive20d',\n"," 'BMW X1 xDrive20d', 'Chevrolet Beat', 'Chevrolet Beat...\n"," array(['Audi', 'BMW', 'Chevrolet', 'Datsun', 'Fiat', 'Force', 'Ford',\n"," 'Hindustan', 'Honda', 'Hyundai', 'Jaguar', 'Jeep', 'Land',\n"," 'Mahindra', 'Maruti', 'Mercedes', 'Mini', 'Mitsubishi', 'Nissan',\n"," 'Renault', 'Skoda', 'Tata', 'Toyota', 'Volkswagen', 'Volvo'],\n"," dtype=object),\n"," array(['Diesel', 'LPG', 'Petrol'], dtype=object)]),\n"," ['name', 'company',\n"," 'fuel_type'])])),\n"," ('linearregression', LinearRegression())])
ColumnTransformer(remainder='passthrough',\n"," transformers=[('onehotencoder',\n"," OneHotEncoder(categories=[array(['Audi A3 Cabriolet', 'Audi A4 1.8', 'Audi A4 2.0', 'Audi A6 2.0',\n"," 'Audi A8', 'Audi Q3 2.0', 'Audi Q5 2.0', 'Audi Q7', 'BMW 3 Series',\n"," 'BMW 5 Series', 'BMW 7 Series', 'BMW X1', 'BMW X1 sDrive20d',\n"," 'BMW X1 xDrive20d', 'Chevrolet Beat', 'Chevrolet Beat Diesel',\n"," 'Chevrolet Beat LS', 'Chevrolet B...\n"," 'Volkswagen Vento Konekt', 'Volvo S80 Summum'], dtype=object),\n"," array(['Audi', 'BMW', 'Chevrolet', 'Datsun', 'Fiat', 'Force', 'Ford',\n"," 'Hindustan', 'Honda', 'Hyundai', 'Jaguar', 'Jeep', 'Land',\n"," 'Mahindra', 'Maruti', 'Mercedes', 'Mini', 'Mitsubishi', 'Nissan',\n"," 'Renault', 'Skoda', 'Tata', 'Toyota', 'Volkswagen', 'Volvo'],\n"," dtype=object),\n"," array(['Diesel', 'LPG', 'Petrol'], dtype=object)]),\n"," ['name', 'company', 'fuel_type'])])
['name', 'company', 'fuel_type']
OneHotEncoder(categories=[array(['Audi A3 Cabriolet', 'Audi A4 1.8', 'Audi A4 2.0', 'Audi A6 2.0',\n"," 'Audi A8', 'Audi Q3 2.0', 'Audi Q5 2.0', 'Audi Q7', 'BMW 3 Series',\n"," 'BMW 5 Series', 'BMW 7 Series', 'BMW X1', 'BMW X1 sDrive20d',\n"," 'BMW X1 xDrive20d', 'Chevrolet Beat', 'Chevrolet Beat Diesel',\n"," 'Chevrolet Beat LS', 'Chevrolet Beat LT', 'Chevrolet Beat PS',\n"," 'Chevrolet Cruze LTZ', 'Chevrolet Enjoy', 'Chevrolet E...\n"," 'Volkswagen Vento Comfortline', 'Volkswagen Vento Highline',\n"," 'Volkswagen Vento Konekt', 'Volvo S80 Summum'], dtype=object),\n"," array(['Audi', 'BMW', 'Chevrolet', 'Datsun', 'Fiat', 'Force', 'Ford',\n"," 'Hindustan', 'Honda', 'Hyundai', 'Jaguar', 'Jeep', 'Land',\n"," 'Mahindra', 'Maruti', 'Mercedes', 'Mini', 'Mitsubishi', 'Nissan',\n"," 'Renault', 'Skoda', 'Tata', 'Toyota', 'Volkswagen', 'Volvo'],\n"," dtype=object),\n"," array(['Diesel', 'LPG', 'Petrol'], dtype=object)])
['year', 'kms_driven']
passthrough
LinearRegression()