Update README.md
Browse files
README.md
CHANGED
|
@@ -69,3 +69,70 @@ arima_results_df = pd.DataFrame({'Date': prediction_dates, 'Predicted_Price': pr
|
|
| 69 |
print("\nARIMA - 7-Day Forecast")
|
| 70 |
print("="*60)
|
| 71 |
print(arima_results_df.to_string(index=False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
print("\nARIMA - 7-Day Forecast")
|
| 70 |
print("="*60)
|
| 71 |
print(arima_results_df.to_string(index=False))
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
<details> <summary>LSTM Model Inference</summary>
|
| 76 |
+
# Install required packages
|
| 77 |
+
!pip install --quiet yfinance joblib tensorflow huggingface_hub scikit-learn
|
| 78 |
+
|
| 79 |
+
# Import Libraries
|
| 80 |
+
from huggingface_hub import hf_hub_download
|
| 81 |
+
import tensorflow as tf
|
| 82 |
+
import joblib
|
| 83 |
+
import numpy as np
|
| 84 |
+
import pandas as pd
|
| 85 |
+
import yfinance as yf
|
| 86 |
+
from sklearn.preprocessing import MinMaxScaler
|
| 87 |
+
|
| 88 |
+
HF_TOKEN = "your_own_hf_token"
|
| 89 |
+
|
| 90 |
+
# Load model and scaler
|
| 91 |
+
model_path = hf_hub_download(
|
| 92 |
+
repo_id="EsferSami/DataSynthis_ML_JobTask",
|
| 93 |
+
filename="Apple-Stock-Price-Forecasting-LSTM-Model/apple_stock_lstm.h5",
|
| 94 |
+
token=HF_TOKEN
|
| 95 |
+
)
|
| 96 |
+
scaler_path = hf_hub_download(
|
| 97 |
+
repo_id="EsferSami/DataSynthis_ML_JobTask",
|
| 98 |
+
filename="Apple-Stock-Price-Forecasting-LSTM-Model/scaler.joblib",
|
| 99 |
+
token=HF_TOKEN
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
model = tf.keras.models.load_model(model_path)
|
| 103 |
+
scaler = joblib.load(scaler_path)
|
| 104 |
+
|
| 105 |
+
# Download recent data
|
| 106 |
+
data = yf.download("AAPL", period="3mo", auto_adjust=False)
|
| 107 |
+
recent_prices = data['Adj Close'].values.astype(float)
|
| 108 |
+
|
| 109 |
+
# Prepare input
|
| 110 |
+
last_60_days = recent_prices[-60:].reshape(-1, 1)
|
| 111 |
+
last_60_scaled = scaler.transform(last_60_days)
|
| 112 |
+
|
| 113 |
+
predictions = []
|
| 114 |
+
current_seq = last_60_scaled.copy()
|
| 115 |
+
last_price = last_60_days[-1][0]
|
| 116 |
+
MAX_DAILY_CHANGE = 0.02
|
| 117 |
+
|
| 118 |
+
for day in range(7):
|
| 119 |
+
input_data = current_seq.reshape(1, 60, 1)
|
| 120 |
+
pred_scaled = model.predict(input_data, verbose=0)
|
| 121 |
+
pred_price_raw = scaler.inverse_transform(pred_scaled)[0][0]
|
| 122 |
+
|
| 123 |
+
change = pred_price_raw - last_price
|
| 124 |
+
change = np.clip(change, -MAX_DAILY_CHANGE*last_price, MAX_DAILY_CHANGE*last_price)
|
| 125 |
+
anchored_price = last_price + change
|
| 126 |
+
predictions.append(anchored_price)
|
| 127 |
+
|
| 128 |
+
pred_scaled_reshaped = scaler.transform(np.array([[anchored_price]]))
|
| 129 |
+
current_seq = np.append(current_seq[1:], pred_scaled_reshaped, axis=0)
|
| 130 |
+
last_price = anchored_price
|
| 131 |
+
|
| 132 |
+
prediction_dates = pd.date_range(start=data.index[-1] + pd.Timedelta(days=1), periods=7)
|
| 133 |
+
results_df = pd.DataFrame({'Date': prediction_dates, 'Predicted_Price': np.round(predictions, 2)})
|
| 134 |
+
|
| 135 |
+
print("\nLSTM - 7-Day Forecast")
|
| 136 |
+
print("="*50)
|
| 137 |
+
print(results_df.to_string(index=False))
|
| 138 |
+
</details>
|