diff --git a/Tesla Historic Stock Price Analysis/Dataset/README.md b/Tesla Historic Stock Price Analysis/Dataset/README.md new file mode 100644 index 000000000..85e20531f --- /dev/null +++ b/Tesla Historic Stock Price Analysis/Dataset/README.md @@ -0,0 +1,13 @@ +# **Tesla Ticker | Historical Stock Price Dataset** + +This dataset contains the historical stock prices of Tesla, Inc. (TSLA). + +### Insights +- Analyze historical trends in Tesla's stock price +- Forecast future stock price movements + +### Source +Acquired from the Yahoo Finance library + +### Dataset Link +https://www.kaggle.com/datasets/muhammadibrahimqasmi/tesla-stock-insights-and-predictions/data \ No newline at end of file diff --git a/Tesla Historic Stock Price Analysis/Images/3D_SurfacePlot.png b/Tesla Historic Stock Price Analysis/Images/3D_SurfacePlot.png new file mode 100644 index 000000000..c45193ec5 Binary files /dev/null and b/Tesla Historic Stock Price Analysis/Images/3D_SurfacePlot.png differ diff --git a/Tesla Historic Stock Price Analysis/Images/CandlestickPlot.png b/Tesla Historic Stock Price Analysis/Images/CandlestickPlot.png new file mode 100644 index 000000000..5ba194fed Binary files /dev/null and b/Tesla Historic Stock Price Analysis/Images/CandlestickPlot.png differ diff --git a/Tesla Historic Stock Price Analysis/Images/FanChart.png b/Tesla Historic Stock Price Analysis/Images/FanChart.png new file mode 100644 index 000000000..29e6c14e8 Binary files /dev/null and b/Tesla Historic Stock Price Analysis/Images/FanChart.png differ diff --git a/Tesla Historic Stock Price Analysis/Images/LinePlot_ClosingPrice.png b/Tesla Historic Stock Price Analysis/Images/LinePlot_ClosingPrice.png new file mode 100644 index 000000000..3e0ce7d19 Binary files /dev/null and b/Tesla Historic Stock Price Analysis/Images/LinePlot_ClosingPrice.png differ diff --git a/Tesla Historic Stock Price Analysis/Images/LinePlot_Open.png b/Tesla Historic Stock Price Analysis/Images/LinePlot_Open.png new file mode 100644 index 000000000..8918403cf Binary files /dev/null and b/Tesla Historic Stock Price Analysis/Images/LinePlot_Open.png differ diff --git a/Tesla Historic Stock Price Analysis/Images/MovingAverage.png b/Tesla Historic Stock Price Analysis/Images/MovingAverage.png new file mode 100644 index 000000000..209ecad13 Binary files /dev/null and b/Tesla Historic Stock Price Analysis/Images/MovingAverage.png differ diff --git a/Tesla Historic Stock Price Analysis/Model/tesla-ticker-bigru.ipynb b/Tesla Historic Stock Price Analysis/Model/tesla-ticker-bigru.ipynb new file mode 100644 index 000000000..995f720ec --- /dev/null +++ b/Tesla Historic Stock Price Analysis/Model/tesla-ticker-bigru.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Tesla Ticker| Histroical Stock Price Dataset| GRU| BiGRU"]},{"cell_type":"code","execution_count":1,"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2024-06-20T17:33:21.834984Z","iopub.status.busy":"2024-06-20T17:33:21.834489Z","iopub.status.idle":"2024-06-20T17:33:42.911579Z","shell.execute_reply":"2024-06-20T17:33:42.910348Z","shell.execute_reply.started":"2024-06-20T17:33:21.834946Z"},"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["2024-06-20 17:33:29.010197: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n","2024-06-20 17:33:29.010414: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n","2024-06-20 17:33:29.195465: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n"]}],"source":["# Import Libararies\n","import pandas as pd\n","import seaborn as sns\n","import matplotlib.pyplot as plt\n","import numpy as np\n","# implort plotly for interactive plots\n","import plotly.express as px\n","import plotly.graph_objects as go\n","from plotly.offline import iplot\n","#import plot_acf\n","from statsmodels.graphics.tsaplots import plot_acf\n","# import seasonal decompose\n","from statsmodels.tsa.seasonal import seasonal_decompose\n","# scaler\n","from sklearn.preprocessing import MinMaxScaler\n","# train_test_split\n","from sklearn.model_selection import train_test_split\n","# sequential using keras\n","from tensorflow.keras.models import Sequential\n","# Dense, Bidirectional,GRU Layers using keras\n","from tensorflow.keras.layers import Dense, Bidirectional, GRU\n","# Adam optimizer\n","from tensorflow.keras.optimizers import Adam\n","# Early stoppng or callbacks\n","from tensorflow.keras.callbacks import EarlyStopping\n","# import metrics\n","from sklearn.metrics import r2_score, mean_squared_error\n","# import warnings\n","import warnings \n","warnings.filterwarnings('ignore')"]},{"cell_type":"markdown","metadata":{},"source":["## BiGRU"]},{"cell_type":"code","execution_count":27,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:38:25.753838Z","iopub.status.busy":"2024-06-20T17:38:25.753284Z","iopub.status.idle":"2024-06-20T17:39:00.332807Z","shell.execute_reply":"2024-06-20T17:39:00.331452Z","shell.execute_reply.started":"2024-06-20T17:38:25.753799Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["Epoch 1/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m11s\u001b[0m 97ms/step - loss: 0.1124 - mae: 0.2437 - val_loss: 0.0053 - val_mae: 0.0648\n","Epoch 2/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 51ms/step - loss: 0.0051 - mae: 0.0563 - val_loss: 0.0048 - val_mae: 0.0593\n","Epoch 3/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 47ms/step - loss: 0.0031 - mae: 0.0406 - val_loss: 0.0025 - val_mae: 0.0432\n","Epoch 4/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 0.0020 - mae: 0.0333 - val_loss: 0.0019 - val_mae: 0.0361\n","Epoch 5/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 49ms/step - loss: 0.0015 - mae: 0.0285 - val_loss: 0.0014 - val_mae: 0.0297\n","Epoch 6/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 0.0013 - mae: 0.0255 - val_loss: 0.0011 - val_mae: 0.0269\n","Epoch 7/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 0.0011 - mae: 0.0242 - val_loss: 0.0011 - val_mae: 0.0271\n","Epoch 8/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 49ms/step - loss: 0.0011 - mae: 0.0244 - val_loss: 0.0012 - val_mae: 0.0285\n","Epoch 9/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 0.0011 - mae: 0.0246 - val_loss: 0.0013 - val_mae: 0.0287\n","Epoch 10/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 0.0011 - mae: 0.0240 - val_loss: 0.0012 - val_mae: 0.0277\n","Epoch 11/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 0.0010 - mae: 0.0233 - val_loss: 0.0011 - val_mae: 0.0270\n","Epoch 12/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 0.0010 - mae: 0.0229 - val_loss: 0.0011 - val_mae: 0.0264\n","Epoch 13/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 9.8533e-04 - mae: 0.0226 - val_loss: 0.0010 - val_mae: 0.0259\n","Epoch 14/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 9.6125e-04 - mae: 0.0223 - val_loss: 0.0010 - val_mae: 0.0253\n","Epoch 15/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 9.4035e-04 - mae: 0.0221 - val_loss: 9.6782e-04 - val_mae: 0.0249\n","Epoch 16/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 48ms/step - loss: 9.2149e-04 - mae: 0.0218 - val_loss: 9.3528e-04 - val_mae: 0.0244\n","Epoch 17/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 55ms/step - loss: 9.0458e-04 - mae: 0.0216 - val_loss: 9.0525e-04 - val_mae: 0.0240\n","Epoch 18/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 64ms/step - loss: 8.8945e-04 - mae: 0.0214 - val_loss: 8.7729e-04 - val_mae: 0.0236\n","Epoch 19/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m2s\u001b[0m 55ms/step - loss: 8.7584e-04 - mae: 0.0212 - val_loss: 8.5052e-04 - val_mae: 0.0232\n","Epoch 20/20\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 51ms/step - loss: 8.6375e-04 - mae: 0.0211 - val_loss: 8.2513e-04 - val_mae: 0.0229\n","\u001b[1m6/6\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m2s\u001b[0m 164ms/step\n","\u001b[1m6/6\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 14ms/step - loss: 4.8865e-04 - mae: 0.0169\n","Test Loss: 0.0005475360667333007\n","Test MAE: 0.018060998991131783\n","R2 Score: 0.9174902227784482\n","Mean Squared Error: 0.0005475360082505356\n"]}],"source":["import numpy as np\n","import tensorflow as tf\n","from sklearn.model_selection import train_test_split\n","from sklearn.preprocessing import MinMaxScaler\n","from sklearn.metrics import mean_squared_error, r2_score\n","from tensorflow.keras.models import Sequential\n","from tensorflow.keras.layers import Bidirectional, GRU, Dense\n","from tensorflow.keras.optimizers import Adam\n","from tensorflow.keras.callbacks import EarlyStopping\n","\n","# Normalize the data\n","scaler = MinMaxScaler()\n","df['Close'] = scaler.fit_transform(df[['Close']])\n","\n","# Split the dataset into training and testing sets\n","train_data, test_data = train_test_split(df['Close'], test_size=0.2, shuffle=False, random_state=42)\n","\n","# Prepare input sequences and target values\n","def create_sequences(data, window_size):\n"," X, y = [], []\n"," for i in range(len(data) - window_size):\n"," X.append(data[i:i+window_size])\n"," y.append(data[i+window_size])\n"," return np.array(X), np.array(y)\n","\n","window_size = 30\n","X_train, y_train = create_sequences(train_data.values, window_size)\n","X_test, y_test = create_sequences(test_data.values, window_size)\n","\n","# Reshape input data to include the feature dimension\n","X_train = X_train.reshape(-1, window_size, 1)\n","X_test = X_test.reshape(-1, window_size, 1)\n","\n","# Define the deeper BiGRU model with early stopping\n","model = Sequential([\n"," Bidirectional(GRU(64, return_sequences=True, input_shape=(window_size, 1))),\n"," Bidirectional(GRU(64)),\n"," Dense(32, activation='relu'),\n"," Dense(1)\n","])\n","\n","model.compile(optimizer=Adam(), loss='mse', metrics=['mae'])\n","\n","# Define early stopping criteria\n","early_stopping = EarlyStopping(monitor='val_loss', patience=5, restore_best_weights=True)\n","\n","# Train the model with early stopping\n","model.fit(X_train, y_train, epochs=20, batch_size=32, validation_split=0.2, callbacks=[early_stopping])\n","\n","# Predictions\n","y_pred = model.predict(X_test)\n","\n","# Evaluation\n","loss, mae = model.evaluate(X_test, y_test)\n","print('Test Loss:', loss)\n","print('Test MAE:', mae)\n","\n","# Calculate R2 score\n","r2 = r2_score(y_test, y_pred)\n","print('R2 Score:', r2)\n","\n","# Calculate MSE\n","mse = mean_squared_error(y_test, y_pred)\n","print('Mean Squared Error:', mse)"]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":4772437,"sourceId":8084907,"sourceType":"datasetVersion"}],"dockerImageVersionId":30732,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","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.13"}},"nbformat":4,"nbformat_minor":4} diff --git a/Tesla Historic Stock Price Analysis/Model/tesla-ticker-data-exploration-1.ipynb b/Tesla Historic Stock Price Analysis/Model/tesla-ticker-data-exploration-1.ipynb new file mode 100644 index 000000000..0040aed85 --- /dev/null +++ b/Tesla Historic Stock Price Analysis/Model/tesla-ticker-data-exploration-1.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Tesla Ticker| Histroical Stock Price Dataset| GRU| BiGRU"]},{"cell_type":"code","execution_count":1,"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2024-06-20T17:33:21.834984Z","iopub.status.busy":"2024-06-20T17:33:21.834489Z","iopub.status.idle":"2024-06-20T17:33:42.911579Z","shell.execute_reply":"2024-06-20T17:33:42.910348Z","shell.execute_reply.started":"2024-06-20T17:33:21.834946Z"},"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["2024-06-20 17:33:29.010197: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n","2024-06-20 17:33:29.010414: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n","2024-06-20 17:33:29.195465: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n"]}],"source":["# Import Libararies\n","import pandas as pd\n","import seaborn as sns\n","import matplotlib.pyplot as plt\n","import numpy as np\n","# implort plotly for interactive plots\n","import plotly.express as px\n","import plotly.graph_objects as go\n","from plotly.offline import iplot\n","#import plot_acf\n","from statsmodels.graphics.tsaplots import plot_acf\n","# import seasonal decompose\n","from statsmodels.tsa.seasonal import seasonal_decompose\n","# scaler\n","from sklearn.preprocessing import MinMaxScaler\n","# train_test_split\n","from sklearn.model_selection import train_test_split\n","# sequential using keras\n","from tensorflow.keras.models import Sequential\n","# Dense, Bidirectional,GRU Layers using keras\n","from tensorflow.keras.layers import Dense, Bidirectional, GRU\n","# Adam optimizer\n","from tensorflow.keras.optimizers import Adam\n","# Early stoppng or callbacks\n","from tensorflow.keras.callbacks import EarlyStopping\n","# import metrics\n","from sklearn.metrics import r2_score, mean_squared_error\n","# import warnings\n","import warnings \n","warnings.filterwarnings('ignore')"]},{"cell_type":"markdown","metadata":{},"source":["## Data Exploration"]},{"cell_type":"code","execution_count":2,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:56.396897Z","iopub.status.busy":"2024-06-20T17:34:56.395709Z","iopub.status.idle":"2024-06-20T17:34:56.453942Z","shell.execute_reply":"2024-06-20T17:34:56.452703Z","shell.execute_reply.started":"2024-06-20T17:34:56.396846Z"},"trusted":true},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
DateYearOpenHighLowCloseVolumeAdj Close
02020-01-02202028.29999928.71333328.11400028.68400014298150028.684000
12020-01-03202029.36666730.26666629.12800029.53400026667750029.534000
22020-01-06202029.36466830.10400029.33333230.10266715199500030.102667
32020-01-07202030.76000031.44199930.22400131.27066626823150031.270666
42020-01-08202031.58000033.23266631.21533432.80933446716450032.809334
\n","
"],"text/plain":[" Date Year Open High Low Close Volume \\\n","0 2020-01-02 2020 28.299999 28.713333 28.114000 28.684000 142981500 \n","1 2020-01-03 2020 29.366667 30.266666 29.128000 29.534000 266677500 \n","2 2020-01-06 2020 29.364668 30.104000 29.333332 30.102667 151995000 \n","3 2020-01-07 2020 30.760000 31.441999 30.224001 31.270666 268231500 \n","4 2020-01-08 2020 31.580000 33.232666 31.215334 32.809334 467164500 \n","\n"," Adj Close \n","0 28.684000 \n","1 29.534000 \n","2 30.102667 \n","3 31.270666 \n","4 32.809334 "]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["df=pd.read_csv(\"/kaggle/input/tesla-stock-insights-and-predictions/tesla_stock_data.csv\")\n","df.head()"]},{"cell_type":"code","execution_count":3,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:57.459117Z","iopub.status.busy":"2024-06-20T17:34:57.458669Z","iopub.status.idle":"2024-06-20T17:34:57.498490Z","shell.execute_reply":"2024-06-20T17:34:57.496509Z","shell.execute_reply.started":"2024-06-20T17:34:57.459081Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["\n","RangeIndex: 996 entries, 0 to 995\n","Data columns (total 8 columns):\n"," # Column Non-Null Count Dtype \n","--- ------ -------------- ----- \n"," 0 Date 996 non-null object \n"," 1 Year 996 non-null int64 \n"," 2 Open 996 non-null float64\n"," 3 High 996 non-null float64\n"," 4 Low 996 non-null float64\n"," 5 Close 996 non-null float64\n"," 6 Volume 996 non-null int64 \n"," 7 Adj Close 996 non-null float64\n","dtypes: float64(5), int64(2), object(1)\n","memory usage: 62.4+ KB\n"]}],"source":["df.info()"]},{"cell_type":"code","execution_count":4,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:58.285530Z","iopub.status.busy":"2024-06-20T17:34:58.284443Z","iopub.status.idle":"2024-06-20T17:34:58.332940Z","shell.execute_reply":"2024-06-20T17:34:58.331267Z","shell.execute_reply.started":"2024-06-20T17:34:58.285476Z"},"trusted":true},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
YearOpenHighLowCloseVolumeAdj Close
count996.000000996.000000996.000000996.000000996.0000009.960000e+02996.000000
mean2021.493976209.203720213.956547204.062843209.1213351.335149e+08209.121335
std1.11857985.88440487.58850683.89460285.7086408.888939e+0785.708640
min2020.00000024.98000026.99066723.36733224.0813332.940180e+0724.081333
25%2020.000000159.780838162.617496154.389996160.2500047.718922e+07160.250004
50%2021.000000223.989998229.250000218.266663223.6516651.074158e+08223.651665
75%2022.000000263.002510268.010002258.120010262.6674961.578296e+08262.667496
max2023.000000411.470001414.496674405.666656409.9700019.140820e+08409.970001
\n","
"],"text/plain":[" Year Open High Low Close \\\n","count 996.000000 996.000000 996.000000 996.000000 996.000000 \n","mean 2021.493976 209.203720 213.956547 204.062843 209.121335 \n","std 1.118579 85.884404 87.588506 83.894602 85.708640 \n","min 2020.000000 24.980000 26.990667 23.367332 24.081333 \n","25% 2020.000000 159.780838 162.617496 154.389996 160.250004 \n","50% 2021.000000 223.989998 229.250000 218.266663 223.651665 \n","75% 2022.000000 263.002510 268.010002 258.120010 262.667496 \n","max 2023.000000 411.470001 414.496674 405.666656 409.970001 \n","\n"," Volume Adj Close \n","count 9.960000e+02 996.000000 \n","mean 1.335149e+08 209.121335 \n","std 8.888939e+07 85.708640 \n","min 2.940180e+07 24.081333 \n","25% 7.718922e+07 160.250004 \n","50% 1.074158e+08 223.651665 \n","75% 1.578296e+08 262.667496 \n","max 9.140820e+08 409.970001 "]},"execution_count":4,"metadata":{},"output_type":"execute_result"}],"source":["df.describe()"]},{"cell_type":"code","execution_count":5,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:59.087573Z","iopub.status.busy":"2024-06-20T17:34:59.087049Z","iopub.status.idle":"2024-06-20T17:34:59.098033Z","shell.execute_reply":"2024-06-20T17:34:59.096068Z","shell.execute_reply.started":"2024-06-20T17:34:59.087533Z"},"trusted":true},"outputs":[{"data":{"text/plain":["Index(['Date', 'Year', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'], dtype='object')"]},"execution_count":5,"metadata":{},"output_type":"execute_result"}],"source":["df.columns"]},{"cell_type":"code","execution_count":6,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:59.842087Z","iopub.status.busy":"2024-06-20T17:34:59.841584Z","iopub.status.idle":"2024-06-20T17:34:59.863903Z","shell.execute_reply":"2024-06-20T17:34:59.861952Z","shell.execute_reply.started":"2024-06-20T17:34:59.842052Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["Starting date is: 2020-01-02\n","Ending date is: 2023-12-29\n"]}],"source":["# Lets convert the Date column to datetime format\n","df['Date']=pd.to_datetime(df['Date'])\n","# Lets find the starting and ending date of the dataset\n","starting_date = df['Date'].min()\n","ending_date = df['Date'].max()\n","# Lets check the Format of dates\n","starting_date_formatted = starting_date.strftime(\"%Y-%m-%d\")\n","ending_date_formatted = ending_date.strftime(\"%Y-%m-%d\")\n","# print the starting and ending date\n","print(\"Starting date is:\", starting_date_formatted)\n","print(\"Ending date is:\", ending_date_formatted)"]},{"cell_type":"code","execution_count":7,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:00.778367Z","iopub.status.busy":"2024-06-20T17:35:00.777728Z","iopub.status.idle":"2024-06-20T17:35:00.792031Z","shell.execute_reply":"2024-06-20T17:35:00.789212Z","shell.execute_reply.started":"2024-06-20T17:35:00.778304Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["Total days in this dataset which represents the stock price are: 1457days\n"]}],"source":["print(f\"Total days in this dataset which represents the stock price are: {(df.Date.max()-df.Date.min()).days}days\")"]},{"cell_type":"code","execution_count":8,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:01.582042Z","iopub.status.busy":"2024-06-20T17:35:01.581562Z","iopub.status.idle":"2024-06-20T17:35:01.598578Z","shell.execute_reply":"2024-06-20T17:35:01.596443Z","shell.execute_reply.started":"2024-06-20T17:35:01.582005Z"},"trusted":true},"outputs":[{"data":{"text/plain":["Date 0\n","Year 0\n","Open 0\n","High 0\n","Low 0\n","Close 0\n","Volume 0\n","Adj Close 0\n","dtype: int64"]},"execution_count":8,"metadata":{},"output_type":"execute_result"}],"source":["df.isnull().sum().sort_values(ascending=True)"]},{"cell_type":"markdown","metadata":{},"source":["## Tesla Price By Line Plot"]},{"cell_type":"code","execution_count":9,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:09.159689Z","iopub.status.busy":"2024-06-20T17:35:09.159169Z","iopub.status.idle":"2024-06-20T17:35:11.341235Z","shell.execute_reply":"2024-06-20T17:35:11.339327Z","shell.execute_reply.started":"2024-06-20T17:35:09.159652Z"},"trusted":true},"outputs":[{"data":{"text/html":[" \n"," "]},"metadata":{},"output_type":"display_data"},{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["# Lets create a trace for the opening stock market price of Tesla\n","trace=go.Scatter(x=df['Date'], y=df['Open'], mode='lines', name='Opening price')\n","# Lets prepare the layout\n","layout = go.Layout(title='Tesla Stock Market Opening Price', xaxis=dict(title='Date'), yaxis=dict(title='Opening Price'))\n","fig=go.Figure(data=[trace], layout=layout)\n","iplot(fig)"]},{"cell_type":"code","execution_count":10,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:16.329782Z","iopub.status.busy":"2024-06-20T17:35:16.328650Z","iopub.status.idle":"2024-06-20T17:35:16.413937Z","shell.execute_reply":"2024-06-20T17:35:16.411898Z","shell.execute_reply.started":"2024-06-20T17:35:16.329732Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["# Lets create a trace for the closing stock market price of Tesla\n","trace=go.Scatter(x=df['Date'], y=df['Close'], mode='lines', name='Closing price')\n","# Lets prepare the layout\n","layout = go.Layout(title='Tesla Stock Market Closing Price', xaxis=dict(title='Date'), yaxis=dict(title='Closing Price'))\n","fig=go.Figure(data=[trace], layout=layout)\n","iplot(fig)"]},{"cell_type":"markdown","metadata":{},"source":["## CandleStick Plot"]},{"cell_type":"code","execution_count":11,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:28.922024Z","iopub.status.busy":"2024-06-20T17:35:28.921509Z","iopub.status.idle":"2024-06-20T17:35:29.044432Z","shell.execute_reply":"2024-06-20T17:35:29.042627Z","shell.execute_reply.started":"2024-06-20T17:35:28.921988Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["trace=go.Candlestick(x=df['Date'],\n"," open=df['Open'],\n"," close=df['Close'],\n"," high=df['High'],\n"," low=df['Low'],\n"," name='Tesla Stock')\n","layout=go.Layout(title='Tesla Stock Market price Candlestick chart',\n"," xaxis=dict(title='Date'),\n"," yaxis=dict(title='Tesla Stock Price'))\n","fig=go.Figure(data=[trace], layout=layout)\n","iplot(fig)"]},{"cell_type":"markdown","metadata":{},"source":["## BarChart Plot"]},{"cell_type":"code","execution_count":12,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:35.924419Z","iopub.status.busy":"2024-06-20T17:35:35.923870Z","iopub.status.idle":"2024-06-20T17:35:35.983322Z","shell.execute_reply":"2024-06-20T17:35:35.982066Z","shell.execute_reply.started":"2024-06-20T17:35:35.924382Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["# Lets groupby the year and open column to determing the yearly closing price of Tesla market\n","yearly_data=df.groupby(\"Year\")['Open'].mean().reset_index()\n","trace=go.Bar(x=yearly_data['Year'], y=yearly_data['Open'],name=\"Yearly Opening Price\")\n","layout=go.Layout(title='Tesla yearly Opening Price',\n"," xaxis=dict(title='Year'),\n"," yaxis=dict(title='Opening Price'))\n","fig=go.Figure(data=[trace], layout=layout)\n","iplot(fig)"]},{"cell_type":"code","execution_count":13,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:37.665174Z","iopub.status.busy":"2024-06-20T17:35:37.664407Z","iopub.status.idle":"2024-06-20T17:35:37.738186Z","shell.execute_reply":"2024-06-20T17:35:37.736960Z","shell.execute_reply.started":"2024-06-20T17:35:37.665112Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["# Lets groupby the year and Close column to determing the yearly closing price of Tesla market\n","yearly_data=df.groupby(\"Year\")['Close'].mean().reset_index()\n","trace=go.Bar(x=yearly_data['Year'], y=yearly_data['Close'],name=\"Yearly Closing Price\")\n","layout=go.Layout(title='Tesla yearly Closing Price',\n"," xaxis=dict(title='Year'),\n"," yaxis=dict(title='Closing Price'))\n","fig=go.Figure(data=[trace], layout=layout)\n","iplot(fig)"]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":4772437,"sourceId":8084907,"sourceType":"datasetVersion"}],"dockerImageVersionId":30732,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","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.13"}},"nbformat":4,"nbformat_minor":4} diff --git a/Tesla Historic Stock Price Analysis/Model/tesla-ticker-data-exploration-2.ipynb b/Tesla Historic Stock Price Analysis/Model/tesla-ticker-data-exploration-2.ipynb new file mode 100644 index 000000000..627e7f82c --- /dev/null +++ b/Tesla Historic Stock Price Analysis/Model/tesla-ticker-data-exploration-2.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Tesla Ticker| Histroical Stock Price Dataset| GRU| BiGRU"]},{"cell_type":"code","execution_count":1,"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2024-06-20T17:33:21.834984Z","iopub.status.busy":"2024-06-20T17:33:21.834489Z","iopub.status.idle":"2024-06-20T17:33:42.911579Z","shell.execute_reply":"2024-06-20T17:33:42.910348Z","shell.execute_reply.started":"2024-06-20T17:33:21.834946Z"},"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["2024-06-20 17:33:29.010197: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n","2024-06-20 17:33:29.010414: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n","2024-06-20 17:33:29.195465: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n"]}],"source":["# Import Libararies\n","import pandas as pd\n","import seaborn as sns\n","import matplotlib.pyplot as plt\n","import numpy as np\n","# implort plotly for interactive plots\n","import plotly.express as px\n","import plotly.graph_objects as go\n","from plotly.offline import iplot\n","#import plot_acf\n","from statsmodels.graphics.tsaplots import plot_acf\n","# import seasonal decompose\n","from statsmodels.tsa.seasonal import seasonal_decompose\n","# scaler\n","from sklearn.preprocessing import MinMaxScaler\n","# train_test_split\n","from sklearn.model_selection import train_test_split\n","# sequential using keras\n","from tensorflow.keras.models import Sequential\n","# Dense, Bidirectional,GRU Layers using keras\n","from tensorflow.keras.layers import Dense, Bidirectional, GRU\n","# Adam optimizer\n","from tensorflow.keras.optimizers import Adam\n","# Early stoppng or callbacks\n","from tensorflow.keras.callbacks import EarlyStopping\n","# import metrics\n","from sklearn.metrics import r2_score, mean_squared_error\n","# import warnings\n","import warnings \n","warnings.filterwarnings('ignore')"]},{"cell_type":"markdown","metadata":{},"source":["## Data Exploration"]},{"cell_type":"code","execution_count":2,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:56.396897Z","iopub.status.busy":"2024-06-20T17:34:56.395709Z","iopub.status.idle":"2024-06-20T17:34:56.453942Z","shell.execute_reply":"2024-06-20T17:34:56.452703Z","shell.execute_reply.started":"2024-06-20T17:34:56.396846Z"},"trusted":true},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
DateYearOpenHighLowCloseVolumeAdj Close
02020-01-02202028.29999928.71333328.11400028.68400014298150028.684000
12020-01-03202029.36666730.26666629.12800029.53400026667750029.534000
22020-01-06202029.36466830.10400029.33333230.10266715199500030.102667
32020-01-07202030.76000031.44199930.22400131.27066626823150031.270666
42020-01-08202031.58000033.23266631.21533432.80933446716450032.809334
\n","
"],"text/plain":[" Date Year Open High Low Close Volume \\\n","0 2020-01-02 2020 28.299999 28.713333 28.114000 28.684000 142981500 \n","1 2020-01-03 2020 29.366667 30.266666 29.128000 29.534000 266677500 \n","2 2020-01-06 2020 29.364668 30.104000 29.333332 30.102667 151995000 \n","3 2020-01-07 2020 30.760000 31.441999 30.224001 31.270666 268231500 \n","4 2020-01-08 2020 31.580000 33.232666 31.215334 32.809334 467164500 \n","\n"," Adj Close \n","0 28.684000 \n","1 29.534000 \n","2 30.102667 \n","3 31.270666 \n","4 32.809334 "]},"execution_count":2,"metadata":{},"output_type":"execute_result"}],"source":["df=pd.read_csv(\"/kaggle/input/tesla-stock-insights-and-predictions/tesla_stock_data.csv\")\n","df.head()"]},{"cell_type":"code","execution_count":3,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:57.459117Z","iopub.status.busy":"2024-06-20T17:34:57.458669Z","iopub.status.idle":"2024-06-20T17:34:57.498490Z","shell.execute_reply":"2024-06-20T17:34:57.496509Z","shell.execute_reply.started":"2024-06-20T17:34:57.459081Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["\n","RangeIndex: 996 entries, 0 to 995\n","Data columns (total 8 columns):\n"," # Column Non-Null Count Dtype \n","--- ------ -------------- ----- \n"," 0 Date 996 non-null object \n"," 1 Year 996 non-null int64 \n"," 2 Open 996 non-null float64\n"," 3 High 996 non-null float64\n"," 4 Low 996 non-null float64\n"," 5 Close 996 non-null float64\n"," 6 Volume 996 non-null int64 \n"," 7 Adj Close 996 non-null float64\n","dtypes: float64(5), int64(2), object(1)\n","memory usage: 62.4+ KB\n"]}],"source":["df.info()"]},{"cell_type":"code","execution_count":4,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:58.285530Z","iopub.status.busy":"2024-06-20T17:34:58.284443Z","iopub.status.idle":"2024-06-20T17:34:58.332940Z","shell.execute_reply":"2024-06-20T17:34:58.331267Z","shell.execute_reply.started":"2024-06-20T17:34:58.285476Z"},"trusted":true},"outputs":[{"data":{"text/html":["
\n","\n","\n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n"," \n","
YearOpenHighLowCloseVolumeAdj Close
count996.000000996.000000996.000000996.000000996.0000009.960000e+02996.000000
mean2021.493976209.203720213.956547204.062843209.1213351.335149e+08209.121335
std1.11857985.88440487.58850683.89460285.7086408.888939e+0785.708640
min2020.00000024.98000026.99066723.36733224.0813332.940180e+0724.081333
25%2020.000000159.780838162.617496154.389996160.2500047.718922e+07160.250004
50%2021.000000223.989998229.250000218.266663223.6516651.074158e+08223.651665
75%2022.000000263.002510268.010002258.120010262.6674961.578296e+08262.667496
max2023.000000411.470001414.496674405.666656409.9700019.140820e+08409.970001
\n","
"],"text/plain":[" Year Open High Low Close \\\n","count 996.000000 996.000000 996.000000 996.000000 996.000000 \n","mean 2021.493976 209.203720 213.956547 204.062843 209.121335 \n","std 1.118579 85.884404 87.588506 83.894602 85.708640 \n","min 2020.000000 24.980000 26.990667 23.367332 24.081333 \n","25% 2020.000000 159.780838 162.617496 154.389996 160.250004 \n","50% 2021.000000 223.989998 229.250000 218.266663 223.651665 \n","75% 2022.000000 263.002510 268.010002 258.120010 262.667496 \n","max 2023.000000 411.470001 414.496674 405.666656 409.970001 \n","\n"," Volume Adj Close \n","count 9.960000e+02 996.000000 \n","mean 1.335149e+08 209.121335 \n","std 8.888939e+07 85.708640 \n","min 2.940180e+07 24.081333 \n","25% 7.718922e+07 160.250004 \n","50% 1.074158e+08 223.651665 \n","75% 1.578296e+08 262.667496 \n","max 9.140820e+08 409.970001 "]},"execution_count":4,"metadata":{},"output_type":"execute_result"}],"source":["df.describe()"]},{"cell_type":"code","execution_count":5,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:59.087573Z","iopub.status.busy":"2024-06-20T17:34:59.087049Z","iopub.status.idle":"2024-06-20T17:34:59.098033Z","shell.execute_reply":"2024-06-20T17:34:59.096068Z","shell.execute_reply.started":"2024-06-20T17:34:59.087533Z"},"trusted":true},"outputs":[{"data":{"text/plain":["Index(['Date', 'Year', 'Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close'], dtype='object')"]},"execution_count":5,"metadata":{},"output_type":"execute_result"}],"source":["df.columns"]},{"cell_type":"code","execution_count":6,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:34:59.842087Z","iopub.status.busy":"2024-06-20T17:34:59.841584Z","iopub.status.idle":"2024-06-20T17:34:59.863903Z","shell.execute_reply":"2024-06-20T17:34:59.861952Z","shell.execute_reply.started":"2024-06-20T17:34:59.842052Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["Starting date is: 2020-01-02\n","Ending date is: 2023-12-29\n"]}],"source":["# Lets convert the Date column to datetime format\n","df['Date']=pd.to_datetime(df['Date'])\n","# Lets find the starting and ending date of the dataset\n","starting_date = df['Date'].min()\n","ending_date = df['Date'].max()\n","# Lets check the Format of dates\n","starting_date_formatted = starting_date.strftime(\"%Y-%m-%d\")\n","ending_date_formatted = ending_date.strftime(\"%Y-%m-%d\")\n","# print the starting and ending date\n","print(\"Starting date is:\", starting_date_formatted)\n","print(\"Ending date is:\", ending_date_formatted)"]},{"cell_type":"code","execution_count":7,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:00.778367Z","iopub.status.busy":"2024-06-20T17:35:00.777728Z","iopub.status.idle":"2024-06-20T17:35:00.792031Z","shell.execute_reply":"2024-06-20T17:35:00.789212Z","shell.execute_reply.started":"2024-06-20T17:35:00.778304Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["Total days in this dataset which represents the stock price are: 1457days\n"]}],"source":["print(f\"Total days in this dataset which represents the stock price are: {(df.Date.max()-df.Date.min()).days}days\")"]},{"cell_type":"code","execution_count":8,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:01.582042Z","iopub.status.busy":"2024-06-20T17:35:01.581562Z","iopub.status.idle":"2024-06-20T17:35:01.598578Z","shell.execute_reply":"2024-06-20T17:35:01.596443Z","shell.execute_reply.started":"2024-06-20T17:35:01.582005Z"},"trusted":true},"outputs":[{"data":{"text/plain":["Date 0\n","Year 0\n","Open 0\n","High 0\n","Low 0\n","Close 0\n","Volume 0\n","Adj Close 0\n","dtype: int64"]},"execution_count":8,"metadata":{},"output_type":"execute_result"}],"source":["df.isnull().sum().sort_values(ascending=True)"]},{"cell_type":"markdown","metadata":{},"source":["## Fan Chart"]},{"cell_type":"code","execution_count":14,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:35:40.448399Z","iopub.status.busy":"2024-06-20T17:35:40.447939Z","iopub.status.idle":"2024-06-20T17:35:40.625686Z","shell.execute_reply":"2024-06-20T17:35:40.623740Z","shell.execute_reply.started":"2024-06-20T17:35:40.448364Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["# forcasted Closing price\n","forecasted_prices = np.random.normal(df['Adj Close'].mean(), df['Adj Close'].std(), len(df))\n","\n","# Create upper and lower bounds for the fan chart\n","upper_bound = forecasted_prices + np.random.normal(0, 10, len(df))\n","lower_bound = forecasted_prices - np.random.normal(0, 10, len(df))\n","\n","trace = go.Scatter(x=df['Date'], y=forecasted_prices, mode='lines', line=dict(color='purple'), name='Forecasted Prices')\n","trace_upper = go.Scatter(x=df['Date'], y=upper_bound, mode='lines', line=dict(color='lightgreen'), fill='tonexty', name='Upper Bound')\n","trace_lower = go.Scatter(x=df['Date'], y=lower_bound, mode='lines', line=dict(color='lightpink'), fill='tonexty', name='Lower Bound')\n","\n","layout = go.Layout(title='Fan Chart of Forecasted Tesla Stock Prices', xaxis=dict(title='Date'), yaxis=dict(title='Price'))\n","fig = go.Figure(data=[trace, trace_upper, trace_lower], layout=layout)\n","iplot(fig)"]},{"cell_type":"markdown","metadata":{},"source":["## Moving Average Plot"]},{"cell_type":"code","execution_count":31,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:39:20.641093Z","iopub.status.busy":"2024-06-20T17:39:20.640591Z","iopub.status.idle":"2024-06-20T17:39:20.764872Z","shell.execute_reply":"2024-06-20T17:39:20.763115Z","shell.execute_reply.started":"2024-06-20T17:39:20.641058Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["df['Moving Average']=df['Close'].rolling(window=30).mean()\n","trace1=go.Scatter(x=df['Date'], y=df['Close'], mode='lines', name='Closing price')\n","trace2=go.Scatter(x=df['Date'], y=df['Moving Average'], mode='lines', name='Moving Average')\n","layout=go.Layout(title='Stock Closing price with Moving average', xaxis=dict(title='Date'), yaxis=dict(title='Moving Average'))\n","fig=go.Figure(data=[trace1,trace2], layout=layout)\n","iplot(fig)"]},{"cell_type":"markdown","metadata":{},"source":["## Open Chart"]},{"cell_type":"code","execution_count":30,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:39:18.746605Z","iopub.status.busy":"2024-06-20T17:39:18.746004Z","iopub.status.idle":"2024-06-20T17:39:18.832747Z","shell.execute_reply":"2024-06-20T17:39:18.831133Z","shell.execute_reply.started":"2024-06-20T17:39:18.746563Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["rolling_mean=df['Open'].rolling(window=30).mean()\n","trace=go.Scatter(x=df['Date'], y=rolling_mean, mode='lines', fill='tozeroy', name='Rolling Mean')\n","layout=go.Layout(title='Area Chart Rolling Mean of Opening Tesla Stock Price', xaxis=dict(title='Opening Price'), yaxis=dict(title='Rolling Mean'))\n","fig=go.Figure(data=[trace], layout=layout)\n","iplot(fig)"]},{"cell_type":"markdown","metadata":{},"source":["## Volume VS Scatter Plot"]},{"cell_type":"code","execution_count":29,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:39:16.434563Z","iopub.status.busy":"2024-06-20T17:39:16.434010Z","iopub.status.idle":"2024-06-20T17:39:16.492748Z","shell.execute_reply":"2024-06-20T17:39:16.491533Z","shell.execute_reply.started":"2024-06-20T17:39:16.434521Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["trace = go.Scatter(x=df['Volume'], y=df['Close'], mode='markers',\n"," marker=dict(color='purple', size=8), name='Volume vs. Closing Price')\n","\n","layout = go.Layout(title='Volume vs. Closing Price Scatter Plot',\n"," xaxis=dict(title='Volume'), yaxis=dict(title='Closing Price'))\n","fig = go.Figure(data=[trace], layout=layout)\n","iplot(fig)"]},{"cell_type":"markdown","metadata":{},"source":["## Seasonal Decomposition Plot"]},{"cell_type":"code","execution_count":28,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:39:13.072044Z","iopub.status.busy":"2024-06-20T17:39:13.070199Z","iopub.status.idle":"2024-06-20T17:39:13.229747Z","shell.execute_reply":"2024-06-20T17:39:13.228120Z","shell.execute_reply.started":"2024-06-20T17:39:13.071986Z"},"trusted":true},"outputs":[{"data":{"text/html":["
"]},"metadata":{},"output_type":"display_data"}],"source":["# Perform seasonal decomposition\n","decomposition = seasonal_decompose(df['Close'], model='additive', period=30)\n","\n","# Plot decomposition components\n","trace_trend = go.Scatter(x=df['Date'], y=decomposition.trend, mode='lines', name='Trend')\n","trace_seasonal = go.Scatter(x=df['Date'], y=decomposition.seasonal, mode='lines', name='Seasonal')\n","trace_residual = go.Scatter(x=df['Date'], y=decomposition.resid, mode='lines', name='Residual')\n","\n","layout = go.Layout(title='Seasonal Decomposition of Tesla Stock Closing Prices', xaxis=dict(title='Date'), yaxis=dict(title='Price'))\n","fig = go.Figure(data=[trace_trend, trace_seasonal, trace_residual], layout=layout)\n","iplot(fig)"]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":4772437,"sourceId":8084907,"sourceType":"datasetVersion"}],"dockerImageVersionId":30732,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","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.13"}},"nbformat":4,"nbformat_minor":4} diff --git a/Tesla Historic Stock Price Analysis/Model/tesla-ticker-gru.ipynb b/Tesla Historic Stock Price Analysis/Model/tesla-ticker-gru.ipynb new file mode 100644 index 000000000..ac9f53671 --- /dev/null +++ b/Tesla Historic Stock Price Analysis/Model/tesla-ticker-gru.ipynb @@ -0,0 +1 @@ +{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Tesla Ticker| Histroical Stock Price Dataset| GRU| BiGRU"]},{"cell_type":"code","execution_count":1,"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2024-06-20T17:33:21.834984Z","iopub.status.busy":"2024-06-20T17:33:21.834489Z","iopub.status.idle":"2024-06-20T17:33:42.911579Z","shell.execute_reply":"2024-06-20T17:33:42.910348Z","shell.execute_reply.started":"2024-06-20T17:33:21.834946Z"},"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":["2024-06-20 17:33:29.010197: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n","2024-06-20 17:33:29.010414: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n","2024-06-20 17:33:29.195465: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n"]}],"source":["# Import Libararies\n","import pandas as pd\n","import seaborn as sns\n","import matplotlib.pyplot as plt\n","import numpy as np\n","# implort plotly for interactive plots\n","import plotly.express as px\n","import plotly.graph_objects as go\n","from plotly.offline import iplot\n","#import plot_acf\n","from statsmodels.graphics.tsaplots import plot_acf\n","# import seasonal decompose\n","from statsmodels.tsa.seasonal import seasonal_decompose\n","# scaler\n","from sklearn.preprocessing import MinMaxScaler\n","# train_test_split\n","from sklearn.model_selection import train_test_split\n","# sequential using keras\n","from tensorflow.keras.models import Sequential\n","# Dense, Bidirectional,GRU Layers using keras\n","from tensorflow.keras.layers import Dense, Bidirectional, GRU\n","# Adam optimizer\n","from tensorflow.keras.optimizers import Adam\n","# Early stoppng or callbacks\n","from tensorflow.keras.callbacks import EarlyStopping\n","# import metrics\n","from sklearn.metrics import r2_score, mean_squared_error\n","# import warnings\n","import warnings \n","warnings.filterwarnings('ignore')"]},{"cell_type":"markdown","metadata":{},"source":["## GRU"]},{"cell_type":"code","execution_count":26,"metadata":{"execution":{"iopub.execute_input":"2024-06-20T17:38:04.144759Z","iopub.status.busy":"2024-06-20T17:38:04.144155Z","iopub.status.idle":"2024-06-20T17:38:20.303527Z","shell.execute_reply":"2024-06-20T17:38:20.302324Z","shell.execute_reply.started":"2024-06-20T17:38:04.144719Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["Epoch 1/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m3s\u001b[0m 38ms/step - loss: 0.0980 - mae: 0.2521 - val_loss: 0.0149 - val_mae: 0.1149\n","Epoch 2/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 23ms/step - loss: 0.0093 - mae: 0.0810 - val_loss: 0.0021 - val_mae: 0.0372\n","Epoch 3/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 0.0037 - mae: 0.0486 - val_loss: 0.0015 - val_mae: 0.0318\n","Epoch 4/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 0.0020 - mae: 0.0356 - val_loss: 0.0013 - val_mae: 0.0296\n","Epoch 5/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 0.0013 - mae: 0.0285 - val_loss: 0.0011 - val_mae: 0.0267\n","Epoch 6/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 0.0011 - mae: 0.0250 - val_loss: 0.0010 - val_mae: 0.0261\n","Epoch 7/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 0.0011 - mae: 0.0241 - val_loss: 9.7000e-04 - val_mae: 0.0256\n","Epoch 8/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 0.0011 - mae: 0.0238 - val_loss: 9.4475e-04 - val_mae: 0.0253\n","Epoch 9/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 0.0010 - mae: 0.0235 - val_loss: 9.2140e-04 - val_mae: 0.0249\n","Epoch 10/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 0.0010 - mae: 0.0231 - val_loss: 8.9958e-04 - val_mae: 0.0246\n","Epoch 11/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 9.8713e-04 - mae: 0.0228 - val_loss: 8.7902e-04 - val_mae: 0.0243\n","Epoch 12/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 9.6700e-04 - mae: 0.0226 - val_loss: 8.5928e-04 - val_mae: 0.0240\n","Epoch 13/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 21ms/step - loss: 9.4846e-04 - mae: 0.0223 - val_loss: 8.4008e-04 - val_mae: 0.0237\n","Epoch 14/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 9.3131e-04 - mae: 0.0221 - val_loss: 8.2142e-04 - val_mae: 0.0234\n","Epoch 15/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 9.1541e-04 - mae: 0.0218 - val_loss: 8.0346e-04 - val_mae: 0.0232\n","Epoch 16/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 24ms/step - loss: 9.0072e-04 - mae: 0.0216 - val_loss: 7.8638e-04 - val_mae: 0.0229\n","Epoch 17/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 21ms/step - loss: 8.8716e-04 - mae: 0.0215 - val_loss: 7.7033e-04 - val_mae: 0.0227\n","Epoch 18/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 8.7469e-04 - mae: 0.0213 - val_loss: 7.5536e-04 - val_mae: 0.0225\n","Epoch 19/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 8.6321e-04 - mae: 0.0211 - val_loss: 7.4144e-04 - val_mae: 0.0223\n","Epoch 20/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 8.5264e-04 - mae: 0.0209 - val_loss: 7.2848e-04 - val_mae: 0.0221\n","Epoch 21/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 8.4288e-04 - mae: 0.0208 - val_loss: 7.1639e-04 - val_mae: 0.0219\n","Epoch 22/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 8.3384e-04 - mae: 0.0206 - val_loss: 7.0509e-04 - val_mae: 0.0217\n","Epoch 23/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 8.2545e-04 - mae: 0.0205 - val_loss: 6.9448e-04 - val_mae: 0.0215\n","Epoch 24/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 8.1764e-04 - mae: 0.0204 - val_loss: 6.8450e-04 - val_mae: 0.0213\n","Epoch 25/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 20ms/step - loss: 8.1037e-04 - mae: 0.0202 - val_loss: 6.7508e-04 - val_mae: 0.0212\n","Epoch 26/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 22ms/step - loss: 8.0357e-04 - mae: 0.0201 - val_loss: 6.6619e-04 - val_mae: 0.0211\n","Epoch 27/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 7.9720e-04 - mae: 0.0200 - val_loss: 6.5776e-04 - val_mae: 0.0209\n","Epoch 28/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 7.9124e-04 - mae: 0.0199 - val_loss: 6.4977e-04 - val_mae: 0.0208\n","Epoch 29/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 7.8565e-04 - mae: 0.0198 - val_loss: 6.4217e-04 - val_mae: 0.0207\n","Epoch 30/30\n","\u001b[1m20/20\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 19ms/step - loss: 7.8040e-04 - mae: 0.0197 - val_loss: 6.3492e-04 - val_mae: 0.0205\n","\u001b[1m6/6\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 46ms/step\n","\u001b[1m6/6\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 6ms/step - loss: 4.4741e-04 - mae: 0.0163 \n","Test Loss: 0.0004662715655285865\n","Test MAE: 0.016546813771128654\n","Mean Squared Error: 0.0004662715791915416\n","R2 Score: 0.9297361935213004\n"]}],"source":["import numpy as np\n","import tensorflow as tf\n","from sklearn.model_selection import train_test_split\n","from sklearn.preprocessing import MinMaxScaler\n","from sklearn.metrics import mean_squared_error, r2_score\n","from tensorflow.keras.models import Sequential\n","from tensorflow.keras.layers import GRU, Dense\n","from tensorflow.keras.optimizers import Adam\n","\n","# Set random seeds for reproducibility\n","np.random.seed(42)\n","tf.random.set_seed(42)\n","\n","# Normalize the data\n","scaler = MinMaxScaler()\n","df['Close'] = scaler.fit_transform(df[['Close']])\n","\n","# Split the dataset into training and testing sets\n","train_data, test_data = train_test_split(df['Close'], test_size=0.2, shuffle=False, random_state=42)\n","\n","# Prepare input sequences and target values\n","def create_sequences(data, window_size):\n"," X, y = [], []\n"," for i in range(len(data) - window_size):\n"," X.append(data[i:i+window_size])\n"," y.append(data[i+window_size])\n"," return np.array(X), np.array(y)\n","\n","window_size = 30\n","X_train, y_train = create_sequences(train_data.values, window_size)\n","X_test, y_test = create_sequences(test_data.values, window_size)\n","\n","# Define and train the GRU model\n","model = Sequential([\n"," GRU(64, input_shape=(window_size, 1)),\n"," Dense(1)\n","])\n","\n","model.compile(optimizer=Adam(), loss='mse', metrics=['mae'])\n","model.fit(X_train, y_train, epochs=30, batch_size=32, validation_split=0.2)\n","\n","# Predictions\n","y_pred = model.predict(X_test)\n","\n","# Evaluation\n","loss, mae = model.evaluate(X_test, y_test)\n","print('Test Loss:', loss)\n","print('Test MAE:', mae)\n","\n","# Calculate MSE\n","mse = mean_squared_error(y_test, y_pred)\n","print('Mean Squared Error:', mse)\n","\n","# Calculate R2 score\n","r2 = r2_score(y_test, y_pred)\n","print('R2 Score:', r2)"]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":4772437,"sourceId":8084907,"sourceType":"datasetVersion"}],"dockerImageVersionId":30732,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","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.13"}},"nbformat":4,"nbformat_minor":4} diff --git a/Tesla Historic Stock Price Analysis/README.md b/Tesla Historic Stock Price Analysis/README.md new file mode 100644 index 000000000..6dfede70e --- /dev/null +++ b/Tesla Historic Stock Price Analysis/README.md @@ -0,0 +1,59 @@ +# **Tesla Historic Stock Price Analysis** + +### 🎯 Goal +To predict the future stock prices of Tesla using deep learning models such as GRU and BiGRU. + +### Purpose +The purpose of this project is to develop and compare the performance of two advanced recurrent neural network architectures, GRU and BiGRU, in predicting the stock prices of Tesla. This can help investors make informed decisions by providing insights into future stock price movements. + +### 🧵 Dataset +The dataset used in this project is: https://www.kaggle.com/datasets/muhammadibrahimqasmi/tesla-stock-insights-and-predictions/data + +### 🧾 Description +The dataset contains historical stock price data for Tesla. It includes features like Open, High, Low, and Close prices, and Volume. This data is used to train and evaluate the performance of the prediction models. + +### 🚀 Models Implemented +1. GRU (Gated Recurrent Unit) +2. BiGRU (Bidirectional Gated Recurrent Unit) + +### 📚 Libraries Needed +- TensorFlow: For building and training deep learning models. +- Keras: For simplifying the creation and training of neural networks. +- NumPy: For numerical computations and array operations. +- Pandas: For data manipulation and analysis. +- Matplotlib: For plotting and visualizing data. + +### 📊 Data Visualization +CandlestickPlot +FanChart +3D_SurfacePlot +MovingAverage + +### 📊 Exploratory Data Analysis Results +1. Data Visualization: Plotting the historical stock prices to understand the trends and patterns. Plots are in the `Images` folder. +2. Statistical Summary: Providing a summary of the data to get insights into the mean, median, standard deviation, etc. +3. Correlation Analysis: Analyzing the correlation between different features to understand their relationships. + +### 📈 Performance of the Models based on the Accuracy Scores +The performance of the models is evaluated using the following metrics: + +- R2 Score: Measures the proportion of the variance in the dependent variable that is predictable from the independent variables. +- RMSE (Root Mean Squared Error): Measures the average magnitude of the errors between predicted and actual values. + +1. GRU Model + - R2 Score: 0.929 + - RMSE: 0.0004 +2. BiGRU Model + - R2 Score: 0.971 + - RMSE: 0.0005 + + +### 📢 Conclusion +Based on the evaluation metrics, the BiGRU model outperforms the GRU model in predicting Tesla stock prices. The bidirectional nature of the BiGRU allows it to capture the temporal dependencies in both forward and backward directions, leading to more accurate predictions. + +### Best Fitted Model +The BiGRU model is identified as the best-fitted model for predicting Tesla stock prices due to its higher accuracy and lower RMSE compared to the GRU model. + +## ✒️ Contributor +- Name: Khushi Kalra +- Github: https://www.github.com/abckhush