How iamdeepakhr/stock-price-prediction-using-machine-learning works
Main Components
• Frontend (User Interface):
• Represented by the HTML template (templates/index.html) and static files (static/script.js, static/style.css).
• UI components, including interactive graph elements, are powered by Chart.js.
• Backend Web Server:
• Managed by Flask (app.py), which handles API requests from the client.
• Acts as the controller to process user inputs, fetch data, and serve web pages.
• Machine Learning Models:
• The trained LSTM model (model/stock_lstm_model.keras) and scaler (model/scaler.pkl) are used to predict stock prices.
• The model training and retraining are handled by train_model.py.
• External Data Source:
• Integration with Yahoo Finance API for real-time stock data acquisition.
• Data Flow & Processing:
• Python libraries like yFinance and TensorFlow/Keras that bring data processing and model inference into the flow.
Relationships and Interactions
• Users interact with the Frontend via their web browsers.
• The Frontend sends requests (e.g., input stock symbols, trigger retraining) to the Flask backend.
• The Flask backend receives requests and either:
• Contacts the Yahoo Finance API to fetch current and historical stock data.
• Uses the pre-trained LSTM model and scaler to process the data and generate predictions.
• Or triggers retraining by running the train_model.py script to update the model with new data.
• Once processed, the data (actual stock prices and predictions) are sent back to the Frontend where they are visualized (using Chart.js).
Architectural Patterns and Design Principles
• Separation of Concerns: The frontend is strictly for presentation while the backend serves the application logic and machine learning inference.
• Modularity: Each component (UI, backend logic, ML model, external API interaction) is independently manageable.
• Dynamic Data Fetching: Real-time integration with Yahoo Finance to ensure up-to-date predictions.
• Scalability & Maintainability: Code is organized to allow for easy tweaks to data handling, UI update, and model retraining.