Welcome to the API App powered by Flask and Python! This application serves as a backend API that interacts with a MySQL database and provides data endpoints for a React front-end application.
Before getting started, make sure you have the following prerequisites installed on your system:
- Node.js (required for the React front-end)
- MySQL (ensure the MySQL server is running)
- Python (3.x recommended)
git clone https://github.com/moham7dreza/time_series_prediction_flask_api
cd time_series_prediction_flask_api
pip install -r requirements.txt
-
Log in to MySQL with your MySQL client:
mysql -u your_database_user -p -
Create a new database:
CREATE DATABASE your_database_name;
-
Exit the MySQL shell:
EXIT;
-
Create a
.envfile in the project directory. -
Add the following lines to the
.envfile, replacing the placeholders with your MySQL credentials:DB_HOST=your_database_host DB_USER=your_database_user DB_PASSWORD=your_database_password DB_NAME=your_database_name
-
In the project directory, run the following commands to create and apply migrations:
flask db init flask db migrate flask db upgrade
This will set up the necessary tables in your MySQL database.
- please visit the React GitHub Repository.
All datasets are located in the iran_stock folder, and the pre-trained models with 100 epochs are stored in the time_seies_models directory.
The following datasets from the Iran market were used for prediction:
DollarCarHomeTechOil
All datasets have been preprocessed, and the data extraction involved computing the weekly average of prices for prediction.
The data is separated into sequences with a specific number of time steps (n_steps) for training the models. This separation helps in capturing temporal dependencies. The value of n_steps can be configured based on the desired context for prediction.
Checklist for prices available for prediction:
<CLOSE><LOW><HIGH><OPEN>
The following models have been trained on univariate and multivariate time series data:
- Convolutional Neural Network (
CNN) - Long Short-Term Memory (
LSTM) - Bidirectional
LSTM - Artificial Neural Network (
ANN) - Bidirectional Artificial Neural Network (
Bi-ANN) - Gated Recurrent Unit (
GRU) - Bidirectional
GRU - Vanilla Recurrent Neural Network (
RNN) - Bidirectional
RNN
- Data Period:
2014to2022 - Train-Test Split:
80%
Use the following metrics to calculate errors:
- Mean Absolute Error (
MAE) - Mean Squared Error (
MSE) - Mean Absolute Percentage Error (
MAPE) - R-squared (
R2) - Root Mean Squared Error (
RMSE)
The MySQL database is used to store the history of prediction properties. This includes information such as selected models, datasets, prices, n_steps, and evaluation metrics.
-
Ensure that your MySQL server is running.
-
In the project directory, run the Flask application:
python -m flask run
-
Navigate to the React front-end application using the provided link (e.g., http://localhost:3000).
That's it! You have successfully set up and run the API App with Flask and Python. If you encounter any issues, please check your configurations and ensure that all prerequisites are correctly installed.
