CryptoCurrencyPredictionLSTM/3+Crypto_Price_Prediction.ipynb
harivansh-afk 57a0ae1739
Base files
2024-11-01 16:13:38 -04:00

2285 lines
71 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "PLZl5KnqIGQ8"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import sklearn\n",
"import matplotlib.pyplot as plt\n",
"import sys \n",
"import seaborn as sns\n",
"\n",
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"\n",
"%matplotlib inline\n",
"import plotly.graph_objs as go\n",
"#import plotly.plotly as py\n",
"import datetime as dt\n",
"import matplotlib.dates as mdates"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "RN88EZ6yJYDd"
},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'tensorflow.python'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mc:\\Users\\rathi\\OneDrive\\Documents\\-\\Coding\\PYTHON\\CRYPTO PREDICTION\\3+Crypto_Price_Prediction.ipynb Cell 3\u001b[0m in \u001b[0;36m1\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/rathi/OneDrive/Documents/-/Coding/PYTHON/CRYPTO%20PREDICTION/3%2BCrypto_Price_Prediction.ipynb#W2sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mkeras\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m \u001b[39mimport\u001b[39;00m Sequential\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/rathi/OneDrive/Documents/-/Coding/PYTHON/CRYPTO%20PREDICTION/3%2BCrypto_Price_Prediction.ipynb#W2sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mkeras\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mlayers\u001b[39;00m \u001b[39mimport\u001b[39;00m Dense, LSTM, Dropout, GRU\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/rathi/OneDrive/Documents/-/Coding/PYTHON/CRYPTO%20PREDICTION/3%2BCrypto_Price_Prediction.ipynb#W2sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mkeras\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mlayers\u001b[39;00m \u001b[39mimport\u001b[39;00m \u001b[39m*\u001b[39m\n",
"File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\keras\\__init__.py:20\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39m# Copyright 2015 The TensorFlow Authors. All Rights Reserved.\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[39m#\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[39m# Licensed under the Apache License, Version 2.0 (the \"License\");\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[39m# limitations under the License.\u001b[39;00m\n\u001b[0;32m 14\u001b[0m \u001b[39m# ==============================================================================\u001b[39;00m\n\u001b[0;32m 15\u001b[0m \u001b[39m\"\"\"Implementation of the Keras API, the high-level API of TensorFlow.\u001b[39;00m\n\u001b[0;32m 16\u001b[0m \n\u001b[0;32m 17\u001b[0m \u001b[39mDetailed documentation and user guides are available at\u001b[39;00m\n\u001b[0;32m 18\u001b[0m \u001b[39m[keras.io](https://keras.io).\u001b[39;00m\n\u001b[0;32m 19\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m---> 20\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mkeras\u001b[39;00m \u001b[39mimport\u001b[39;00m distribute\n\u001b[0;32m 21\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mkeras\u001b[39;00m \u001b[39mimport\u001b[39;00m models\n\u001b[0;32m 22\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mkeras\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mengine\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39minput_layer\u001b[39;00m \u001b[39mimport\u001b[39;00m Input\n",
"File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\keras\\distribute\\__init__.py:18\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39m# Copyright 2019 The TensorFlow Authors. All Rights Reserved.\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[39m#\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[39m# Licensed under the Apache License, Version 2.0 (the \"License\");\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[39m# limitations under the License.\u001b[39;00m\n\u001b[0;32m 14\u001b[0m \u001b[39m# ==============================================================================\u001b[39;00m\n\u001b[0;32m 15\u001b[0m \u001b[39m\"\"\"Keras' Distribution Strategy library.\"\"\"\u001b[39;00m\n\u001b[1;32m---> 18\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mkeras\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mdistribute\u001b[39;00m \u001b[39mimport\u001b[39;00m sidecar_evaluator\n",
"File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\keras\\distribute\\sidecar_evaluator.py:17\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39m# Copyright 2020 The TensorFlow Authors. All Rights Reserved.\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[39m#\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[39m# Licensed under the Apache License, Version 2.0 (the \"License\");\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[39m# limitations under the License.\u001b[39;00m\n\u001b[0;32m 14\u001b[0m \u001b[39m# ==============================================================================\u001b[39;00m\n\u001b[0;32m 15\u001b[0m \u001b[39m\"\"\"Python module for evaluation loop.\"\"\"\u001b[39;00m\n\u001b[1;32m---> 17\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mtensorflow\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mcompat\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mv2\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mtf\u001b[39;00m\n\u001b[0;32m 19\u001b[0m \u001b[39m# isort: off\u001b[39;00m\n\u001b[0;32m 20\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtensorflow\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mpython\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mplatform\u001b[39;00m \u001b[39mimport\u001b[39;00m tf_logging \u001b[39mas\u001b[39;00m logging\n",
"File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\tensorflow\\__init__.py:37\u001b[0m\n\u001b[0;32m 34\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39msys\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39m_sys\u001b[39;00m\n\u001b[0;32m 35\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mtyping\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39m_typing\u001b[39;00m\n\u001b[1;32m---> 37\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtensorflow\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mpython\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mtools\u001b[39;00m \u001b[39mimport\u001b[39;00m module_util \u001b[39mas\u001b[39;00m _module_util\n\u001b[0;32m 38\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtensorflow\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mpython\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mutil\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mlazy_loader\u001b[39;00m \u001b[39mimport\u001b[39;00m LazyLoader \u001b[39mas\u001b[39;00m _LazyLoader\n\u001b[0;32m 40\u001b[0m \u001b[39m# Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.\u001b[39;00m\n",
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'tensorflow.python'"
]
}
],
"source": [
"from keras.models import Sequential\n",
"from keras.layers import Dense, LSTM, Dropout, GRU\n",
"from keras.layers import *\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"from sklearn.metrics import mean_squared_error, mean_absolute_error\n",
"from sklearn.model_selection import train_test_split\n",
"from keras.callbacks import EarlyStopping\n",
"from tensorflow.keras.optimizers import Adam, SGD"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"background_save": true,
"base_uri": "https://localhost:8080/",
"height": 38,
"resources": {
"http://localhost:8080/nbextensions/google.colab/files.js": {
"data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlIExMQwovLwovLyBMaWNlbnNlZCB1bmRlciB0aGUgQXBhY2hlIExpY2Vuc2UsIFZlcnNpb24gMi4wICh0aGUgIkxpY2Vuc2UiKTsKLy8geW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLgovLyBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXQKLy8KLy8gICAgICBodHRwOi8vd3d3LmFwYWNoZS5vcmcvb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Y29wZS5nb29nbGUuY29sYWIgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYi5fZmlsZXMgPSB7CiAgX3VwbG9hZEZpbGVzLAogIF91cGxvYWRGaWxlc0NvbnRpbnVlLAp9Owp9KShzZWxmKTsK",
"headers": [
[
"content-type",
"application/javascript"
]
],
"ok": true,
"status": 200,
"status_text": ""
}
}
},
"id": "sOGCxI5MIHJ8",
"outputId": "2a391b7b-7b06-4c09-daaa-dfe79a178c84"
},
"outputs": [],
"source": [
"# from google.colab import files\n",
"# uploaded = files.upload()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "PLXtatQdIKkr"
},
"outputs": [],
"source": [
"# import io\n",
"# df = pd.read_csv(io.StringIO(uploaded['crypto-markets.csv'].decode('utf-8')))\n",
"\n",
"df = pd.read_csv(\"crypto-markets.csv\")\n",
"\n",
"data_copy = df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "vFFnVybLILE8",
"outputId": "5bf743d9-a5cb-4184-dd52-0a346bde79f2"
},
"outputs": [],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "TDuDU-SlIW8s",
"outputId": "b5dab737-bce6-4822-c2b5-053c6bc68a26"
},
"outputs": [],
"source": [
"df.shape #total number of rows and columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "rSQy0La6Iaez",
"outputId": "efe86655-27e4-4773-a87a-523435d68318"
},
"outputs": [],
"source": [
"df.isnull().sum() #total of null values column wise "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
},
"id": "HzaCeYB_Ia_j",
"outputId": "90fe7dea-0df1-48e2-eb85-e2417ff927d9"
},
"outputs": [],
"source": [
"df.describe() #statistical readings of all the columns "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "t2R1q-FAIejT",
"outputId": "aebb2a25-de90-4d15-cfe2-011325915a20"
},
"outputs": [],
"source": [
"df.info() #info on all the columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xdF9qRVBM82y"
},
"outputs": [],
"source": [
"data = df #copy of dataframe\n",
"\n",
"#set up a column with an index so I can only sample 1/10th of the dataset \n",
"data[\"row_id\"]= range(1, len(data) + 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "kEwAdAFzNGfa",
"outputId": "47586bab-8683-4edf-8f21-475aed383a5a"
},
"outputs": [],
"source": [
"#drop columns I'm not using\n",
"data_=data.drop(['slug','ranknow','volume','market'], axis=1)\n",
"data_.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 238
},
"id": "txJAiKwmNNg7",
"outputId": "6c2070a1-7b4d-4155-f209-0eda8ff7bc41"
},
"outputs": [],
"source": [
"data_.set_index('row_id', inplace=True)\n",
"data_.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Bynw95JgNUx6",
"outputId": "5e4c28c2-3a39-4a64-8106-c00c1d643c9b"
},
"outputs": [],
"source": [
"#counitng unique symbols \n",
"data[\"name\"].unique() #total number of unique cryptos "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xjq9b8pRNR9C"
},
"outputs": [],
"source": [
"#set date to timestamp format\n",
"data_['date'] = pd.to_datetime(data_['date']).dt.date "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "OVpiyV4PS4wY"
},
"outputs": [],
"source": [
"#pick out the currency for two years span (2016>)\n",
"\n",
"date = data_[data_['date'] >= dt.date(2016, 1, 1)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Vvz_kNbgS5dQ"
},
"outputs": [],
"source": [
"#show if each one closed up or down each day\n",
"date['pos_neg']= date['open']-date['close']\n",
"date.head()\n",
"#create a binary column - 0 = gain, 1 = loss to have something to predict\n",
"date['Up/Down'] = np.where(date['pos_neg']>0, '0', '1')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "uZLR2R9WQyzR"
},
"outputs": [],
"source": [
"#create data sets for different crypto currencies\n",
"etherdate = date[date['symbol']=='ETH']\n",
"ltcdate = date[date['symbol']=='LTC']\n",
"tetherdate = date[date['symbol']=='USDT']\n",
"cardanodate = date[date['symbol']=='ADA']\n",
"rippledate = date[date['symbol']=='XRP']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "TQKkNj3wUM6B"
},
"outputs": [],
"source": [
"#concat the different frames into one\n",
"frames=[etherdate,ltcdate,tetherdate,cardanodate,rippledate]\n",
"five_crypto = pd.concat(frames)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Zjb4kqCzVXwY",
"outputId": "66568d7f-6656-4101-913c-11e21f22e7e6"
},
"outputs": [],
"source": [
"five_crypto.info()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 296
},
"id": "TXNuyzFoVevf",
"outputId": "3c7295fd-0ec6-4a3f-e09b-e81d5cc7adf8"
},
"outputs": [],
"source": [
"#this chart shows each of the six and the number of times they closed up for the day. \n",
"sns.set_style('whitegrid')\n",
"sns.countplot(x='symbol',hue='Up/Down',data=five_crypto,palette='rainbow')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 454
},
"id": "b-KaRiCFVlF3",
"outputId": "426f31e8-b3b3-44e6-ea05-641d58318b45"
},
"outputs": [],
"source": [
"#a comparison the the up/down ratio at the end of the day for the six.\n",
"sns.set(style=\"whitegrid\")\n",
"\n",
"g = sns.factorplot(\"symbol\", \"close_ratio\", \"Up/Down\",\n",
" data=five_crypto, kind=\"bar\",\n",
" size=6, palette=\"muted\",\n",
" legend_out=True)\n",
"g.despine(left=True)\n",
"g.set_ylabels(\"Ratio Count\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "S3ZOHw0xW5RK"
},
"outputs": [],
"source": [
"data['market_billion'] = data['market'] / 1000000000\n",
"data['volume_million'] = data['volume'] / 1000000000\n",
"data['volume_billion'] = data['volume']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 338
},
"id": "s86ZmNTCWvdf",
"outputId": "e1b87670-2d40-4b8e-d1c9-378782b9f330"
},
"outputs": [],
"source": [
"# Let's prepare one dataframe where we will observe closing prices for each currency\n",
"wide_format = data.groupby(['date', 'name'])['close'].last().unstack()\n",
"wide_format.head(3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 301
},
"id": "fKfl6z3bWxMP",
"outputId": "010fb6ee-6ac0-4fa5-a6b8-0ff102902d0a"
},
"outputs": [],
"source": [
"ax = data.groupby(['name'])['market_billion'].last().sort_values(ascending=False).head(10).sort_values().plot(kind='barh');\n",
"ax.set_xlabel(\"Market cap (in billion USD)\");\n",
"plt.title(\"Top 10 Currencies by Market Cap\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 301
},
"id": "4MJQipOJXAlD",
"outputId": "0b8c53b6-4253-47e0-8c2f-d9f92a8ac7c1"
},
"outputs": [],
"source": [
"ax = data.groupby(['name'])['volume_million'].last().sort_values(ascending=False).head(10).sort_values().plot(kind='barh');\n",
"ax.set_xlabel(\"Transaction Volume (in million)\");\n",
"plt.title(\"Top 10 Currencies by Transaction Volume\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "qfrzkuc2XbeX",
"outputId": "a182edbc-70a2-4d4d-9f72-3727d9c538fc"
},
"outputs": [],
"source": [
"# For sake of convenience, let's define the top 6 currencies\n",
"\n",
"top_6_currency_names = data.groupby(['name'])['market'].last().sort_values(ascending=False).head(6).index\n",
"data_top_6_currencies = data[data['name'].isin(top_6_currency_names)]\n",
"data_top_6_currencies.head(5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 301
},
"id": "X2vurY0xXmff",
"outputId": "f08949e0-ec1b-4167-8875-99474ff74d57"
},
"outputs": [],
"source": [
"ax = data_top_6_currencies.groupby(['date', 'name'])['close'].mean().unstack().plot();\n",
"ax.set_ylabel(\"Price per 1 unit (in USD)\");\n",
"plt.title(\"Price per unit currency\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 301
},
"id": "0XQYcAf8Xy2o",
"outputId": "5dc80b97-f28a-40b7-f929-13cb06120176"
},
"outputs": [],
"source": [
"ax = data_top_6_currencies.groupby(['date', 'name'])['market_billion'].mean().unstack().plot();\n",
"ax.set_ylabel(\"Market Cap (in billion USD)\");\n",
"plt.title(\"Market cap per unit currency\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 506
},
"id": "_Ezp2S7NX9sI",
"outputId": "7da7fcc0-5908-4dd8-f980-bb7f8fce40da"
},
"outputs": [],
"source": [
"#co-relation between different cryptos\n",
"plt.figure(figsize=(14,8))\n",
"sns.heatmap(wide_format[top_6_currency_names].corr(),vmin=0, vmax=1, cmap='coolwarm', annot=True);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "NbAmRhK-CrQV",
"outputId": "e8338b77-ce5e-47ba-f17c-1b971f2d4b2b"
},
"outputs": [],
"source": [
"data_top_6_currencies.head(5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 661
},
"id": "yy3-xD2qJ8lI",
"outputId": "cf7f6044-f55c-4ee1-c38b-47e99bd705bd"
},
"outputs": [],
"source": [
"data_top_6_currencies.drop(['ranknow'],axis=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "O1V5XiRaF1DU",
"outputId": "d551e810-f579-4252-8c89-99a5b97df7ff"
},
"outputs": [],
"source": [
"data_top_6_currencies.shape"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TNJ2Lwm3KDAX"
},
"source": [
"#Bitcoin"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "49_WACQuDBll",
"outputId": "5f524485-7bfd-4400-ac65-08819492e014"
},
"outputs": [],
"source": [
"#bitcoin\n",
"df1 = data_top_6_currencies[data_top_6_currencies['name']=='Bitcoin']\n",
"\n",
"df1.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "JjcbrGKDQTQC",
"outputId": "045951bb-0e3a-499b-ed16-8fcba13e5896"
},
"outputs": [],
"source": [
"print(df1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "l6R9yP7G_7C9",
"outputId": "7ec05f9a-69a0-4b30-9b00-8062d5ab045a"
},
"outputs": [],
"source": [
"df1.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "X4QbNB76AUtO",
"outputId": "3853da87-8db7-483b-bd83-0d69a36e18bc"
},
"outputs": [],
"source": [
"d = df1.iloc[:, 5:10]\n",
"print(d.head())\n",
"print(d.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 410
},
"id": "zDuTpvheHFQ-",
"outputId": "9c6fdee9-de24-4f66-d1c6-00c12a69dad4"
},
"outputs": [],
"source": [
"plt.figure(figsize=(12,6))\n",
"sns.lineplot(x=d.index, y=\"open\", data=d).set_title(\"Price of Bitcoin\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "35cpNfDfHFUN",
"outputId": "23b39114-4fc4-42a3-d7a3-aeab60030a3b"
},
"outputs": [],
"source": [
"data = d.iloc[:, 0]\n",
"print(len(data))\n",
"print(data)\n",
"hist = []\n",
"target = []\n",
"length = 90\n",
"for i in range(len(data)-length):\n",
" x = data[i:i+length]\n",
" y = data[i+length]\n",
" hist.append(x)\n",
" target.append(y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ybiiTeB7HFad",
"outputId": "97d5b512-2429-44d3-bc73-5a94b9325916"
},
"outputs": [],
"source": [
"print(hist[1][89])\n",
"print(data[90])\n",
"print(target[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "e5cpw-VsHTGw"
},
"outputs": [],
"source": [
"hist = np.array(hist)\n",
"target = np.array(target)\n",
"target = target.reshape(-1,1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Ook8PYf9HTLD"
},
"outputs": [],
"source": [
"from sklearn.preprocessing import MinMaxScaler\n",
"sc = MinMaxScaler()\n",
"hist_scaled = sc.fit_transform(hist)\n",
"target_scaled = sc.fit_transform(target)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "T_-csG_1HTON",
"outputId": "5fbb5f68-96e1-4f98-fae9-1dbb1fbf7e47"
},
"outputs": [],
"source": [
"hist_scaled = hist_scaled.reshape((len(hist_scaled), length, 1))\n",
"print(hist_scaled.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Ui0ppeSGHTRf"
},
"outputs": [],
"source": [
"X_train = hist_scaled[:1900,:,:]\n",
"X_test = hist_scaled[1900:,:,:]\n",
"y_train = target_scaled[:1900,:]\n",
"y_test = target_scaled[1900:,:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "T5o66_7XHTUm"
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras import layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "9C8DS-c7Hgp1",
"outputId": "e29c0ce0-4ca5-495a-eb3d-3a93be61950b"
},
"outputs": [],
"source": [
"model = tf.keras.Sequential()\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" input_shape=(90,1), dropout=0.2))\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" dropout=0.2))\n",
"model.add(layers.LSTM(units=32, dropout=0.2))\n",
"model.add(layers.Dense(units=1))\n",
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "P91hyF2GHgzR"
},
"outputs": [],
"source": [
"model.compile(optimizer='adam', loss='mean_squared_error')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "I5uoPY81Hmy4",
"outputId": "08ad7eed-2807-415b-cca6-b7f1db79ebf9"
},
"outputs": [],
"source": [
"history = model.fit(X_train, y_train, epochs=30, batch_size=32)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 502
},
"id": "_2skqc4uHoo4",
"outputId": "9334689b-73a1-48c3-9411-c5eff80540f8"
},
"outputs": [],
"source": [
"loss = history.history['loss']\n",
"epoch_count = range(1, len(loss) + 1)\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(epoch_count, loss, 'r--')\n",
"plt.legend(['Training Loss'])\n",
"plt.xlabel('Epoch')\n",
"plt.ylabel('Loss')\n",
"plt.show();"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 501
},
"id": "XeNxAYOlHg8b",
"outputId": "474939e5-3aea-401b-b312-ab3c434ca9b5"
},
"outputs": [],
"source": [
"pred = model.predict(X_test)\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(y_test, color='blue', label='Real')\n",
"plt.plot(pred, color='red', label='Prediction')\n",
"plt.title('Bitcoin Price Prediction')\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "I7VuAnbfJByj"
},
"source": [
"#XRP (Ripple)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ZK38bhh6JByj",
"outputId": "022a7b36-5a24-43b5-bfb1-e14b29dc6af1"
},
"outputs": [],
"source": [
"#bitcoin\n",
"df2 = data_top_6_currencies[data_top_6_currencies['name']=='XRP']\n",
"\n",
"df2.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "jV8de94uJByj",
"outputId": "16f68219-e348-47fe-ec42-156427813871"
},
"outputs": [],
"source": [
"print(df2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "vT1hHSzbJByk",
"outputId": "0c15cfeb-ac61-446b-97ae-91a31b813235"
},
"outputs": [],
"source": [
"df2.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "bOfzu0IhJByk",
"outputId": "99041c2b-6683-45d9-fee7-3d9e2ba89101"
},
"outputs": [],
"source": [
"d2 = df2.iloc[:, 5:10]\n",
"print(d2.head())\n",
"print(d2.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 410
},
"id": "hSNYPEm7JByk",
"outputId": "b1bb1d23-7a54-4439-d8fa-f204886cab79"
},
"outputs": [],
"source": [
"plt.figure(figsize=(12,6))\n",
"sns.lineplot(x=d2.index, y=\"open\", data=d2).set_title(\"Price of Ripple\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "pcllm_j2JByk",
"outputId": "effc2f69-4149-4390-be0e-f260f5ae6ec2"
},
"outputs": [],
"source": [
"data = d2.iloc[:, 0]\n",
"\n",
"print(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "JoAgH76ZLPjI"
},
"outputs": [],
"source": [
"hist = []\n",
"target = []\n",
"length = 90\n",
"for i in range(2042,len(data)-length):\n",
" x = data[2042:i+length]\n",
" y = data[i+length]\n",
" hist.append(x)\n",
" target.append(y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "jGSDstNAJByl"
},
"outputs": [],
"source": [
"hist = np.array(hist)\n",
"target = np.array(target)\n",
"target = target.reshape(-1,1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "FpugPkG9NAtl"
},
"outputs": [],
"source": [
"hist = hist.reshape(-1,1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 381
},
"id": "icGR5bLNJByl",
"outputId": "2e8b762b-8ce2-4d91-bd44-a006a6fe559e"
},
"outputs": [],
"source": [
"from sklearn.preprocessing import MinMaxScaler\n",
"sc = MinMaxScaler()\n",
"hist_scaled = sc.fit_transform(hist)\n",
"target_scaled = sc.fit_transform(target)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "AXyWLswgJByl",
"outputId": "27002554-6aff-4173-bfcc-dff86d04a1d2"
},
"outputs": [],
"source": [
"hist_scaled = hist_scaled.reshape((len(hist_scaled), length, 1))\n",
"print(hist_scaled.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "j9I5SQkPJByl"
},
"outputs": [],
"source": [
"X_train = hist_scaled[:1900,:,:]\n",
"X_test = hist_scaled[1900:,:,:]\n",
"y_train = target_scaled[:1900,:]\n",
"y_test = target_scaled[1900:,:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "wMmrZ7hFJByl"
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras import layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Tfb5_8l6JByl",
"outputId": "c59503b3-e2cf-4ccc-ab5a-3d487da4d767"
},
"outputs": [],
"source": [
"model = tf.keras.Sequential()\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" input_shape=(90,1), dropout=0.2))\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" dropout=0.2))\n",
"model.add(layers.LSTM(units=32, dropout=0.2))\n",
"model.add(layers.Dense(units=1))\n",
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "XblbdTVWJByl"
},
"outputs": [],
"source": [
"model.compile(optimizer='adam', loss='mean_squared_error')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wCu3FeoiJBym",
"outputId": "9e95db9e-0329-42e8-a740-f56c4c8f1ce1"
},
"outputs": [],
"source": [
"history = model.fit(X_train, y_train, epochs=30, batch_size=32)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 501
},
"id": "jqnFts9HJBym",
"outputId": "4d9124d3-4f27-4678-d728-7037c6b723fa"
},
"outputs": [],
"source": [
"pred = model.predict(X_test)\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(y_test, color='blue', label='Real')\n",
"plt.plot(pred, color='red', label='Prediction')\n",
"plt.title('Ripple Price Prediction')\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "HVw69BHsP-SH"
},
"source": [
"#Ethereum"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "6Gf_B5zeP-SI",
"outputId": "f8b449f2-2861-485b-a856-d34e57c17867"
},
"outputs": [],
"source": [
"#bitcoin\n",
"df3 = data_top_6_currencies[data_top_6_currencies['slug']=='ethereum']\n",
"\n",
"df3.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wTrWsHkZP-SI",
"outputId": "5790481a-51d7-4fcf-c069-acb926892bcb"
},
"outputs": [],
"source": [
"print(df3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "zsvIQYO3P-SI",
"outputId": "57dc9c1a-5cb2-47d2-9a82-b99842248a94"
},
"outputs": [],
"source": [
"df3.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "TnheAbnAP-SI",
"outputId": "f3948958-bb36-4936-8eac-86179eaf36f2"
},
"outputs": [],
"source": [
"d3 = df3.iloc[:, 5:10]\n",
"print(d3.head())\n",
"print(d3.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 410
},
"id": "T3xP1Eo8P-SJ",
"outputId": "e6c83d5e-0291-41a2-94c7-91cc5afb6104"
},
"outputs": [],
"source": [
"plt.figure(figsize=(12,6))\n",
"sns.lineplot(x=d3.index, y=\"open\", data=d3).set_title(\"Price of Ethereum\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "kbwR0m7RP-SJ",
"outputId": "4880a7a3-544e-4a9c-c33d-ca7f1e7d0221"
},
"outputs": [],
"source": [
"data = d3.iloc[:, 0]\n",
"\n",
"print(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "KPzSexH2P-SJ"
},
"outputs": [],
"source": [
"hist = []\n",
"target = []\n",
"length = 90\n",
"for i in range(3986,len(data)-length):\n",
" x = data[3986:i+length]\n",
" y = data[i+length]\n",
" hist.append(x)\n",
" target.append(y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "I5QVQECtP-SJ"
},
"outputs": [],
"source": [
"hist = np.array(hist)\n",
"target = np.array(target)\n",
"target = target.reshape(-1,1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "rhe9sKH3P-SJ"
},
"outputs": [],
"source": [
"hist = hist.reshape(-1,1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "FNSDMq0mP-SK",
"outputId": "e90ec60d-7d53-468e-cc15-43f4f25b1dba"
},
"outputs": [],
"source": [
"hist_scaled = hist_scaled.reshape((len(hist_scaled), length, 1))\n",
"print(hist_scaled.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bBrwRQLsP-SK"
},
"outputs": [],
"source": [
"X_train = hist_scaled[:1900,:,:]\n",
"X_test = hist_scaled[1900:,:,:]\n",
"y_train = target_scaled[:1900,:]\n",
"y_test = target_scaled[1900:,:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "zvGPHlb2P-SK"
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras import layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "aWFjURq-P-SK",
"outputId": "f941254d-4964-4573-85c7-1ff0fe062ca8"
},
"outputs": [],
"source": [
"model = tf.keras.Sequential()\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" input_shape=(90,1), dropout=0.2))\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" dropout=0.2))\n",
"model.add(layers.LSTM(units=32, dropout=0.2))\n",
"model.add(layers.Dense(units=1))\n",
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "gcUc1ZBHP-SK"
},
"outputs": [],
"source": [
"model.compile(optimizer='adam', loss='mean_squared_error')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ZfAB0JWTP-SK",
"outputId": "45985017-af61-43c6-cc29-d85d10c38a68"
},
"outputs": [],
"source": [
"history = model.fit(X_train, y_train, epochs=30, batch_size=32)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 504
},
"id": "DT2SuvDdP-SK",
"outputId": "1aa682fa-9709-457f-845d-a6c5b4b8d126"
},
"outputs": [],
"source": [
"loss = history.history['loss']\n",
"epoch_count = range(1, len(loss) + 1)\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(epoch_count, loss, 'r--')\n",
"plt.legend(['Training Loss'])\n",
"plt.xlabel('Epoch')\n",
"plt.ylabel('Loss')\n",
"plt.show();"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 501
},
"id": "eArbMF4TP-SL",
"outputId": "306dcd95-93db-47f1-8c32-c97757c9b584"
},
"outputs": [],
"source": [
"pred = model.predict(X_test)\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(y_test, color='blue', label='Real')\n",
"plt.plot(pred, color='red', label='Prediction')\n",
"plt.title('Ethereum Price Prediction')\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "k4_p4ZjbUJWo"
},
"source": [
"#Bitcoin Cash (BCH)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "O4H46vFAUJWo",
"outputId": "515cdde8-18ad-4f16-effa-dd66d0ac6380"
},
"outputs": [],
"source": [
"\n",
"df4 = data_top_6_currencies[data_top_6_currencies['symbol']=='BCH']\n",
"\n",
"df4.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "5-4itcj_UJWo",
"outputId": "35e6401a-92fb-4f3d-d845-4246d7e5c05f"
},
"outputs": [],
"source": [
"print(df4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "mn_n52xrUJWo",
"outputId": "b2088956-9bf1-4b69-ade6-ef1049fd8f15"
},
"outputs": [],
"source": [
"df4.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "lNOi437hUJWp",
"outputId": "4acc7d16-f0b8-4458-86b6-8b895f60776b"
},
"outputs": [],
"source": [
"d4 = df4.iloc[:, 5:10]\n",
"print(d4.head())\n",
"print(d4.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 410
},
"id": "WHrBesaXUJWp",
"outputId": "5a43e17c-b851-4460-a112-9e7f950c115f"
},
"outputs": [],
"source": [
"plt.figure(figsize=(12,6))\n",
"sns.lineplot(x=d4.index, y=\"open\", data=d4).set_title(\"Price of Bitcoin Cash\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "YIlXzSaUUJWp",
"outputId": "e4214da2-9147-4e4f-ddbf-60224a7ab83e"
},
"outputs": [],
"source": [
"data = d4.iloc[:, 0]\n",
"\n",
"print(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "sZeAotUnUJWp"
},
"outputs": [],
"source": [
"hist = []\n",
"target = []\n",
"length = 90\n",
"for i in range(6775,len(data)-length):\n",
" x = data[6775:i+length]\n",
" y = data[i+length]\n",
" hist.append(x)\n",
" target.append(y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SBJAZqjGUJWp"
},
"outputs": [],
"source": [
"hist = np.array(hist)\n",
"target = np.array(target)\n",
"target = target.reshape(-1,1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "jLGddq22UJWp"
},
"outputs": [],
"source": [
"hist = hist.reshape(1,-1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hC4XeVpMUJWq",
"outputId": "d822ff1e-cb56-4e83-cb99-c7792309c96c"
},
"outputs": [],
"source": [
"hist_scaled = hist_scaled.reshape((len(hist_scaled), length, 1))\n",
"print(hist_scaled.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xctoaT_KUJWq"
},
"outputs": [],
"source": [
"X_train = hist_scaled[:1900,:,:]\n",
"X_test = hist_scaled[1900:,:,:]\n",
"y_train = target_scaled[:1900,:]\n",
"y_test = target_scaled[1900:,:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "kTzfwpunUJWq"
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras import layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "RoZrj801UJWq",
"outputId": "5bcea4f2-4c03-4c59-d37f-1330e4e8795b"
},
"outputs": [],
"source": [
"model = tf.keras.Sequential()\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" input_shape=(90,1), dropout=0.2))\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" dropout=0.2))\n",
"model.add(layers.LSTM(units=32, dropout=0.2))\n",
"model.add(layers.Dense(units=1))\n",
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bb-ArUEIUJWq"
},
"outputs": [],
"source": [
"model.compile(optimizer='adam', loss='mean_squared_error')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "bQebGMcsUJWq",
"outputId": "aa752aaa-dbd6-4aac-cae6-42f18e6f7b1d"
},
"outputs": [],
"source": [
"history = model.fit(X_train, y_train, epochs=30, batch_size=32)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 501
},
"id": "UH77ijSZUJWq",
"outputId": "9009ae84-499d-4c8d-d18e-dc8fc479ecb7"
},
"outputs": [],
"source": [
"pred = model.predict(X_test)\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(y_test, color='blue', label='Real')\n",
"plt.plot(pred, color='red', label='Prediction')\n",
"plt.title('Bitcoin Cash Prediction')\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "zIyf6qzoX2oL"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "pBEwefqtX3kW"
},
"source": [
"#EOS"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "TjCsw9DNX3kW",
"outputId": "c44e67f8-b66c-4c41-c898-73f7821629aa"
},
"outputs": [],
"source": [
"df5 = data_top_6_currencies[data_top_6_currencies['symbol']=='EOS']\n",
"\n",
"df5.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "7VzpsN7TX3kW",
"outputId": "81f3990c-1939-4fe5-818f-8e597166f8f6"
},
"outputs": [],
"source": [
"print(df5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "e-d8UPiHX3kW",
"outputId": "253e678c-66a2-4f72-d8b9-5422a9fee9e6"
},
"outputs": [],
"source": [
"df5.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "stGfWD9YX3kX",
"outputId": "cbaee387-a35d-483d-d0b4-3c4c6d1293e8"
},
"outputs": [],
"source": [
"d5 = df5.iloc[:, 5:10]\n",
"print(d5.head())\n",
"print(d5.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 410
},
"id": "Y8SdLCNNX3kX",
"outputId": "2e8edc3b-5e7a-4684-8318-4e6229b17166"
},
"outputs": [],
"source": [
"plt.figure(figsize=(12,6))\n",
"sns.lineplot(x=d5.index, y=\"open\", data=d5).set_title(\"Price of EOS\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wvdmLlFsX3kX",
"outputId": "6a0d3dad-bb9c-4325-cae5-959f222c9ac3"
},
"outputs": [],
"source": [
"data = d5.iloc[:, 0]\n",
"\n",
"print(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "yawhGJ_rX3kX"
},
"outputs": [],
"source": [
"hist = []\n",
"target = []\n",
"length = 90\n",
"for i in range(7270,len(data)-length):\n",
" x = data[7270:i+length]\n",
" y = data[i+length]\n",
" hist.append(x)\n",
" target.append(y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ldt2BGLhX3kX"
},
"outputs": [],
"source": [
"hist = np.array(hist)\n",
"target = np.array(target)\n",
"target = target.reshape(-1,1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ylr7fwbAX3kX"
},
"outputs": [],
"source": [
"hist = hist.reshape(1,-1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ejlHo8paX3kX",
"outputId": "49925969-2cfb-42de-9d6e-c1e695866eec"
},
"outputs": [],
"source": [
"hist_scaled = hist_scaled.reshape((len(hist_scaled), length, 1))\n",
"print(hist_scaled.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "TOFbdITuX3kX"
},
"outputs": [],
"source": [
"X_train = hist_scaled[:1900,:,:]\n",
"X_test = hist_scaled[1900:,:,:]\n",
"y_train = target_scaled[:1900,:]\n",
"y_test = target_scaled[1900:,:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2q1aJEr5X3kY"
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras import layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "zAml_KZ4X3kY",
"outputId": "0c411e7b-36d4-4ac5-9f14-b2bdac508d0b"
},
"outputs": [],
"source": [
"model = tf.keras.Sequential()\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" input_shape=(90,1), dropout=0.2))\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" dropout=0.2))\n",
"model.add(layers.LSTM(units=32, dropout=0.2))\n",
"model.add(layers.Dense(units=1))\n",
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "blIv5kwJX3kY"
},
"outputs": [],
"source": [
"model.compile(optimizer='adam', loss='mean_squared_error')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "PYbQNxSRX3kY",
"outputId": "9a4cbc6e-4075-47e9-820f-083cdc6c59f5"
},
"outputs": [],
"source": [
"history = model.fit(X_train, y_train, epochs=30, batch_size=32)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 501
},
"id": "TT6qgo_iX3kY",
"outputId": "cb71873e-b886-4e41-9947-f2b3765d2f6e"
},
"outputs": [],
"source": [
"pred = model.predict(X_test)\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(y_test, color='blue', label='Real')\n",
"plt.plot(pred, color='red', label='Prediction')\n",
"plt.title('EOS Prediction')\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "F087Ykqwazgx"
},
"source": [
"#Stellar"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "gSZO1_fBa5Oe",
"outputId": "e7db4e69-1838-409d-e2fe-1c8c92614a2c"
},
"outputs": [],
"source": [
"df6 = data_top_6_currencies[data_top_6_currencies['name']=='Stellar']\n",
"\n",
"df6.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mejmybDCa5Of",
"outputId": "573b4195-a4fd-47c3-a924-2579a992512e"
},
"outputs": [],
"source": [
"print(df6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "6jooY2Gza5Of",
"outputId": "cb00a2dd-c0ba-4ade-9a3f-5f769a78a2bb"
},
"outputs": [],
"source": [
"df6.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "u4YVMNKha5Of",
"outputId": "33a752e7-ee5a-4f3b-be07-032b4400973e"
},
"outputs": [],
"source": [
"d = df6.iloc[:, 5:10]\n",
"print(d.head())\n",
"print(d.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 410
},
"id": "Pib0FOL3a5Of",
"outputId": "64bbcef9-615a-45c8-817c-d607016ab130"
},
"outputs": [],
"source": [
"plt.figure(figsize=(12,6))\n",
"sns.lineplot(x=d.index, y=\"open\", data=d).set_title(\"Price of Stellar\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "1FPPamzibSiL",
"outputId": "05da7d73-8e57-4f94-b52d-da5d4cf97102"
},
"outputs": [],
"source": [
"print(d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "O5snSz7Aa5Of",
"outputId": "83f62e46-1b7f-4825-cc84-2128c9d2c5be"
},
"outputs": [],
"source": [
"data = d.iloc[:, 0]\n",
"print(len(data))\n",
"print(data)\n",
"hist = []\n",
"target = []\n",
"length = 90\n",
"for i in range(5197, len(data)-length):\n",
" x = data[5197,:i+length]\n",
" y = data[i+length]\n",
" hist.append(x)\n",
" target.append(y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5wCLydLha5Og"
},
"outputs": [],
"source": [
"hist = np.array(hist)\n",
"target = np.array(target)\n",
"target = target.reshape(-1,1)\n",
"hist=hist.reshape(-1,1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "PxEu7xN0a5Og"
},
"outputs": [],
"source": [
"from sklearn.preprocessing import MinMaxScaler\n",
"sc = MinMaxScaler()\n",
"hist_scaled = sc.fit_transform(hist)\n",
"target_scaled = sc.fit_transform(target)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "JBgXLlZAa5Og",
"outputId": "371d59f2-bdfe-4e90-b328-3ba17be8f29f"
},
"outputs": [],
"source": [
"hist_scaled = hist_scaled.reshape((len(hist_scaled), length, 1))\n",
"print(hist_scaled.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "wmqhRFVUa5Og"
},
"outputs": [],
"source": [
"X_train = hist_scaled[:1900,:,:]\n",
"X_test = hist_scaled[1900:,:,:]\n",
"y_train = target_scaled[:1900,:]\n",
"y_test = target_scaled[1900:,:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "hKMNQyGna5Og"
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras import layers"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wIUvXFUCa5Og",
"outputId": "7a104795-05f8-411f-94f9-314eb6c46b84"
},
"outputs": [],
"source": [
"model = tf.keras.Sequential()\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" input_shape=(90,1), dropout=0.2))\n",
"model.add(layers.LSTM(units=32, return_sequences=True,\n",
" dropout=0.2))\n",
"model.add(layers.LSTM(units=32, dropout=0.2))\n",
"model.add(layers.Dense(units=1))\n",
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2JVd7TxPa5Og"
},
"outputs": [],
"source": [
"model.compile(optimizer='adam', loss='mean_squared_error')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "m5lWh3Yba5Oh",
"outputId": "2846ed4f-6ace-4a2f-b80c-b580aba9a176"
},
"outputs": [],
"source": [
"history = model.fit(X_train, y_train, epochs=30, batch_size=32)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 501
},
"id": "bCmQ1HDRa5Oh",
"outputId": "ed8ad8b9-4bb2-4563-f756-26dde67ca6eb"
},
"outputs": [],
"source": [
"pred = model.predict(X_test)\n",
"plt.figure(figsize=(12,8))\n",
"plt.plot(y_test, color='blue', label='Real')\n",
"plt.plot(pred, color='red', label='Prediction')\n",
"plt.title('Stellar Price Prediction')\n",
"plt.legend()\n",
"plt.show()"
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [
"W06FRpNCHKCo",
"sQ_p1oakHNPn",
"bGQUmu60NwRD",
"VJIl1DwwN43f"
],
"provenance": []
},
"kernelspec": {
"display_name": "Python 3.10.7 64-bit (microsoft store)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
},
"vscode": {
"interpreter": {
"hash": "94348be3325f1ae160a67cb39ab80a1e458b4a3911d8ece2b1e6db7371f6660e"
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}