| # NSE LSTM Model Usage Example | |
| import tensorflow as tf | |
| import pickle | |
| import numpy as np | |
| import pandas as pd | |
| def load_model(): | |
| """Load the trained NSE LSTM model and scaler""" | |
| model = tf.keras.models.load_model("nse_lstm_model.keras") | |
| with open("nse_lstm_scaler.pkl", "rb") as f: | |
| scaler = pickle.load(f) | |
| return model, scaler | |
| def prepare_features(data): | |
| """Prepare features for prediction""" | |
| # This is a simplified example - you'll need to implement | |
| # the same feature engineering used during training | |
| features = [] | |
| for i in range(len(data) - 4): # 5-day window | |
| window = data[i:i+5] | |
| # Calculate your 25 features here | |
| # For now, using dummy data | |
| feature_vector = np.random.randn(25) | |
| features.append(feature_vector) | |
| return np.array(features).reshape(-1, 5, 25) | |
| def predict_stock_price(symbol_data): | |
| """Predict next day's stock price""" | |
| model, scaler = load_model() | |
| # Prepare features | |
| features = prepare_features(symbol_data) | |
| # Make prediction | |
| prediction = model.predict(features) | |
| return prediction | |
| # Example usage | |
| if __name__ == "__main__": | |
| # Load your stock data here | |
| # data = pd.read_csv("your_stock_data.csv") | |
| # For demonstration, using random data | |
| dummy_data = np.random.randn(100, 5) # 100 days, 5 features | |
| prediction = predict_stock_price(dummy_data) | |
| print(f"Predicted price change: {prediction[0][0]}") | |