Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hayatiyrtgl/lstm_time_seriesv2
The code downloads Microsoft stock data, preprocesses it, builds and trains a deep learning model, and visualizes predictions.
https://github.com/hayatiyrtgl/lstm_time_seriesv2
analyzer deep-learning deep-neural-networks forecasting lstm pandas python time-series
Last synced: 17 days ago
JSON representation
The code downloads Microsoft stock data, preprocesses it, builds and trains a deep learning model, and visualizes predictions.
- Host: GitHub
- URL: https://github.com/hayatiyrtgl/lstm_time_seriesv2
- Owner: HayatiYrtgl
- Created: 2024-05-04T22:44:52.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-05-04T22:45:49.000Z (8 months ago)
- Last Synced: 2024-11-05T09:15:38.066Z (2 months ago)
- Topics: analyzer, deep-learning, deep-neural-networks, forecasting, lstm, pandas, python, time-series
- Language: Jupyter Notebook
- Homepage:
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This code is a Python script for analyzing Microsoft stock data using time series analysis techniques. Let's break down the steps:
1. **Setting up Kaggle API**: The script begins by setting up the Kaggle API to download the dataset. It copies the Kaggle API key file (`kaggle.json`) to the appropriate directory and sets permissions.
2. **Downloading and Unzipping Data**: It then downloads a dataset named "microsoft-stock-time-series-analysis" from Kaggle and unzips it.
3. **Importing Libraries**: After the setup, it imports necessary libraries including `pandas`, `numpy`, and `matplotlib`.
4. **Reading and Preprocessing Data**: The script reads the Microsoft stock data from a CSV file named "Microsoft_Stock.csv" into a pandas DataFrame. It checks for missing values, converts the "Date" column to datetime format, sets the date column as the index, and drops the "Date" column.
5. **Visualizing Data**: It plots the first 1000 data points of the "Close" price as the training data (in blue) and the remaining data points as the test data (in orange).
6. **Data Preparation**: The script prepares the data for training by creating input-output pairs. It defines a function `data_creation()` to create sequences of data points with a specified window size for input features (`X`) and corresponding target values (`y`).
7. **Train and Test Split**: It splits the data into training and test sets.
8. **Model Building**: It builds a deep learning model using Keras. The model consists of two LSTM layers followed by dropout layers and dense layers. The model is compiled with mean squared error (MSE) loss function and Adam optimizer.
9. **Model Training**: The model is trained on the training data for 200 epochs.
10. **Model Evaluation**: It predicts the stock prices on the test data and plots the real stock prices against the predicted ones.
11. **Making Predictions**: It makes a single prediction for the stock price at a given index.
12. **Visualizing Predictions**: It plots the predicted stock prices along with the training data and indicates the prediction line.
Overall, this script demonstrates a workflow for time series analysis and forecasting of Microsoft stock prices using deep learning techniques.